Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 95 additions & 95 deletions components/calendar/src/any_calendar.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions components/calendar/src/cal/buddhist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const BUDDHIST_ERA_OFFSET: i32 = 543;
///
/// # Era codes
///
/// This calendar uses a single era code, `buddhist` (alias `be`), with 1 B.E. being 543 BCE.
/// This calendar uses a single era code `be`, with 1 Buddhist Era being 543 BCE. Dates before this era use negative years.
///
/// # Month codes
///
Expand All @@ -61,7 +61,7 @@ impl Calendar for Buddhist {
day: u8,
) -> Result<Self::DateInner, DateError> {
match era {
Some("buddhist" | "be") | None => {}
Some("be") | None => {}
_ => return Err(DateError::UnknownEra),
}
let year = year - BUDDHIST_ERA_OFFSET;
Expand Down Expand Up @@ -120,7 +120,7 @@ impl Calendar for Buddhist {
types::YearInfo::new(
buddhist_year,
types::EraYear {
standard_era: tinystr!(16, "buddhist").into(),
standard_era: tinystr!(16, "be").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BE")),
era_year: buddhist_year,
ambiguity: types::YearAmbiguity::CenturyRequired,
Expand Down
4 changes: 2 additions & 2 deletions components/calendar/src/cal/chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use icu_provider::prelude::*;
///
/// # Year and Era codes
///
/// This Calendar uses a single era code, `chinese`.
/// This calendar does not use era codes.
///
/// Unlike the Gregorian calendar, the Chinese calendar does not traditionally count years in an infinitely
/// increasing sequence. Instead, 10 "celestial stems" and 12 "terrestrial branches" are combined to form a
Expand Down Expand Up @@ -181,7 +181,7 @@ impl Calendar for Chinese {
};

match era {
Some("chinese") | None => {}
None => {}
_ => return Err(DateError::UnknownEra),
}

Expand Down
12 changes: 6 additions & 6 deletions components/calendar/src/cal/coptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use tinystr::tinystr;
///
/// # Era codes
///
/// This calendar uses two era codes: `coptic-inverse`, and `coptic`, corresponding to the Before Diocletian and After Diocletian/Anno Martyrum
/// This calendar uses two era codes: `bd`, and `am`, corresponding to the Before Diocletian and After Diocletian/Anno Martyrum
/// eras. 1 A.M. is equivalent to 284 C.E.
///
/// # Month codes
Expand Down Expand Up @@ -102,8 +102,8 @@ impl Calendar for Coptic {
day: u8,
) -> Result<Self::DateInner, DateError> {
let year = match era {
Some("coptic") | None => year_check(year, 1..)?,
Some("coptic-inverse") => 1 - year_check(year, 1..)?,
Some("am") | None => year_check(year, 1..)?,
Some("bd") => 1 - year_check(year, 1..)?,
Some(_) => return Err(DateError::UnknownEra),
};

Expand Down Expand Up @@ -166,8 +166,8 @@ impl Calendar for Coptic {
types::YearInfo::new(
year,
types::EraYear {
standard_era: tinystr!(16, "coptic").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AD")),
standard_era: tinystr!(16, "am").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AM")),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
Expand All @@ -176,7 +176,7 @@ impl Calendar for Coptic {
types::YearInfo::new(
year,
types::EraYear {
standard_era: tinystr!(16, "coptic-inverse").into(),
standard_era: tinystr!(16, "bd").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BD")),
era_year: 1 - year,
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
Expand Down
5 changes: 2 additions & 3 deletions components/calendar/src/cal/dangi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ use icu_provider::prelude::*;
/// ```
/// # Era codes
///
/// This Calendar uses a single era code `dangi` based on the year -2332 ISO (2333 BCE) as year 1. Typically
/// years will be formatted using cyclic years and the related ISO year.
/// This calendar does not use era codes.
///
/// # Month codes
///
Expand Down Expand Up @@ -170,7 +169,7 @@ impl Calendar for Dangi {
return Err(DateError::UnknownMonthCode(month_code));
};
match era {
Some("dangi") | None => {}
None => {}
_ => return Err(DateError::UnknownEra),
}

Expand Down
21 changes: 9 additions & 12 deletions components/calendar/src/cal/ethiopian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub enum EthiopianEraStyle {
///
/// # Era codes
///
/// This calendar always uses the `ethioaa` era (aliases `mundi`, `ethiopic-amete-alem`), where 1 Anno Mundi is 5493 BCE.
/// This calendar always uses the `aa` era, where 1 Amete Alem is 5493 BCE. Dates before this era use negative years.
/// Dates before that use negative year numbers.
/// In the Amete Mihret scheme it uses the additional `ethiopic` era (alias `incar`), 1 Incarnation is 9 CE.
/// In the Amete Mihret scheme it uses the additional `am` era, 1 Amete Mihret is 9 CE.
///
/// # Month codes
///
Expand Down Expand Up @@ -120,16 +120,13 @@ impl Calendar for Ethiopian {
day: u8,
) -> Result<Self::DateInner, DateError> {
let year = match (self.era_style(), era) {
(EthiopianEraStyle::AmeteMihret, Some("incar" | "ethiopic") | None) => {
(EthiopianEraStyle::AmeteMihret, Some("am") | None) => {
year_check(year, 1..)? + INCARNATION_OFFSET
}
(EthiopianEraStyle::AmeteMihret, Some("mundi" | "ethioaa" | "ethiopic-amete-alem")) => {
(EthiopianEraStyle::AmeteMihret, Some("aa")) => {
year_check(year, ..=INCARNATION_OFFSET)?
}
(
EthiopianEraStyle::AmeteAlem,
Some("mundi" | "ethioaa" | "ethiopic-amete-alem") | None,
) => year,
(EthiopianEraStyle::AmeteAlem, Some("aa") | None) => year,
(_, Some(_)) => {
return Err(DateError::UnknownEra);
}
Expand Down Expand Up @@ -203,8 +200,8 @@ impl Calendar for Ethiopian {
types::YearInfo::new(
year,
types::EraYear {
standard_era: tinystr!(16, "ethioaa").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "Anno Mundi")),
standard_era: tinystr!(16, "aa").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "AA")),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
Expand All @@ -213,8 +210,8 @@ impl Calendar for Ethiopian {
types::YearInfo::new(
year - INCARNATION_OFFSET,
types::EraYear {
standard_era: tinystr!(16, "ethiopic").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "Incarnation")),
standard_era: tinystr!(16, "am").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AM")),
era_year: year - INCARNATION_OFFSET,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
Expand Down
32 changes: 16 additions & 16 deletions components/calendar/src/cal/gregorian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use tinystr::tinystr;
///
/// # Era codes
///
/// This calendar uses two era codes: `gregory-inverse` (aliases `bce`, `bc`), and `gregory` (aliases `ce`, `ad`), corresponding to the BCE and CE eras.
/// This calendar uses two era codes: `bce` (alias `bc`), and `ce` (alias `ad`), corresponding to the BCE and CE eras.
#[derive(Copy, Clone, Debug, Default)]
#[allow(clippy::exhaustive_structs)] // this type is stable
pub struct Gregorian;
Expand All @@ -50,8 +50,8 @@ impl Calendar for Gregorian {
day: u8,
) -> Result<Self::DateInner, DateError> {
let year = match era {
Some("gregory-inverse" | "bce" | "bc") | None => 1 - year_check(year, 1..)?,
Some("gregory" | "ad" | "ce") => year_check(year, 1..)?,
Some("bce" | "bc") | None => 1 - year_check(year, 1..)?,
Some("ad" | "ce") => year_check(year, 1..)?,
Some(_) => return Err(DateError::UnknownEra),
};

Expand Down Expand Up @@ -111,7 +111,7 @@ impl Calendar for Gregorian {
types::YearInfo::new(
year,
types::EraYear {
standard_era: tinystr!(16, "gregory").into(),
standard_era: tinystr!(16, "ce").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "CE")),
era_year: year,
ambiguity: match year {
Expand All @@ -126,7 +126,7 @@ impl Calendar for Gregorian {
types::YearInfo::new(
year,
types::EraYear {
standard_era: tinystr!(16, "gregory-inverse").into(),
standard_era: tinystr!(16, "bce").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BCE")),
era_year: 1_i32.saturating_sub(year),
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
Expand Down Expand Up @@ -243,7 +243,7 @@ mod test {
iso_month: 1,
iso_day: 1,
expected_year: 1,
expected_era: Era(tinystr!(16, "gregory")),
expected_era: Era(tinystr!(16, "ce")),
expected_month: 1,
expected_day: 1,
},
Expand All @@ -253,7 +253,7 @@ mod test {
iso_month: 6,
iso_day: 30,
expected_year: 1,
expected_era: Era(tinystr!(16, "gregory")),
expected_era: Era(tinystr!(16, "ce")),
expected_month: 6,
expected_day: 30,
},
Expand All @@ -263,7 +263,7 @@ mod test {
iso_month: 2,
iso_day: 29,
expected_year: 4,
expected_era: Era(tinystr!(16, "gregory")),
expected_era: Era(tinystr!(16, "ce")),
expected_month: 2,
expected_day: 29,
},
Expand All @@ -273,7 +273,7 @@ mod test {
iso_month: 9,
iso_day: 5,
expected_year: 4,
expected_era: Era(tinystr!(16, "gregory")),
expected_era: Era(tinystr!(16, "ce")),
expected_month: 9,
expected_day: 5,
},
Expand All @@ -283,7 +283,7 @@ mod test {
iso_month: 3,
iso_day: 1,
expected_year: 100,
expected_era: Era(tinystr!(16, "gregory")),
expected_era: Era(tinystr!(16, "ce")),
expected_month: 3,
expected_day: 1,
},
Expand All @@ -297,7 +297,7 @@ mod test {
#[test]
fn test_gregorian_bce() {
// Tests that the Gregorian calendar gives the correct expected
// day, month, and year for negative years (BC/BCE/pre-gregory era)
// day, month, and year for negative years (BC/BCE era)

let cases = [
TestCase {
Expand All @@ -306,7 +306,7 @@ mod test {
iso_month: 12,
iso_day: 31,
expected_year: 1,
expected_era: Era(tinystr!(16, "gregory-inverse")),
expected_era: Era(tinystr!(16, "bce")),
expected_month: 12,
expected_day: 31,
},
Expand All @@ -316,7 +316,7 @@ mod test {
iso_month: 1,
iso_day: 1,
expected_year: 1,
expected_era: Era(tinystr!(16, "gregory-inverse")),
expected_era: Era(tinystr!(16, "bce")),
expected_month: 1,
expected_day: 1,
},
Expand All @@ -326,7 +326,7 @@ mod test {
iso_month: 12,
iso_day: 31,
expected_year: 2,
expected_era: Era(tinystr!(16, "gregory-inverse")),
expected_era: Era(tinystr!(16, "bce")),
expected_month: 12,
expected_day: 31,
},
Expand All @@ -336,7 +336,7 @@ mod test {
iso_month: 12,
iso_day: 31,
expected_year: 5,
expected_era: Era(tinystr!(16, "gregory-inverse")),
expected_era: Era(tinystr!(16, "bce")),
expected_month: 12,
expected_day: 31,
},
Expand All @@ -346,7 +346,7 @@ mod test {
iso_month: 1,
iso_day: 1,
expected_year: 5,
expected_era: Era(tinystr!(16, "gregory-inverse")),
expected_era: Era(tinystr!(16, "bce")),
expected_month: 1,
expected_day: 1,
},
Expand Down
13 changes: 5 additions & 8 deletions components/calendar/src/cal/hebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use calendrical_calculations::rata_die::RataDie;
///
/// # Era codes
///
/// This calendar uses a single era code `hebrew` (alias `am`), Anno Mundi.
/// This calendar uses a single era code `am`, Anno Mundi. Dates before this era use negative years.
///
/// # Month codes
///
Expand Down Expand Up @@ -141,7 +141,7 @@ impl Calendar for Hebrew {
day: u8,
) -> Result<Self::DateInner, DateError> {
match era {
Some("hebrew" | "am") | None => {}
Some("am") | None => {}
_ => return Err(DateError::UnknownEra),
}

Expand Down Expand Up @@ -262,8 +262,8 @@ impl Calendar for Hebrew {
types::YearInfo::new(
date.0.year.value,
types::EraYear {
standard_era: tinystr!(16, "am").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "AM")),
standard_era: tinystr!(16, "hebrew").into(),
era_year: date.0.year.value,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
Expand Down Expand Up @@ -489,15 +489,12 @@ mod tests {
// Era year is accessible via the public getter.
// TODO(#3962): Make extended year publicly accessible.
assert_eq!(greg_date.inner.0 .0.year, -5000);
assert_eq!(
greg_date.year().standard_era().unwrap().0,
"gregory-inverse"
);
assert_eq!(greg_date.year().standard_era().unwrap().0, "bce");
// In Gregorian, era year is 1 - extended year
assert_eq!(greg_date.year().era_year().unwrap(), 5001);
let hebr_date = greg_date.to_calendar(Hebrew);
assert_eq!(hebr_date.inner.0.year.value, -1240);
assert_eq!(hebr_date.year().standard_era().unwrap().0, "hebrew");
assert_eq!(hebr_date.year().standard_era().unwrap().0, "am");
// In Hebrew, there is no inverse era, so negative extended years are negative era years
assert_eq!(hebr_date.year().era_year_or_extended(), -1240);
}
Expand Down
Loading