diff --git a/components/calendar/src/buddhist.rs b/components/calendar/src/buddhist.rs index 666b02658bf..fbf77d1d747 100644 --- a/components/calendar/src/buddhist.rs +++ b/components/calendar/src/buddhist.rs @@ -2,7 +2,34 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -//! This module contains types and implementations for the Buddhist calendar +//! This module contains types and implementations for the Buddhist calendar. +//! +//! ```rust +//! use icu::calendar::{Date, DateTime, +//! types::IsoHour, types::IsoMinute, types::IsoSecond, +//! buddhist::Buddhist}; +//! +//! // `Date` type +//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap(); +//! let date_buddhist = Date::new_from_iso(date_iso, Buddhist); +//! +//! // `DateTime` type +//! let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0).unwrap(); +//! let datetime_buddhist = DateTime::new_from_iso(datetime_iso, Buddhist); +//! +//! // `Date` checks +//! assert_eq!(date_buddhist.year().number, 2513); +//! assert_eq!(date_buddhist.month().number, 1); +//! assert_eq!(date_buddhist.day_of_month().0, 2); +//! +//! // `DateTime` type +//! assert_eq!(datetime_buddhist.date.year().number, 2513); +//! assert_eq!(datetime_buddhist.date.month().number, 1); +//! assert_eq!(datetime_buddhist.date.day_of_month().0, 2); +//! assert_eq!(datetime_buddhist.time.hour, IsoHour::new_unchecked(13)); +//! assert_eq!(datetime_buddhist.time.minute, IsoMinute::new_unchecked(1)); +//! assert_eq!(datetime_buddhist.time.second, IsoSecond::new_unchecked(0)); +//! ``` use crate::iso::{Iso, IsoDateInner, IsoYear}; use crate::{types, Calendar, Date, DateDuration, DateDurationUnit, DateTime, DateTimeError}; diff --git a/components/calendar/src/coptic.rs b/components/calendar/src/coptic.rs index f673bb14250..cce67611372 100644 --- a/components/calendar/src/coptic.rs +++ b/components/calendar/src/coptic.rs @@ -2,7 +2,34 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -//! This module contains types and implementations for the Coptic calendar +//! This module contains types and implementations for the Coptic calendar. +//! +//! ```rust +//! use icu::calendar::{Date, DateTime, +//! types::IsoHour, types::IsoMinute, types::IsoSecond, +//! coptic::Coptic}; +//! +//! // `Date` type +//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap(); +//! let date_coptic = Date::new_from_iso(date_iso, Coptic); +//! +//! // `DateTime` type +//! let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0).unwrap(); +//! let datetime_coptic = DateTime::new_from_iso(datetime_iso, Coptic); +//! +//! // `Date` checks +//! assert_eq!(date_coptic.year().number, 1686); +//! assert_eq!(date_coptic.month().number, 4); +//! assert_eq!(date_coptic.day_of_month().0, 24); +//! +//! // `DateTime` type +//! assert_eq!(datetime_coptic.date.year().number, 1686); +//! assert_eq!(datetime_coptic.date.month().number, 4); +//! assert_eq!(datetime_coptic.date.day_of_month().0, 24); +//! assert_eq!(datetime_coptic.time.hour, IsoHour::new_unchecked(13)); +//! assert_eq!(datetime_coptic.time.minute, IsoMinute::new_unchecked(1)); +//! assert_eq!(datetime_coptic.time.second, IsoSecond::new_unchecked(0)); +//! ``` use crate::iso::{Iso, IsoYear}; use crate::julian::Julian; diff --git a/components/calendar/src/ethiopic.rs b/components/calendar/src/ethiopic.rs index 070c06e5198..6a1897cf432 100644 --- a/components/calendar/src/ethiopic.rs +++ b/components/calendar/src/ethiopic.rs @@ -2,7 +2,34 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -//! This module contains types and implementations for the Ethiopic calendar +//! This module contains types and implementations for the Ethiopic calendar. +//! +//! ```rust +//! use icu::calendar::{Date, DateTime, +//! types::IsoHour, types::IsoMinute, types::IsoSecond, +//! ethiopic::Ethiopic}; +//! +//! // `Date` type +//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap(); +//! let date_ethiopic = Date::new_from_iso(date_iso, Ethiopic); +//! +//! // `DateTime` type +//! let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0).unwrap(); +//! let datetime_ethiopic = DateTime::new_from_iso(datetime_iso, Ethiopic); +//! +//! // `Date` checks +//! assert_eq!(date_ethiopic.year().number, 1962); +//! assert_eq!(date_ethiopic.month().number, 4); +//! assert_eq!(date_ethiopic.day_of_month().0, 24); +//! +//! // `DateTime` type +//! assert_eq!(datetime_ethiopic.date.year().number, 1962); +//! assert_eq!(datetime_ethiopic.date.month().number, 4); +//! assert_eq!(datetime_ethiopic.date.day_of_month().0, 24); +//! assert_eq!(datetime_ethiopic.time.hour, IsoHour::new_unchecked(13)); +//! assert_eq!(datetime_ethiopic.time.minute, IsoMinute::new_unchecked(1)); +//! assert_eq!(datetime_ethiopic.time.second, IsoSecond::new_unchecked(0)); +//! ``` use crate::coptic::Coptic; use crate::iso::{Iso, IsoYear}; diff --git a/components/calendar/src/gregorian.rs b/components/calendar/src/gregorian.rs index 1a9f28775bd..b979e714bc0 100644 --- a/components/calendar/src/gregorian.rs +++ b/components/calendar/src/gregorian.rs @@ -2,7 +2,34 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -//! This module contains types and implementations for the Gregorian calendar +//! This module contains types and implementations for the Gregorian calendar. +//! +//! ```rust +//! use icu::calendar::{Date, DateTime, +//! types::IsoHour, types::IsoMinute, types::IsoSecond, +//! gregorian::Gregorian}; +//! +//! // `Date` type +//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap(); +//! let date_gregorian = Date::new_from_iso(date_iso, Gregorian); +//! +//! // `DateTime` type +//! let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0).unwrap(); +//! let datetime_gregorian = DateTime::new_from_iso(datetime_iso, Gregorian); +//! +//! // `Date` checks +//! assert_eq!(date_gregorian.year().number, 1970); +//! assert_eq!(date_gregorian.month().number, 1); +//! assert_eq!(date_gregorian.day_of_month().0, 2); +//! +//! // `DateTime` type +//! assert_eq!(datetime_gregorian.date.year().number, 1970); +//! assert_eq!(datetime_gregorian.date.month().number, 1); +//! assert_eq!(datetime_gregorian.date.day_of_month().0, 2); +//! assert_eq!(datetime_gregorian.time.hour, IsoHour::new_unchecked(13)); +//! assert_eq!(datetime_gregorian.time.minute, IsoMinute::new_unchecked(1)); +//! assert_eq!(datetime_gregorian.time.second, IsoSecond::new_unchecked(0)); +//! ``` use crate::iso::{Iso, IsoDateInner, IsoDay, IsoMonth, IsoYear}; use crate::{types, Calendar, Date, DateDuration, DateDurationUnit, DateTime, DateTimeError}; diff --git a/components/calendar/src/indian.rs b/components/calendar/src/indian.rs index 6e7819fec4f..d1f03b40158 100644 --- a/components/calendar/src/indian.rs +++ b/components/calendar/src/indian.rs @@ -2,7 +2,34 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -//! This module contains types and implementations for the Indian national calendar +//! This module contains types and implementations for the Indian national calendar. +//! +//! ```rust +//! use icu::calendar::{Date, DateTime, +//! types::IsoHour, types::IsoMinute, types::IsoSecond, +//! indian::Indian}; +//! +//! // `Date` type +//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap(); +//! let date_indian = Date::new_from_iso(date_iso, Indian); +//! +//! // `DateTime` type +//! let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0).unwrap(); +//! let datetime_indian = DateTime::new_from_iso(datetime_iso, Indian); +//! +//! // `Date` checks +//! assert_eq!(date_indian.year().number, 1892); +//! assert_eq!(date_indian.month().number, 1); +//! assert_eq!(date_indian.day_of_month().0, 2); +//! +//! // `DateTime` type +//! assert_eq!(datetime_indian.date.year().number, 1892); +//! assert_eq!(datetime_indian.date.month().number, 1); +//! assert_eq!(datetime_indian.date.day_of_month().0, 2); +//! assert_eq!(datetime_indian.time.hour, IsoHour::new_unchecked(13)); +//! assert_eq!(datetime_indian.time.minute, IsoMinute::new_unchecked(1)); +//! assert_eq!(datetime_indian.time.second, IsoSecond::new_unchecked(0)); +//! ``` use crate::iso::{Iso, IsoYear}; use crate::{ diff --git a/components/calendar/src/iso.rs b/components/calendar/src/iso.rs index 2892632d4ac..333dade3e69 100644 --- a/components/calendar/src/iso.rs +++ b/components/calendar/src/iso.rs @@ -2,7 +2,31 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -//! This module contains types and implementations for the ISO calendar +//! This module contains types and implementations for the ISO calendar. +//! +//! ```rust +//! use icu::calendar::{Date, DateTime, +//! types::IsoHour, types::IsoMinute, types::IsoSecond}; +//! +//! // `Date` type +//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap(); +//! +//! // `DateTime` type +//! let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0).unwrap(); +//! +//! // `Date` checks +//! assert_eq!(date_iso.year().number, 1970); +//! assert_eq!(date_iso.month().number, 1); +//! assert_eq!(date_iso.day_of_month().0, 2); +//! +//! // `DateTime` type +//! assert_eq!(datetime_iso.date.year().number, 1970); +//! assert_eq!(datetime_iso.date.month().number, 1); +//! assert_eq!(datetime_iso.date.day_of_month().0, 2); +//! assert_eq!(datetime_iso.time.hour, IsoHour::new_unchecked(13)); +//! assert_eq!(datetime_iso.time.minute, IsoMinute::new_unchecked(1)); +//! assert_eq!(datetime_iso.time.second, IsoSecond::new_unchecked(0)); +//! ``` use crate::{types, Calendar, Date, DateDuration, DateDurationUnit, DateTime, DateTimeError}; use core::convert::{TryFrom, TryInto}; diff --git a/components/calendar/src/julian.rs b/components/calendar/src/julian.rs index 883c2039a14..a89cd308de5 100644 --- a/components/calendar/src/julian.rs +++ b/components/calendar/src/julian.rs @@ -2,7 +2,34 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -//! This module contains types and implementations for the Julian calendar +//! This module contains types and implementations for the Julian calendar. +//! +//! ```rust +//! use icu::calendar::{Date, DateTime, +//! types::IsoHour, types::IsoMinute, types::IsoSecond, +//! julian::Julian}; +//! +//! // `Date` type +//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap(); +//! let date_julian = Date::new_from_iso(date_iso, Julian); +//! +//! // `DateTime` type +//! let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0).unwrap(); +//! let datetime_julian = DateTime::new_from_iso(datetime_iso, Julian); +//! +//! // `Date` checks +//! assert_eq!(date_julian.year().number, 1969); +//! assert_eq!(date_julian.month().number, 12); +//! assert_eq!(date_julian.day_of_month().0, 20); +//! +//! // `DateTime` type +//! assert_eq!(datetime_julian.date.year().number, 1969); +//! assert_eq!(datetime_julian.date.month().number, 12); +//! assert_eq!(datetime_julian.date.day_of_month().0, 20); +//! assert_eq!(datetime_julian.time.hour, IsoHour::new_unchecked(13)); +//! assert_eq!(datetime_julian.time.minute, IsoMinute::new_unchecked(1)); +//! assert_eq!(datetime_julian.time.second, IsoSecond::new_unchecked(0)); +//! ``` use crate::iso::{Iso, IsoYear}; use crate::{