Skip to content

Commit 2d248bb

Browse files
committed
era indices
1 parent d1ad434 commit 2d248bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+848
-1439
lines changed

components/calendar/src/any_calendar.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,14 +1612,14 @@ mod tests {
16121612
fn japanese() {
16131613
let japanese = AnyCalendar::new(AnyCalendarKind::Japanese);
16141614
let japanese = Ref(&japanese);
1615-
single_test_roundtrip(japanese, Some(("reiwa", None)), 3, Month::new(3), 1);
1616-
single_test_roundtrip(japanese, Some(("heisei", None)), 6, Month::new(12), 1);
1617-
single_test_roundtrip(japanese, Some(("meiji", None)), 10, Month::new(3), 1);
1618-
single_test_roundtrip(japanese, Some(("ce", None)), 1000, Month::new(3), 1);
1615+
single_test_roundtrip(japanese, Some(("reiwa", Some(6))), 3, Month::new(3), 1);
1616+
single_test_roundtrip(japanese, Some(("heisei", Some(5))), 6, Month::new(12), 1);
1617+
single_test_roundtrip(japanese, Some(("meiji", Some(2))), 10, Month::new(3), 1);
1618+
single_test_roundtrip(japanese, Some(("ce", Some(1))), 1000, Month::new(3), 1);
16191619
single_test_roundtrip(japanese, None, 1000, Month::new(3), 1);
16201620
single_test_roundtrip(japanese, None, -100, Month::new(3), 1);
16211621
single_test_roundtrip(japanese, None, 2024, Month::new(3), 1);
1622-
single_test_roundtrip(japanese, Some(("bce", None)), 10, Month::new(3), 1);
1622+
single_test_roundtrip(japanese, Some(("bce", Some(0))), 10, Month::new(3), 1);
16231623
// Since #6910, the era range is not enforced in try_from_codes
16241624
/*
16251625
single_test_error(

components/calendar/src/cal/japanese.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,27 @@ impl GregorianYears for &'_ Japanese {
213213
fn era_year_from_extended(&self, year: i32, month: u8, day: u8) -> types::EraYear {
214214
let date: EraStartDate = EraStartDate { year, month, day };
215215

216-
if let Some((start, era)) = [self.last_era.unpack(), REIWA, HEISEI, SHOWA, TAISHO, MEIJI]
217-
.into_iter()
218-
.find(|&(start, _)| date >= start)
216+
if let Some((idx, (start, era))) = [
217+
(7, self.last_era.unpack()),
218+
(6, REIWA),
219+
(5, HEISEI),
220+
(4, SHOWA),
221+
(3, TAISHO),
222+
(2, MEIJI),
223+
]
224+
.into_iter()
225+
.skip((self.last_era == const { PackedEra::pack(REIWA) }) as usize)
226+
.find(|&(_, (start, _))| date >= start)
219227
{
220228
types::EraYear {
221229
era,
222-
// TODO: return era indices?
223-
era_index: None,
230+
era_index: Some(idx),
224231
year: year - start.year + 1,
225232
extended_year: year,
226233
ambiguity: types::YearAmbiguity::CenturyRequired,
227234
}
228235
} else {
229-
types::EraYear {
230-
// TODO: return era indices?
231-
era_index: None,
232-
..CeBce.era_year_from_extended(year, month, day)
233-
}
236+
CeBce.era_year_from_extended(year, month, day)
234237
}
235238
}
236239

provider/data/datetime/data/datetime_names_year_japanese_v1.rs.data

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/data/datetime/fingerprints.csv

Lines changed: 396 additions & 396 deletions
Large diffs are not rendered by default.

provider/source/data/debug/datetime/names/year/japanese/v1/3/ar-EG.json

Lines changed: 8 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/source/data/debug/datetime/names/year/japanese/v1/3/ar.json

Lines changed: 8 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/source/data/debug/datetime/names/year/japanese/v1/3/bn.json

Lines changed: 8 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/source/data/debug/datetime/names/year/japanese/v1/3/ccp.json

Lines changed: 8 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/source/data/debug/datetime/names/year/japanese/v1/3/en-001.json

Lines changed: 8 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/source/data/debug/datetime/names/year/japanese/v1/3/en-ZA.json

Lines changed: 8 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)