Skip to content

Commit

Permalink
Add test about negative extended years (#5087)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Jun 26, 2024
1 parent 5217174 commit bdead59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/calendar/src/gregorian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions components/calendar/src/hebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bdead59

Please sign in to comment.