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 test about negative extended years #5087

Merged
merged 2 commits into from
Jun 26, 2024
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
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
Loading