1
- //! This module implements `ZonedDateTime` and any directly related algorithms.
1
+ //! This module contains the core implementation of the `ZonedDateTime`
2
+ //! builtin type.
2
3
3
4
use alloc:: string:: String ;
4
5
use core:: { cmp:: Ordering , num:: NonZeroU128 } ;
@@ -80,7 +81,47 @@ impl PartialZonedDateTime {
80
81
}
81
82
}
82
83
83
- /// The native Rust implementation of `Temporal.ZonedDateTime`.
84
+ /// The native Rust implementation of a Temporal `ZonedDateTime`.
85
+ ///
86
+ /// A `ZonedDateTime` represents a date and time in a specific time
87
+ /// zone and calendar. A `ZonedDateTime` is represented as an instant
88
+ /// of unix epoch nanoseconds with a calendar, and a time zone.
89
+ ///
90
+ /// ## Time zone provider` API
91
+ ///
92
+ /// The core implementation of `ZonedDateTime` are primarily time zone
93
+ /// provider APIs denoted by a `*_with_provider` suffix. This means a
94
+ /// provider that implements the `TimeZoneProvider` trait must be provided.
95
+ ///
96
+ /// A default file system time zone provider, `FsTzdbProvider`, can be
97
+ /// enabled with the `tzdb` feature flag.
98
+ ///
99
+ /// The non time zone provider API, which is a default implementation of the
100
+ /// methods using `FsTzdbProvider` can be enabled with the `compiled_data`
101
+ /// feature flag.
102
+ ///
103
+ /// ## Example
104
+ ///
105
+ /// ```rust
106
+ /// use temporal_rs::{Calendar, Instant, TimeZone, ZonedDateTime};
107
+ ///
108
+ /// let zoned_date_time = ZonedDateTime::try_new(
109
+ /// 0,
110
+ /// Calendar::default(),
111
+ /// TimeZone::default(),
112
+ /// ).unwrap();
113
+ ///
114
+ /// assert_eq!(zoned_date_time.epoch_milliseconds(), 0);
115
+ /// assert_eq!(zoned_date_time.epoch_nanoseconds().as_i128(), 0);
116
+ /// assert_eq!(zoned_date_time.timezone().identifier().unwrap(), "UTC");
117
+ /// assert_eq!(zoned_date_time.calendar().identifier(), "iso8601");
118
+ /// ```
119
+ ///
120
+ /// ## Reference
121
+ ///
122
+ /// For more information, see the [MDN documentation][mdn-zoneddatetime].
123
+ ///
124
+ /// [mdn-zoneddatetime]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime
84
125
#[ non_exhaustive]
85
126
#[ derive( Debug , Clone , PartialEq , Eq ) ]
86
127
pub struct ZonedDateTime {
@@ -405,6 +446,7 @@ impl ZonedDateTime {
405
446
& self . tz
406
447
}
407
448
449
+ /// Create a `ZonedDateTime` from a `PartialZonedDateTime`.
408
450
#[ inline]
409
451
pub fn from_partial_with_provider (
410
452
partial : PartialZonedDateTime ,
@@ -648,13 +690,15 @@ impl ZonedDateTime {
648
690
Ok ( iso. time . nanosecond )
649
691
}
650
692
693
+ /// Returns an offset string for the current `ZonedDateTime`.
651
694
pub fn offset_with_provider ( & self , provider : & impl TimeZoneProvider ) -> TemporalResult < String > {
652
695
let offset = self
653
696
. tz
654
697
. get_offset_nanos_for ( self . epoch_nanoseconds ( ) . as_i128 ( ) , provider) ?;
655
698
Ok ( nanoseconds_to_formattable_offset ( offset) . to_string ( ) )
656
699
}
657
700
701
+ /// Returns the offset nanoseconds for the current `ZonedDateTime`.
658
702
pub fn offset_nanoseconds_with_provider (
659
703
& self ,
660
704
provider : & impl TimeZoneProvider ,
@@ -700,6 +744,7 @@ pub(crate) fn nanoseconds_to_formattable_offset(nanoseconds: i128) -> Formattabl
700
744
// ==== Core calendar method implementations ====
701
745
702
746
impl ZonedDateTime {
747
+ /// Returns the era for the current `ZonedDateTime`.
703
748
pub fn era_with_provider (
704
749
& self ,
705
750
provider : & impl TimeZoneProvider ,
@@ -709,6 +754,7 @@ impl ZonedDateTime {
709
754
Ok ( self . calendar . era ( & pdt. iso . date ) )
710
755
}
711
756
757
+ /// Returns the era-specific year for the current `ZonedDateTime`.
712
758
pub fn era_year_with_provider (
713
759
& self ,
714
760
provider : & impl TimeZoneProvider ,
0 commit comments