diff --git a/components/calendar/src/gregorian.rs b/components/calendar/src/gregorian.rs index 9571d3c78ef..ed11979d95f 100644 --- a/components/calendar/src/gregorian.rs +++ b/components/calendar/src/gregorian.rs @@ -54,7 +54,7 @@ pub struct Gregorian; #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)] /// The inner date type used for representing [`Date`]s of [`Gregorian`]. See [`Date`] and [`Gregorian`] for more details. -pub struct GregorianDateInner(IsoDateInner); +pub struct GregorianDateInner(pub(crate) IsoDateInner); impl Calendar for Gregorian { type DateInner = GregorianDateInner; diff --git a/components/calendar/src/hebrew.rs b/components/calendar/src/hebrew.rs index 71f73689508..9258cda162d 100644 --- a/components/calendar/src/hebrew.rs +++ b/components/calendar/src/hebrew.rs @@ -523,6 +523,23 @@ mod tests { assert_eq!(yi.keviyah.year_length(), 383); } + #[test] + fn test_negative_era_years() { + let greg_date = Date::try_new_gregorian_date(-5000, 1, 1).unwrap(); + // Extended year is accessible via the inner value. + // Era year is accessible via the public getter. + // TODO(#3962): Make extended year publicly accessible. + assert_eq!(greg_date.inner.0 .0.year, -5000); + assert_eq!(greg_date.year().era.0, "bce"); + // In Gregorian, era year is 1 - extended year + assert_eq!(greg_date.year().number, 5001); + let hebr_date = greg_date.to_calendar(Hebrew); + assert_eq!(hebr_date.inner.0.year, -1240); + assert_eq!(hebr_date.year().era.0, "hebrew"); + // In Hebrew, there is no inverse era, so negative extended years are negative era years + assert_eq!(hebr_date.year().number, -1240); + } + #[test] fn test_weekdays() { // https://github.com/unicode-org/icu4x/issues/4893