Skip to content

Commit 7776949

Browse files
committed
docs
1 parent 2fdd626 commit 7776949

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

components/time/src/types.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ dt_unit!(
118118
/// Must be within inclusive bounds `[0, 999_999_999]`."
119119
);
120120

121-
/// A representation of a time in hours, minutes, seconds, and nanoseconds
121+
/// A representation of a time-of-day in hours, minutes, seconds, and nanoseconds
122122
///
123123
/// **The primary definition of this type is in the [`icu_time`](https://docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
124124
///
@@ -184,6 +184,20 @@ impl Time {
184184
/// A date and time for a given calendar.
185185
///
186186
/// **The primary definition of this type is in the [`icu_time`](https://docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
187+
///
188+
/// This type exists as an input type for datetime formatting and should only be constructed
189+
/// to pass to a datetime formatter.
190+
///
191+
/// # Semantics
192+
///
193+
/// This type represents the date and time that are *displayed* to a user. It does not identify
194+
/// the absolute time that an event happens, nor does it represent the general concept of a
195+
/// "local date time", which would require time zone and leap second information for operations
196+
/// like validation, arithmetic, and comparisons.
197+
///
198+
/// Hence, while this type implements [`PartialEq`]/[`Eq`] (equal [`DateTime`]s will *display*
199+
/// equally), it does not implement [`PartialOrd`]/[`Ord`], arithmetic, and it is possible to
200+
/// create [`DateTime`]s that do not exist for a particular timezone.
187201
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
188202
#[allow(clippy::exhaustive_structs)] // this type is stable
189203
pub struct DateTime<A: AsCalendar> {
@@ -196,6 +210,24 @@ pub struct DateTime<A: AsCalendar> {
196210
/// A date and time for a given calendar, local to a specified time zone.
197211
///
198212
/// **The primary definition of this type is in the [`icu_time`](https://docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
213+
///
214+
/// This type exists as an input type for datetime formatting and should only be constructed
215+
/// to pass to a datetime formatter.
216+
///
217+
/// # Semantics
218+
///
219+
/// This type represents the date, time, and time zone that are *displayed* to a user.
220+
/// It does not identify the absolute time that an event happens, nor does it represent
221+
/// the general concept of a "zoned date time", which would require time zone and leap
222+
/// second information for operations like validation, arithmetic, and comparisons[^1].
223+
///
224+
/// Hence, while this type implements [`PartialEq`]/[`Eq`] (equal [`ZonedDateTime`]s will
225+
/// *display* equally), it does not implement [`PartialOrd`]/[`Ord`], arithmetic, and it
226+
/// is possible to create [`ZonedDateTime`]s that do not exist.
227+
///
228+
/// [^1]: [`ZonedDateTime<UtcOffset>`] is an exception to this, as the whole time zone
229+
/// identity is part of the type, and there are no local time discontinuities.
230+
/// Therefore it actually identifies an absolute time and implements [`PartialOrd`].
199231
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
200232
#[allow(clippy::exhaustive_structs)] // this type is stable
201233
pub struct ZonedDateTime<A: AsCalendar, Z> {

0 commit comments

Comments
 (0)