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

1 BCE returned as 0 CE in the Japanese calendar #4968

Closed
anba opened this issue May 30, 2024 · 3 comments · Fixed by #5006
Closed

1 BCE returned as 0 CE in the Japanese calendar #4968

anba opened this issue May 30, 2024 · 3 comments · Fixed by #5006
Labels
C-calendar Component: Calendars S-tiny Size: Less than an hour (trivial fixes) T-bug Type: Bad behavior, security, privacy

Comments

@anba
Copy link

anba commented May 30, 2024

Test case:

use icu::calendar::{Calendar, Ref};
use icu::calendar::japanese::Japanese;
use icu::calendar::types::{Era, MonthCode};

use std::str::FromStr;

fn main() {
  let cal = Japanese::new();

  let era = Era::from_str("bce").unwrap(); 
  let monthCode = MonthCode::from_str("M01").unwrap();

  let bce1 = cal.date_from_codes(era, 1, monthCode, 1).unwrap();
  let bce2 = cal.date_from_codes(era, 2, monthCode, 1).unwrap();

  let bce1_year = cal.year(&bce1);
  let bce1_year_era = bce1_year.era;
  println!("BCE 1: {} [{}]", bce1_year.number, format!("{bce1_year_era:?}"));

  let bce2_year = cal.year(&bce2);
  let bce2_year_era = bce2_year.era;
  println!("BCE 2: {} [{}]", bce2_year.number, format!("{bce2_year_era:?}"));

  println!("\n\n");
  dbg!(bce1);
  dbg!(bce2);
}

Prints:

BCE 1: 0 [Era("ce")]
BCE 2: 2 [Era("bce")]

But expected is BCE 1: 1 [Era("bce")].

@anba
Copy link
Author

anba commented May 30, 2024

This is possibly caused by this line:

if date.year < 0 {

Changing the condition to date.year <= 0 may be sufficient to fix this.

@sffc
Copy link
Member

sffc commented Jun 4, 2024

Yes I think the one-liner change is probably correct. Thanks for spotting this!

@sffc sffc added C-calendar Component: Calendars T-bug Type: Bad behavior, security, privacy S-tiny Size: Less than an hour (trivial fixes) labels Jun 4, 2024
@sffc sffc closed this as completed in #5006 Jun 6, 2024
sffc added a commit that referenced this issue Jun 6, 2024
Fixes #4968

I'd like to make a release for this one because it's a one-line change
and we're already working on a patch release.
sffc added a commit that referenced this issue Jun 6, 2024
Fixes #4968

I'd like to make a release for this one because it's a one-line change
and we're already working on a patch release.

(cherry picked from commit ad65b6d)
@sffc
Copy link
Member

sffc commented Jun 6, 2024

icu_calendar version 1.5.1 has been released with this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-calendar Component: Calendars S-tiny Size: Less than an hour (trivial fixes) T-bug Type: Bad behavior, security, privacy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants