Skip to content

Commit 4135234

Browse files
committed
update
1 parent b886706 commit 4135234

File tree

14 files changed

+206
-244
lines changed

14 files changed

+206
-244
lines changed

components/calendar/src/any_calendar.rs

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

components/calendar/src/cal/buddhist.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const BUDDHIST_ERA_OFFSET: i32 = 543;
4242
///
4343
/// # Era codes
4444
///
45-
/// This calendar uses a single era code, `buddhist` (alias `be`), with 1 B.E. being 543 BCE.
45+
/// This calendar uses a single era code `be`, with 1 Buddhist Era being 543 BCE. Dates before this era use negative years.
4646
///
4747
/// # Month codes
4848
///
@@ -61,7 +61,7 @@ impl Calendar for Buddhist {
6161
day: u8,
6262
) -> Result<Self::DateInner, DateError> {
6363
match era {
64-
Some("buddhist" | "be") | None => {}
64+
Some("be") | None => {}
6565
_ => return Err(DateError::UnknownEra),
6666
}
6767
let year = year - BUDDHIST_ERA_OFFSET;
@@ -120,7 +120,7 @@ impl Calendar for Buddhist {
120120
types::YearInfo::new(
121121
buddhist_year,
122122
types::EraYear {
123-
standard_era: tinystr!(16, "buddhist").into(),
123+
standard_era: tinystr!(16, "be").into(),
124124
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BE")),
125125
era_year: buddhist_year,
126126
ambiguity: types::YearAmbiguity::CenturyRequired,

components/calendar/src/cal/chinese.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use icu_provider::prelude::*;
5656
///
5757
/// # Year and Era codes
5858
///
59-
/// This Calendar uses a single era code, `chinese`.
59+
/// This calendar does not use era codes.
6060
///
6161
/// Unlike the Gregorian calendar, the Chinese calendar does not traditionally count years in an infinitely
6262
/// increasing sequence. Instead, 10 "celestial stems" and 12 "terrestrial branches" are combined to form a
@@ -181,7 +181,7 @@ impl Calendar for Chinese {
181181
};
182182

183183
match era {
184-
Some("chinese") | None => {}
184+
None => {}
185185
_ => return Err(DateError::UnknownEra),
186186
}
187187

components/calendar/src/cal/coptic.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use tinystr::tinystr;
3535
///
3636
/// # Era codes
3737
///
38-
/// This calendar uses two era codes: `coptic-inverse`, and `coptic`, corresponding to the Before Diocletian and After Diocletian/Anno Martyrum
38+
/// This calendar uses two era codes: `bd`, and `am`, corresponding to the Before Diocletian and After Diocletian/Anno Martyrum
3939
/// eras. 1 A.M. is equivalent to 284 C.E.
4040
///
4141
/// # Month codes
@@ -102,8 +102,8 @@ impl Calendar for Coptic {
102102
day: u8,
103103
) -> Result<Self::DateInner, DateError> {
104104
let year = match era {
105-
Some("coptic") | None => year_check(year, 1..)?,
106-
Some("coptic-inverse") => 1 - year_check(year, 1..)?,
105+
Some("am") | None => year_check(year, 1..)?,
106+
Some("bd") => 1 - year_check(year, 1..)?,
107107
Some(_) => return Err(DateError::UnknownEra),
108108
};
109109

@@ -166,8 +166,8 @@ impl Calendar for Coptic {
166166
types::YearInfo::new(
167167
year,
168168
types::EraYear {
169-
standard_era: tinystr!(16, "coptic").into(),
170-
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AD")),
169+
standard_era: tinystr!(16, "am").into(),
170+
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AM")),
171171
era_year: year,
172172
ambiguity: types::YearAmbiguity::CenturyRequired,
173173
},
@@ -176,7 +176,7 @@ impl Calendar for Coptic {
176176
types::YearInfo::new(
177177
year,
178178
types::EraYear {
179-
standard_era: tinystr!(16, "coptic-inverse").into(),
179+
standard_era: tinystr!(16, "bd").into(),
180180
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BD")),
181181
era_year: 1 - year,
182182
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,

components/calendar/src/cal/dangi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ use icu_provider::prelude::*;
6767
/// ```
6868
/// # Era codes
6969
///
70-
/// This Calendar uses a single era code `dangi` based on the year -2332 ISO (2333 BCE) as year 1. Typically
71-
/// years will be formatted using cyclic years and the related ISO year.
70+
/// This calendar does not use era codes.
7271
///
7372
/// # Month codes
7473
///
@@ -170,7 +169,7 @@ impl Calendar for Dangi {
170169
return Err(DateError::UnknownMonthCode(month_code));
171170
};
172171
match era {
173-
Some("dangi") | None => {}
172+
None => {}
174173
_ => return Err(DateError::UnknownEra),
175174
}
176175

components/calendar/src/cal/ethiopian.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ pub enum EthiopianEraStyle {
5252
///
5353
/// # Era codes
5454
///
55-
/// This calendar always uses the `ethioaa` era (aliases `mundi`, `ethiopic-amete-alem`), where 1 Anno Mundi is 5493 BCE.
55+
/// This calendar always uses the `aa` era, where 1 Amete Alem is 5493 BCE. Dates before this era use negative years.
5656
/// Dates before that use negative year numbers.
57-
/// In the Amete Mihret scheme it uses the additional `ethiopic` era (alias `incar`), 1 Incarnation is 9 CE.
57+
/// In the Amete Mihret scheme it uses the additional `am` era, 1 Amete Mihret is 9 CE.
5858
///
5959
/// # Month codes
6060
///
@@ -120,16 +120,13 @@ impl Calendar for Ethiopian {
120120
day: u8,
121121
) -> Result<Self::DateInner, DateError> {
122122
let year = match (self.era_style(), era) {
123-
(EthiopianEraStyle::AmeteMihret, Some("incar" | "ethiopic") | None) => {
123+
(EthiopianEraStyle::AmeteMihret, Some("am") | None) => {
124124
year_check(year, 1..)? + INCARNATION_OFFSET
125125
}
126-
(EthiopianEraStyle::AmeteMihret, Some("mundi" | "ethioaa" | "ethiopic-amete-alem")) => {
126+
(EthiopianEraStyle::AmeteMihret, Some("aa")) => {
127127
year_check(year, ..=INCARNATION_OFFSET)?
128128
}
129-
(
130-
EthiopianEraStyle::AmeteAlem,
131-
Some("mundi" | "ethioaa" | "ethiopic-amete-alem") | None,
132-
) => year,
129+
(EthiopianEraStyle::AmeteAlem, Some("aa") | None) => year,
133130
(_, Some(_)) => {
134131
return Err(DateError::UnknownEra);
135132
}
@@ -203,8 +200,8 @@ impl Calendar for Ethiopian {
203200
types::YearInfo::new(
204201
year,
205202
types::EraYear {
206-
standard_era: tinystr!(16, "ethioaa").into(),
207-
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "Anno Mundi")),
203+
standard_era: tinystr!(16, "aa").into(),
204+
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "AA")),
208205
era_year: year,
209206
ambiguity: types::YearAmbiguity::CenturyRequired,
210207
},
@@ -213,8 +210,8 @@ impl Calendar for Ethiopian {
213210
types::YearInfo::new(
214211
year - INCARNATION_OFFSET,
215212
types::EraYear {
216-
standard_era: tinystr!(16, "ethiopic").into(),
217-
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "Incarnation")),
213+
standard_era: tinystr!(16, "am").into(),
214+
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AM")),
218215
era_year: year - INCARNATION_OFFSET,
219216
ambiguity: types::YearAmbiguity::CenturyRequired,
220217
},

components/calendar/src/cal/gregorian.rs

Lines changed: 16 additions & 16 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 two era codes: `gregory-inverse` (aliases `bce`, `bc`), and `gregory` (aliases `ce`, `ad`), corresponding to the BCE and CE eras.
34+
/// This calendar uses two era codes: `bce` (alias `bc`), and `ce` (alias `ad`), corresponding to the BCE and CE eras.
3535
#[derive(Copy, Clone, Debug, Default)]
3636
#[allow(clippy::exhaustive_structs)] // this type is stable
3737
pub struct Gregorian;
@@ -50,8 +50,8 @@ impl Calendar for Gregorian {
5050
day: u8,
5151
) -> Result<Self::DateInner, DateError> {
5252
let year = match era {
53-
Some("gregory-inverse" | "bce" | "bc") | None => 1 - year_check(year, 1..)?,
54-
Some("gregory" | "ad" | "ce") => year_check(year, 1..)?,
53+
Some("bce" | "bc") | None => 1 - year_check(year, 1..)?,
54+
Some("ad" | "ce") => year_check(year, 1..)?,
5555
Some(_) => return Err(DateError::UnknownEra),
5656
};
5757

@@ -111,7 +111,7 @@ impl Calendar for Gregorian {
111111
types::YearInfo::new(
112112
year,
113113
types::EraYear {
114-
standard_era: tinystr!(16, "gregory").into(),
114+
standard_era: tinystr!(16, "ce").into(),
115115
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "CE")),
116116
era_year: year,
117117
ambiguity: match year {
@@ -126,7 +126,7 @@ impl Calendar for Gregorian {
126126
types::YearInfo::new(
127127
year,
128128
types::EraYear {
129-
standard_era: tinystr!(16, "gregory-inverse").into(),
129+
standard_era: tinystr!(16, "bce").into(),
130130
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BCE")),
131131
era_year: 1_i32.saturating_sub(year),
132132
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
@@ -243,7 +243,7 @@ mod test {
243243
iso_month: 1,
244244
iso_day: 1,
245245
expected_year: 1,
246-
expected_era: Era(tinystr!(16, "gregory")),
246+
expected_era: Era(tinystr!(16, "ce")),
247247
expected_month: 1,
248248
expected_day: 1,
249249
},
@@ -253,7 +253,7 @@ mod test {
253253
iso_month: 6,
254254
iso_day: 30,
255255
expected_year: 1,
256-
expected_era: Era(tinystr!(16, "gregory")),
256+
expected_era: Era(tinystr!(16, "ce")),
257257
expected_month: 6,
258258
expected_day: 30,
259259
},
@@ -263,7 +263,7 @@ mod test {
263263
iso_month: 2,
264264
iso_day: 29,
265265
expected_year: 4,
266-
expected_era: Era(tinystr!(16, "gregory")),
266+
expected_era: Era(tinystr!(16, "ce")),
267267
expected_month: 2,
268268
expected_day: 29,
269269
},
@@ -273,7 +273,7 @@ mod test {
273273
iso_month: 9,
274274
iso_day: 5,
275275
expected_year: 4,
276-
expected_era: Era(tinystr!(16, "gregory")),
276+
expected_era: Era(tinystr!(16, "ce")),
277277
expected_month: 9,
278278
expected_day: 5,
279279
},
@@ -283,7 +283,7 @@ mod test {
283283
iso_month: 3,
284284
iso_day: 1,
285285
expected_year: 100,
286-
expected_era: Era(tinystr!(16, "gregory")),
286+
expected_era: Era(tinystr!(16, "ce")),
287287
expected_month: 3,
288288
expected_day: 1,
289289
},
@@ -297,7 +297,7 @@ mod test {
297297
#[test]
298298
fn test_gregorian_bce() {
299299
// Tests that the Gregorian calendar gives the correct expected
300-
// day, month, and year for negative years (BC/BCE/pre-gregory era)
300+
// day, month, and year for negative years (BC/BCE era)
301301

302302
let cases = [
303303
TestCase {
@@ -306,7 +306,7 @@ mod test {
306306
iso_month: 12,
307307
iso_day: 31,
308308
expected_year: 1,
309-
expected_era: Era(tinystr!(16, "gregory-inverse")),
309+
expected_era: Era(tinystr!(16, "bce")),
310310
expected_month: 12,
311311
expected_day: 31,
312312
},
@@ -316,7 +316,7 @@ mod test {
316316
iso_month: 1,
317317
iso_day: 1,
318318
expected_year: 1,
319-
expected_era: Era(tinystr!(16, "gregory-inverse")),
319+
expected_era: Era(tinystr!(16, "bce")),
320320
expected_month: 1,
321321
expected_day: 1,
322322
},
@@ -326,7 +326,7 @@ mod test {
326326
iso_month: 12,
327327
iso_day: 31,
328328
expected_year: 2,
329-
expected_era: Era(tinystr!(16, "gregory-inverse")),
329+
expected_era: Era(tinystr!(16, "bce")),
330330
expected_month: 12,
331331
expected_day: 31,
332332
},
@@ -336,7 +336,7 @@ mod test {
336336
iso_month: 12,
337337
iso_day: 31,
338338
expected_year: 5,
339-
expected_era: Era(tinystr!(16, "gregory-inverse")),
339+
expected_era: Era(tinystr!(16, "bce")),
340340
expected_month: 12,
341341
expected_day: 31,
342342
},
@@ -346,7 +346,7 @@ mod test {
346346
iso_month: 1,
347347
iso_day: 1,
348348
expected_year: 5,
349-
expected_era: Era(tinystr!(16, "gregory-inverse")),
349+
expected_era: Era(tinystr!(16, "bce")),
350350
expected_month: 1,
351351
expected_day: 1,
352352
},

components/calendar/src/cal/hebrew.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use calendrical_calculations::rata_die::RataDie;
3535
///
3636
/// # Era codes
3737
///
38-
/// This calendar uses a single era code `hebrew` (alias `am`), Anno Mundi.
38+
/// This calendar uses a single era code `am`, Anno Mundi. Dates before this era use negative years.
3939
///
4040
/// # Month codes
4141
///
@@ -141,7 +141,7 @@ impl Calendar for Hebrew {
141141
day: u8,
142142
) -> Result<Self::DateInner, DateError> {
143143
match era {
144-
Some("hebrew" | "am") | None => {}
144+
Some("am") | None => {}
145145
_ => return Err(DateError::UnknownEra),
146146
}
147147

@@ -262,8 +262,8 @@ impl Calendar for Hebrew {
262262
types::YearInfo::new(
263263
date.0.year.value,
264264
types::EraYear {
265+
standard_era: tinystr!(16, "am").into(),
265266
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "AM")),
266-
standard_era: tinystr!(16, "hebrew").into(),
267267
era_year: date.0.year.value,
268268
ambiguity: types::YearAmbiguity::CenturyRequired,
269269
},
@@ -489,15 +489,12 @@ mod tests {
489489
// Era year is accessible via the public getter.
490490
// TODO(#3962): Make extended year publicly accessible.
491491
assert_eq!(greg_date.inner.0 .0.year, -5000);
492-
assert_eq!(
493-
greg_date.year().standard_era().unwrap().0,
494-
"gregory-inverse"
495-
);
492+
assert_eq!(greg_date.year().standard_era().unwrap().0, "bce");
496493
// In Gregorian, era year is 1 - extended year
497494
assert_eq!(greg_date.year().era_year().unwrap(), 5001);
498495
let hebr_date = greg_date.to_calendar(Hebrew);
499496
assert_eq!(hebr_date.inner.0.year.value, -1240);
500-
assert_eq!(hebr_date.year().standard_era().unwrap().0, "hebrew");
497+
assert_eq!(hebr_date.year().standard_era().unwrap().0, "am");
501498
// In Hebrew, there is no inverse era, so negative extended years are negative era years
502499
assert_eq!(hebr_date.year().era_year_or_extended(), -1240);
503500
}

0 commit comments

Comments
 (0)