icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Indian calendar can return ISO-date with zero day_of_month

Open anba opened this issue 1 year ago • 2 comments

The computed ISO date should be 2000-12-31, but instead it returns 2001-01-00.

Not a regression from release 1.5, also reproducible with release 1.4.

Test case:

use icu::calendar::Date;
use icu::calendar::Calendar;
use icu::calendar::indian::Indian;

fn main() {
  let cal = Indian;

  let iso = Date::try_new_iso_date(2000, 12, 31).unwrap();
  let date = cal.date_from_iso(iso);

  println!("year = {}", cal.year(&date).number);
  println!("month = {}", cal.month(&date).ordinal);
  println!("day = {}", cal.day_of_month(&date).0);

  let iso = cal.date_to_iso(&date);

  println!("iso.year = {}", iso.year().number);
  println!("iso.month = {}", iso.month().ordinal);
  println!("iso.day = {}", iso.day_of_month().0);
}

anba avatar Jun 18 '24 10:06 anba

Possibly caused by this line: https://github.com/unicode-org/icu4x/blob/6d65cb511267b5f7b91fd18db120a37f44ddf615/components/calendar/src/indian.rs#L153

Changing the test condition from >= days_in_year to > days_in_year could fix this bug.

anba avatar Jun 18 '24 10:06 anba

cc @sffc

Manishearth avatar Jun 20 '24 21:06 Manishearth

This issue was fixed in #5726.

anba avatar Nov 10 '25 07:11 anba