Skip to content

Commit e4ad164

Browse files
Update era codes (#6525)
unicode-org/cldr#4519
1 parent d370681 commit e4ad164

File tree

5 files changed

+62
-54
lines changed

5 files changed

+62
-54
lines changed

components/calendar/src/any_calendar.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,13 +1792,13 @@ mod tests {
17921792
DateError::UnknownMonthCode(MonthCode(tinystr!(4, "M13"))),
17931793
);
17941794

1795-
single_test_roundtrip(indian, Some(("saka", Some(0))), 100, "M03", 1);
1795+
single_test_roundtrip(indian, Some(("shaka", Some(0))), 100, "M03", 1);
17961796
single_test_roundtrip(indian, None, 2000, "M12", 1);
17971797
single_test_roundtrip(indian, None, -100, "M03", 1);
1798-
single_test_roundtrip(indian, Some(("saka", Some(0))), 0, "M03", 1);
1798+
single_test_roundtrip(indian, Some(("shaka", Some(0))), 0, "M03", 1);
17991799
single_test_error(
18001800
indian,
1801-
Some(("saka", Some(0))),
1801+
Some(("shaka", Some(0))),
18021802
100,
18031803
"M13",
18041804
1,
@@ -1937,8 +1937,8 @@ mod tests {
19371937
DateError::UnknownMonthCode(MonthCode(tinystr!(4, "M9"))),
19381938
);
19391939

1940-
single_test_roundtrip(roc, Some(("minguo", Some(1))), 10, "M05", 3);
1941-
single_test_roundtrip(roc, Some(("minguo-qian", Some(0))), 15, "M01", 10);
1940+
single_test_roundtrip(roc, Some(("roc", Some(1))), 10, "M05", 3);
1941+
single_test_roundtrip(roc, Some(("broc", Some(0))), 15, "M01", 10);
19421942
single_test_roundtrip(roc, None, 100, "M10", 30);
19431943

19441944
single_test_roundtrip(hijri_simulated, Some(("ah", Some(0))), 477, "M03", 1);

components/calendar/src/cal/hijri.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use crate::cal::iso::{Iso, IsoDateInner};
2323
use crate::calendar_arithmetic::PrecomputedDataSource;
2424
use crate::calendar_arithmetic::{ArithmeticDate, CalendarArithmetic};
25-
use crate::error::DateError;
25+
use crate::error::{year_check, DateError};
2626
use crate::provider::hijri::PackedHijriYearInfo;
2727
use crate::provider::hijri::{CalendarHijriSimulatedMeccaV1, HijriData};
2828
use crate::types::EraYear;
@@ -38,19 +38,28 @@ use ummalqura_data::{UMMALQURA_DATA, UMMALQURA_DATA_STARTING_YEAR};
3838
mod ummalqura_data;
3939

4040
fn era_year(year: i32) -> EraYear {
41-
types::EraYear {
42-
era: tinystr!(16, "ah"),
43-
era_index: Some(0),
44-
year,
45-
ambiguity: types::YearAmbiguity::CenturyRequired,
41+
if year > 0 {
42+
types::EraYear {
43+
era: tinystr!(16, "ah"),
44+
era_index: Some(0),
45+
year,
46+
ambiguity: types::YearAmbiguity::CenturyRequired,
47+
}
48+
} else {
49+
types::EraYear {
50+
era: tinystr!(16, "bh"),
51+
era_index: Some(1),
52+
year: 1 - year,
53+
ambiguity: types::YearAmbiguity::CenturyRequired,
54+
}
4655
}
4756
}
4857

4958
/// The [simulated Hijri Calendar](https://en.wikipedia.org/wiki/Islamic_calendar)
5059
///
5160
/// # Era codes
5261
///
53-
/// This calendar uses a single era code `ah`, Anno Hegirae. Dates before this era use negative years.
62+
/// This calendar uses two era codes: `ah`, and `bh`, corresponding to the Anno Hegirae and Before Hijrah eras
5463
///
5564
/// # Month codes
5665
///
@@ -81,7 +90,7 @@ impl HijriSimulatedLocation {
8190
///
8291
/// # Era codes
8392
///
84-
/// This calendar uses a single era code `ah`, Anno Hegirae. Dates before this era use negative years.
93+
/// This calendar uses two era codes: `ah`, and `bh`, corresponding to the Anno Hegirae and Before Hijrah eras
8594
///
8695
/// # Month codes
8796
///
@@ -99,7 +108,7 @@ pub struct HijriUmmAlQura;
99108
///
100109
/// # Era codes
101110
///
102-
/// This calendar uses a single era code `ah`, Anno Hegirae. Dates before this era use negative years.
111+
/// This calendar uses two era codes: `ah`, and `bh`, corresponding to the Anno Hegirae and Before Hijrah eras
103112
///
104113
/// # Month codes
105114
///
@@ -376,7 +385,8 @@ impl Calendar for HijriSimulated {
376385
day: u8,
377386
) -> Result<Self::DateInner, DateError> {
378387
let year = match era {
379-
Some("islamic-rgsa" | "ah") | None => year,
388+
Some("ah") | None => year_check(year, 1..)?,
389+
Some("bh") => 1 - year_check(year, 1..)?,
380390
Some(_) => return Err(DateError::UnknownEra),
381391
};
382392
let Some((month, false)) = month_code.parsed() else {
@@ -658,7 +668,8 @@ impl Calendar for HijriUmmAlQura {
658668
day: u8,
659669
) -> Result<Self::DateInner, DateError> {
660670
let year = match era {
661-
Some("islamic-umalqura" | "ah") | None => year,
671+
Some("ah") | None => year_check(year, 1..)?,
672+
Some("bh") => 1 - year_check(year, 1..)?,
662673
Some(_) => return Err(DateError::UnknownEra),
663674
};
664675
let Some((month, false)) = month_code.parsed() else {
@@ -883,9 +894,8 @@ impl Calendar for HijriTabular {
883894
day: u8,
884895
) -> Result<Self::DateInner, DateError> {
885896
let year = match era {
886-
Some("ah") | None => year,
887-
Some("islamic-civil" | "islamicc") if self.epoch == HijriTabularEpoch::Friday => year,
888-
Some("islamic-tbla") if self.epoch == HijriTabularEpoch::Thursday => year,
897+
Some("ah") | None => year_check(year, 1..)?,
898+
Some("bh") => 1 - year_check(year, 1..)?,
889899
Some(_) => return Err(DateError::UnknownEra),
890900
};
891901

@@ -1895,11 +1905,9 @@ mod test {
18951905
#[test]
18961906
fn test_regression_4914() {
18971907
// https://github.com/unicode-org/icu4x/issues/4914
1898-
let cal = HijriUmmAlQura::new();
1899-
let era = "islamic-umalqura";
1900-
let year = -6823;
1901-
let month_code = MonthCode(tinystr!(4, "M01"));
1902-
let dt = cal.from_codes(Some(era), year, month_code, 1).unwrap();
1908+
let dt = HijriUmmAlQura::new()
1909+
.from_codes(Some("bh"), 6824, MonthCode::new_normal(1).unwrap(), 1)
1910+
.unwrap();
19031911
assert_eq!(dt.0.day, 1);
19041912
assert_eq!(dt.0.month, 1);
19051913
assert_eq!(dt.0.year.value, -6823);

components/calendar/src/cal/indian.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use tinystr::tinystr;
3131
///
3232
/// # Era codes
3333
///
34-
/// This calendar uses a single era code: `saka`, with Saka 0 being 78 CE. Dates before this era use negative years.
34+
/// This calendar uses a single era code: `shaka`, with Śaka 0 being 78 CE. Dates before this era use negative years.
3535
///
3636
/// # Month codes
3737
///
@@ -84,10 +84,10 @@ impl CalendarArithmetic for Indian {
8484
}
8585
}
8686

87-
/// The Saka calendar starts on the 81st day of the Gregorian year (March 22 or 21)
87+
/// The Śaka era starts on the 81st day of the Gregorian year (March 22 or 21)
8888
/// which is an 80 day offset. This number should be subtracted from Gregorian dates
8989
const DAY_OFFSET: u16 = 80;
90-
/// The Saka calendar is 78 years behind Gregorian. This number should be added to Gregorian dates
90+
/// The Śaka era is 78 years behind Gregorian. This number should be added to Gregorian dates
9191
const YEAR_OFFSET: i32 = 78;
9292

9393
impl crate::cal::scaffold::UnstableSealed for Indian {}
@@ -102,7 +102,7 @@ impl Calendar for Indian {
102102
day: u8,
103103
) -> Result<Self::DateInner, DateError> {
104104
let year = match era {
105-
Some("saka") | None => year,
105+
Some("shaka") | None => year,
106106
Some(_) => return Err(DateError::UnknownEra),
107107
};
108108
ArithmeticDate::new_from_codes(self, year, month_code, day).map(IndianDateInner)
@@ -120,7 +120,7 @@ impl Calendar for Indian {
120120
fn from_iso(&self, iso: IsoDateInner) -> IndianDateInner {
121121
// Get day number in year (1 indexed)
122122
let day_of_year_iso = Iso::day_of_year(iso);
123-
// Convert to Saka year
123+
// Convert to Śaka year
124124
let mut year = iso.0.year - YEAR_OFFSET;
125125
// This is in the previous Indian year
126126
let day_of_year_indian = if day_of_year_iso <= DAY_OFFSET {
@@ -186,7 +186,7 @@ impl Calendar for Indian {
186186
fn year_info(&self, date: &Self::DateInner) -> Self::Year {
187187
types::EraYear {
188188
era_index: Some(0),
189-
era: tinystr!(16, "saka"),
189+
era: tinystr!(16, "shaka"),
190190
year: self.extended_year(date),
191191
ambiguity: types::YearAmbiguity::CenturyRequired,
192192
}
@@ -320,19 +320,19 @@ mod tests {
320320

321321
fn check_case(case: TestCase) {
322322
let iso = Date::try_new_iso(case.iso_year, case.iso_month, case.iso_day).unwrap();
323-
let saka = iso.to_calendar(Indian);
323+
let indian = iso.to_calendar(Indian);
324324
assert_eq!(
325-
saka.era_year().year,
325+
indian.era_year().year,
326326
case.expected_year,
327327
"Year check failed for case: {case:?}"
328328
);
329329
assert_eq!(
330-
saka.month().ordinal,
330+
indian.month().ordinal,
331331
case.expected_month,
332332
"Month check failed for case: {case:?}"
333333
);
334334
assert_eq!(
335-
saka.day_of_month().0,
335+
indian.day_of_month().0,
336336
case.expected_day,
337337
"Day check failed for case: {case:?}"
338338
);

components/calendar/src/cal/roc.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const ROC_ERA_OFFSET: i32 = 1911;
3939
///
4040
/// # Era codes
4141
///
42-
/// This calendar uses two era codes: `minguo`, corresponding to years in the 民國 era (CE year 1912 and
43-
/// after), and `minguo-qian`, corresponding to years before the 民國 era (CE year 1911 and before).
42+
/// This calendar uses two era codes: `roc`, corresponding to years in the 民國 era (CE year 1912 and
43+
/// after), and `broc`, corresponding to years before the 民國 era (CE year 1911 and before).
4444
///
4545
///
4646
/// # Month codes
@@ -67,8 +67,8 @@ impl Calendar for Roc {
6767
day: u8,
6868
) -> Result<Self::DateInner, DateError> {
6969
let year = match era {
70-
Some("minguo") | None => ROC_ERA_OFFSET + year_check(year, 1..)?,
71-
Some("minguo-qian") => ROC_ERA_OFFSET + 1 - year_check(year, 1..)?,
70+
Some("roc") | None => ROC_ERA_OFFSET + year_check(year, 1..)?,
71+
Some("broc") => ROC_ERA_OFFSET + 1 - year_check(year, 1..)?,
7272
Some(_) => return Err(DateError::UnknownEra),
7373
};
7474

@@ -129,14 +129,14 @@ impl Calendar for Roc {
129129
let extended_year = self.extended_year(date);
130130
if extended_year > ROC_ERA_OFFSET {
131131
types::EraYear {
132-
era: tinystr!(16, "minguo"),
132+
era: tinystr!(16, "roc"),
133133
era_index: Some(1),
134134
year: extended_year.saturating_sub(ROC_ERA_OFFSET),
135135
ambiguity: types::YearAmbiguity::CenturyRequired,
136136
}
137137
} else {
138138
types::EraYear {
139-
era: tinystr!(16, "minguo-qian"),
139+
era: tinystr!(16, "broc"),
140140
era_index: Some(0),
141141
year: (ROC_ERA_OFFSET + 1).saturating_sub(extended_year),
142142
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
@@ -185,7 +185,7 @@ impl Date<Roc> {
185185
/// let date_roc = Date::try_new_roc(1, 2, 3)
186186
/// .expect("Failed to initialize ROC Date instance.");
187187
///
188-
/// assert_eq!(date_roc.era_year().era, tinystr!(16, "minguo"));
188+
/// assert_eq!(date_roc.era_year().era, tinystr!(16, "roc"));
189189
/// assert_eq!(date_roc.era_year().year, 1, "ROC year check failed!");
190190
/// assert_eq!(date_roc.month().ordinal, 2, "ROC month check failed!");
191191
/// assert_eq!(date_roc.day_of_month().0, 3, "ROC day of month check failed!");
@@ -264,7 +264,7 @@ mod test {
264264
iso_month: 1,
265265
iso_day: 1,
266266
expected_year: 1,
267-
expected_era: "minguo",
267+
expected_era: "roc",
268268
expected_month: 1,
269269
expected_day: 1,
270270
},
@@ -274,7 +274,7 @@ mod test {
274274
iso_month: 2,
275275
iso_day: 29,
276276
expected_year: 1,
277-
expected_era: "minguo",
277+
expected_era: "roc",
278278
expected_month: 2,
279279
expected_day: 29,
280280
},
@@ -284,7 +284,7 @@ mod test {
284284
iso_month: 6,
285285
iso_day: 30,
286286
expected_year: 2,
287-
expected_era: "minguo",
287+
expected_era: "roc",
288288
expected_month: 6,
289289
expected_day: 30,
290290
},
@@ -294,7 +294,7 @@ mod test {
294294
iso_month: 7,
295295
iso_day: 13,
296296
expected_year: 112,
297-
expected_era: "minguo",
297+
expected_era: "roc",
298298
expected_month: 7,
299299
expected_day: 13,
300300
},
@@ -318,7 +318,7 @@ mod test {
318318
iso_month: 12,
319319
iso_day: 31,
320320
expected_year: 1,
321-
expected_era: "minguo-qian",
321+
expected_era: "broc",
322322
expected_month: 12,
323323
expected_day: 31,
324324
},
@@ -328,7 +328,7 @@ mod test {
328328
iso_month: 1,
329329
iso_day: 1,
330330
expected_year: 1,
331-
expected_era: "minguo-qian",
331+
expected_era: "broc",
332332
expected_month: 1,
333333
expected_day: 1,
334334
},
@@ -338,7 +338,7 @@ mod test {
338338
iso_month: 12,
339339
iso_day: 31,
340340
expected_year: 2,
341-
expected_era: "minguo-qian",
341+
expected_era: "broc",
342342
expected_month: 12,
343343
expected_day: 31,
344344
},
@@ -348,7 +348,7 @@ mod test {
348348
iso_month: 2,
349349
iso_day: 29,
350350
expected_year: 4,
351-
expected_era: "minguo-qian",
351+
expected_era: "broc",
352352
expected_month: 2,
353353
expected_day: 29,
354354
},
@@ -358,7 +358,7 @@ mod test {
358358
iso_month: 1,
359359
iso_day: 1,
360360
expected_year: 1911,
361-
expected_era: "minguo-qian",
361+
expected_era: "broc",
362362
expected_month: 1,
363363
expected_day: 1,
364364
},
@@ -368,7 +368,7 @@ mod test {
368368
iso_month: 12,
369369
iso_day: 31,
370370
expected_year: 1912,
371-
expected_era: "minguo-qian",
371+
expected_era: "broc",
372372
expected_month: 12,
373373
expected_day: 31,
374374
},

provider/source/src/calendar/eras.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ fn process_era_dates_map(
163163
"gregory-inverse" => Some("bce"),
164164
"gregory" => Some("ce"),
165165
"hebrew" => Some("am"),
166-
"indian" => Some("saka"),
166+
"indian" => Some("shaka"),
167167
islamic if islamic.starts_with("islamic") => Some("ah"),
168168
"persian" => Some("ap"),
169-
"roc-inverse" => Some("minguo-qian"),
170-
"roc" => Some("minguo"),
169+
"roc-inverse" => Some("broc"),
170+
"roc" => Some("roc"),
171171
"chinese" | "dangi" => None,
172172
"meiji" | "reiwa" | "taisho" | "showa" | "heisei" => Some(code),
173173
c => unreachable!("{c:?}"),

0 commit comments

Comments
 (0)