1- //! This module implements `ZonedDateTime` and any directly related algorithms.
1+ //! This module contains the core implementation of the `ZonedDateTime`
2+ //! builtin type.
23
34use alloc:: string:: String ;
45use core:: { cmp:: Ordering , num:: NonZeroU128 } ;
@@ -80,7 +81,47 @@ impl PartialZonedDateTime {
8081 }
8182}
8283
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
84125#[ non_exhaustive]
85126#[ derive( Debug , Clone , PartialEq , Eq ) ]
86127pub struct ZonedDateTime {
@@ -405,6 +446,7 @@ impl ZonedDateTime {
405446 & self . tz
406447 }
407448
449+ /// Create a `ZonedDateTime` from a `PartialZonedDateTime`.
408450 #[ inline]
409451 pub fn from_partial_with_provider (
410452 partial : PartialZonedDateTime ,
@@ -648,13 +690,15 @@ impl ZonedDateTime {
648690 Ok ( iso. time . nanosecond )
649691 }
650692
693+ /// Returns an offset string for the current `ZonedDateTime`.
651694 pub fn offset_with_provider ( & self , provider : & impl TimeZoneProvider ) -> TemporalResult < String > {
652695 let offset = self
653696 . tz
654697 . get_offset_nanos_for ( self . epoch_nanoseconds ( ) . as_i128 ( ) , provider) ?;
655698 Ok ( nanoseconds_to_formattable_offset ( offset) . to_string ( ) )
656699 }
657700
701+ /// Returns the offset nanoseconds for the current `ZonedDateTime`.
658702 pub fn offset_nanoseconds_with_provider (
659703 & self ,
660704 provider : & impl TimeZoneProvider ,
@@ -700,6 +744,7 @@ pub(crate) fn nanoseconds_to_formattable_offset(nanoseconds: i128) -> Formattabl
700744// ==== Core calendar method implementations ====
701745
702746impl ZonedDateTime {
747+ /// Returns the era for the current `ZonedDateTime`.
703748 pub fn era_with_provider (
704749 & self ,
705750 provider : & impl TimeZoneProvider ,
@@ -709,6 +754,7 @@ impl ZonedDateTime {
709754 Ok ( self . calendar . era ( & pdt. iso . date ) )
710755 }
711756
757+ /// Returns the era-specific year for the current `ZonedDateTime`.
712758 pub fn era_year_with_provider (
713759 & self ,
714760 provider : & impl TimeZoneProvider ,
0 commit comments