Skip to content

Commit

Permalink
Add Republic of China (ROC) calendar (#3677)
Browse files Browse the repository at this point in the history
  • Loading branch information
atcupps authored Jul 14, 2023
1 parent e09f58d commit 553f49d
Show file tree
Hide file tree
Showing 5 changed files with 515 additions and 2 deletions.
19 changes: 19 additions & 0 deletions components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::indian::Indian;
use crate::iso::Iso;
use crate::japanese::{Japanese, JapaneseExtended};
use crate::persian::Persian;
use crate::roc::Roc;
use crate::{
types, AsCalendar, Calendar, CalendarError, Date, DateDuration, DateDurationUnit, DateTime, Ref,
};
Expand Down Expand Up @@ -92,6 +93,8 @@ pub enum AnyCalendar {
Iso(Iso),
/// A [`Chinese`] calendar
Chinese(Chinese),
/// A [`Roc`] calendar
Roc(Roc),
}

// TODO(#3469): Decide on the best way to implement Ord.
Expand All @@ -117,6 +120,8 @@ pub enum AnyDateInner {
Chinese(<Chinese as Calendar>::DateInner),
/// A date for a [`Coptic`] calendar
Coptic(<Coptic as Calendar>::DateInner),
/// A date for a [`Roc`] calendar
Roc(<Roc as Calendar>::DateInner),
/// A date for an [`Iso`] calendar
Iso(<Iso as Calendar>::DateInner),
}
Expand Down Expand Up @@ -182,6 +187,7 @@ impl Calendar for AnyCalendar {
Self::Coptic(ref c) => {
AnyDateInner::Coptic(c.date_from_codes(era, year, month_code, day)?)
}
Self::Roc(ref c) => AnyDateInner::Roc(c.date_from_codes(era, year, month_code, day)?),
Self::Iso(ref c) => AnyDateInner::Iso(c.date_from_codes(era, year, month_code, day)?),
};
Ok(ret)
Expand All @@ -198,6 +204,7 @@ impl Calendar for AnyCalendar {
Self::Iso(ref c) => AnyDateInner::Iso(c.date_from_iso(iso)),
Self::Persian(ref c) => AnyDateInner::Persian(c.date_from_iso(iso)),
Self::Chinese(ref c) => AnyDateInner::Chinese(c.date_from_iso(iso)),
Self::Roc(ref c) => AnyDateInner::Roc(c.date_from_iso(iso)),
}
}

Expand Down Expand Up @@ -379,6 +386,7 @@ impl Calendar for AnyCalendar {
Self::Iso(_) => "AnyCalendar (Iso)",
Self::Persian(_) => "AnyCalendar (Persian)",
Self::Chinese(_) => "AnyCalendar (Chinese)",
Self::Roc(_) => "AnyCalendar (Roc)",
}
}

Expand Down Expand Up @@ -408,6 +416,7 @@ impl AnyCalendar {
AnyCalendarKind::Indian => AnyCalendar::Indian(Indian),
AnyCalendarKind::Persian => AnyCalendar::Persian(Persian),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Roc => AnyCalendar::Roc(Roc),
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Iso => AnyCalendar::Iso(Iso),
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
Expand Down Expand Up @@ -439,6 +448,7 @@ impl AnyCalendar {
AnyCalendarKind::Indian => AnyCalendar::Indian(Indian),
AnyCalendarKind::Persian => AnyCalendar::Persian(Persian),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Roc => AnyCalendar::Roc(Roc),
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Iso => AnyCalendar::Iso(Iso),
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
Expand Down Expand Up @@ -471,6 +481,7 @@ impl AnyCalendar {
AnyCalendarKind::Indian => AnyCalendar::Indian(Indian),
AnyCalendarKind::Persian => AnyCalendar::Persian(Persian),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Roc => AnyCalendar::Roc(Roc),
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Iso => AnyCalendar::Iso(Iso),
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
Expand Down Expand Up @@ -501,6 +512,7 @@ impl AnyCalendar {
AnyCalendarKind::Indian => AnyCalendar::Indian(Indian),
AnyCalendarKind::Persian => AnyCalendar::Persian(Persian),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Roc => AnyCalendar::Roc(Roc),
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Iso => AnyCalendar::Iso(Iso),
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
Expand Down Expand Up @@ -566,6 +578,7 @@ impl AnyCalendar {
Self::Iso(_) => "Iso",
Self::Persian(_) => "Persian",
Self::Chinese(_) => "Chinese",
Self::Roc(_) => "Roc",
}
}

Expand All @@ -585,6 +598,7 @@ impl AnyCalendar {
Self::Iso(_) => AnyCalendarKind::Iso,
Self::Persian(_) => AnyCalendarKind::Persian,
Self::Chinese(_) => AnyCalendarKind::Chinese,
Self::Roc(_) => AnyCalendarKind::Roc,
}
}

Expand Down Expand Up @@ -630,6 +644,7 @@ impl AnyDateInner {
AnyDateInner::Iso(_) => "Iso",
AnyDateInner::Persian(_) => "Persian",
AnyDateInner::Chinese(_) => "Chinese",
AnyDateInner::Roc(_) => "Roc",
}
}
}
Expand Down Expand Up @@ -660,6 +675,8 @@ pub enum AnyCalendarKind {
Persian,
/// The kind of a [`Chinese`] calendar
Chinese,
/// The kind of a [`Roc`] calendar
Roc,
}

impl AnyCalendarKind {
Expand Down Expand Up @@ -733,6 +750,7 @@ impl AnyCalendarKind {
AnyCalendarKind::EthiopianAmeteAlem => "ethioaa",
AnyCalendarKind::Persian => "persian",
AnyCalendarKind::Chinese => "chinese",
AnyCalendarKind::Roc => "roc",
}
}

Expand All @@ -750,6 +768,7 @@ impl AnyCalendarKind {
AnyCalendarKind::EthiopianAmeteAlem => value!("ethioaa"),
AnyCalendarKind::Persian => value!("persian"),
AnyCalendarKind::Chinese => value!("chinese"),
AnyCalendarKind::Roc => value!("roc"),
}
}

Expand Down
3 changes: 1 addition & 2 deletions components/calendar/src/gregorian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//! assert_eq!(date_gregorian.month().ordinal, 1);
//! assert_eq!(date_gregorian.day_of_month().0, 2);
//!
//! // `DateTime` type
//! // `DateTime` checks
//! assert_eq!(datetime_gregorian.date.year().number, 1970);
//! assert_eq!(datetime_gregorian.date.month().ordinal, 1);
//! assert_eq!(datetime_gregorian.date.day_of_month().0, 2);
Expand Down Expand Up @@ -165,7 +165,6 @@ impl Date<Gregorian> {
///
/// ```rust
/// use icu::calendar::Date;
/// use std::convert::TryFrom;
///
/// // Conversion from ISO to Gregorian
/// let date_gregorian = Date::try_new_gregorian_date(1970, 1, 2)
Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub mod julian;
pub mod persian;
pub mod provider;
mod rata_die;
pub mod roc;
pub mod types;
mod week_of;

Expand Down
Loading

0 comments on commit 553f49d

Please sign in to comment.