Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date::new_from_iso(date_iso, X) example for each calendar X #1844

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion components/calendar/src/buddhist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
29 changes: 28 additions & 1 deletion components/calendar/src/coptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion components/calendar/src/ethiopic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
29 changes: 28 additions & 1 deletion components/calendar/src/gregorian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
29 changes: 28 additions & 1 deletion components/calendar/src/indian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
26 changes: 25 additions & 1 deletion components/calendar/src/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
29 changes: 28 additions & 1 deletion components/calendar/src/julian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down