Skip to content

Commit

Permalink
Merge branch 'main' into normalizerdata
Browse files Browse the repository at this point in the history
  • Loading branch information
hsivonen authored Nov 14, 2024
2 parents 505f1cf + 11f42d9 commit 380df55
Show file tree
Hide file tree
Showing 1,947 changed files with 18,447 additions and 44,343 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ icu = "1.5.0"

```rust
use icu::calendar::DateTime;
use icu::datetime::{DateTimeFormatter, NeoSkeletonLength, fieldset::YMDHMS};
use icu::datetime::{DateTimeFormatter, NeoSkeletonLength, fieldset::YMDT};
use icu::locale::locale;

let dtf = DateTimeFormatter::try_new(
&locale!("es").into(),
YMDHMS::long()
YMDT::long()
)
.expect("locale should be present in compiled data");

Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/buddhist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ fn iso_year_as_buddhist(year: i32) -> types::YearInfo {
standard_era: tinystr!(16, "buddhist").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BE")),
era_year: buddhist_year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions components/calendar/src/coptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ fn year_as_coptic(year: i32) -> types::YearInfo {
standard_era: tinystr!(16, "coptic").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AD")),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
} else {
Expand All @@ -322,6 +323,7 @@ fn year_as_coptic(year: i32) -> types::YearInfo {
standard_era: tinystr!(16, "coptic-inverse").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BD")),
era_year: 1 - year,
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
},
)
}
Expand Down
3 changes: 3 additions & 0 deletions components/calendar/src/ethiopian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl Ethiopian {
standard_era: tinystr!(16, "ethioaa").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "Anno Mundi")),
era_year: year + AMETE_ALEM_OFFSET,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
} else if year > 0 {
Expand All @@ -313,6 +314,7 @@ impl Ethiopian {
standard_era: tinystr!(16, "ethiopic").into(),
formatting_era: types::FormattingEra::Index(2, tinystr!(16, "Incarnation")),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
} else {
Expand All @@ -322,6 +324,7 @@ impl Ethiopian {
standard_era: tinystr!(16, "ethiopic-inverse").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "Pre-Incarnation")),
era_year: 1 - year,
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
},
)
}
Expand Down
7 changes: 7 additions & 0 deletions components/calendar/src/gregorian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ fn year_as_gregorian(year: i32) -> types::YearInfo {
standard_era: tinystr!(16, "gregory").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "CE")),
era_year: year,
ambiguity: match year {
..=999 => types::YearAmbiguity::EraAndCenturyRequired,
1000..=1949 => types::YearAmbiguity::CenturyRequired,
1950..=2049 => types::YearAmbiguity::Unambiguous,
2050.. => types::YearAmbiguity::CenturyRequired,
},
},
)
} else {
Expand All @@ -247,6 +253,7 @@ fn year_as_gregorian(year: i32) -> types::YearInfo {
standard_era: tinystr!(16, "gregory-inverse").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BCE")),
era_year: 1_i32.saturating_sub(year),
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
},
)
}
Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/hebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ impl Hebrew {
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "AM")),
standard_era: tinystr!(16, "hebrew").into(),
era_year: civil_year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
}
Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/indian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fn year_as_saka(year: i32) -> types::YearInfo {
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "Saka")),
standard_era: tinystr!(16, "saka").into(),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
}
Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/islamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn year_as_islamic(standard_era: tinystr::TinyStr16, year: i32) -> types::YearIn
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "AH")),
standard_era: standard_era.into(),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
}
Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ impl Iso {
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "")),
standard_era: tinystr!(16, "default").into(),
era_year: year,
ambiguity: types::YearAmbiguity::Unambiguous,
},
)
}
Expand Down
6 changes: 1 addition & 5 deletions components/calendar/src/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ impl Calendar for Japanese {
formatting_era: types::FormattingEra::Code(date.era.into()),
standard_era: date.era.into(),
era_year: date.adjusted_year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
}
Expand Down Expand Up @@ -505,11 +506,6 @@ impl Date<JapaneseExtended> {
.new_japanese_date_inner(era, year, month, day)?;
Ok(Date::from_raw(inner, japanext_calendar))
}

#[doc(hidden)] // for testing
pub fn into_japanese_date(self) -> Date<Japanese> {
Date::from_raw(self.inner, self.calendar.0)
}
}

impl DateTime<Japanese> {
Expand Down
2 changes: 2 additions & 0 deletions components/calendar/src/julian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn year_as_julian(year: i32) -> types::YearInfo {
standard_era: tinystr!(16, "julian").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "AD")),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
} else {
Expand All @@ -237,6 +238,7 @@ fn year_as_julian(year: i32) -> types::YearInfo {
standard_era: tinystr!(16, "julian-inverse").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "BC")),
era_year: 1_i32.saturating_sub(year),
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
},
)
}
Expand Down
1 change: 1 addition & 0 deletions components/calendar/src/persian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ impl Persian {
standard_era: tinystr!(16, "persian").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "AH")),
era_year: year,
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions components/calendar/src/roc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub(crate) fn year_as_roc(year: i64) -> types::YearInfo {
standard_era: tinystr!(16, "roc").into(),
formatting_era: types::FormattingEra::Index(1, tinystr!(16, "ROC")),
era_year: year_i32.saturating_sub(ROC_ERA_OFFSET),
ambiguity: types::YearAmbiguity::CenturyRequired,
},
)
} else {
Expand All @@ -284,6 +285,7 @@ pub(crate) fn year_as_roc(year: i64) -> types::YearInfo {
standard_era: tinystr!(16, "roc-inverse").into(),
formatting_era: types::FormattingEra::Index(0, tinystr!(16, "B. ROC")),
era_year: (ROC_ERA_OFFSET + 1).saturating_sub(year_i32),
ambiguity: types::YearAmbiguity::EraAndCenturyRequired,
},
)
}
Expand Down
35 changes: 34 additions & 1 deletion components/calendar/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ impl YearInfo {
}
}

/// Get the year ambiguity.
pub fn year_ambiguity(self) -> YearAmbiguity {
match self.kind {
YearKind::Cyclic(_) => YearAmbiguity::EraRequired,
YearKind::Era(e) => e.ambiguity,
}
}

/// Get *some* year number that can be displayed
///
/// Gets the eraYear for era dates, otherwise falls back to Extended Year
Expand Down Expand Up @@ -123,6 +131,23 @@ impl YearInfo {
}
}

/// Defines whether the era or century is required to interpret the year.
///
/// For example 2024 AD can be formatted as `2024`, or even `24`, but 1931 AD
/// should not be formatted as `31`, and 2024 BC should not be formatted as `2024`.
#[derive(Copy, Clone, Debug, PartialEq)]
#[allow(clippy::exhaustive_enums)] // logically complete
pub enum YearAmbiguity {
/// The year is unambiguous without a century or era.
Unambiguous,
/// The century is required, the era may be included.
CenturyRequired,
/// The era is required, the century may be included.
EraRequired,
/// The century and era are required.
EraAndCenturyRequired,
}

/// Information about the era as usable for formatting
///
/// This is optimized for storing datetime formatting data.
Expand All @@ -146,7 +171,7 @@ pub enum FormattingEra {

impl FormattingEra {
/// Get a fallback era name suitable for display to the user when the real era name is not availabe
pub fn fallback_era(self) -> TinyStr16 {
pub fn fallback_name(self) -> TinyStr16 {
match self {
Self::Index(_idx, fallback) => fallback,
Self::Code(era) => era.0,
Expand All @@ -172,6 +197,8 @@ pub struct EraYear {
pub standard_era: Era,
/// The numeric year in that era
pub era_year: i32,
/// The ambiguity when formatting this year
pub ambiguity: YearAmbiguity,
}

/// Year information for a year that is specified as a cyclic year
Expand Down Expand Up @@ -466,6 +493,12 @@ macro_rules! dt_unit {
pub fn try_sub(self, other: $storage) -> Option<Self> {
self.0.checked_sub(other).map(Self)
}

/// Returns whether the value is zero.
#[inline]
pub fn is_zero(self) -> bool {
self.0 == 0
}
}
};
}
Expand Down
4 changes: 0 additions & 4 deletions components/calendar/src/week_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ impl WeekCalculator {
icu_provider::gen_any_buffer_data_constructors!(
(locale) -> error: DataError,
/// Creates a new [`WeekCalculator`] from compiled data.
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
///
/// [📚 Help choosing a constructor](icu_provider::constructors)
);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
Expand Down
1 change: 1 addition & 0 deletions components/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ all-features = true
displaydoc = { workspace = true }
icu_collections = { workspace = true }
icu_normalizer = { workspace = true }
icu_locale_core = { workspace = true }
icu_properties = { workspace = true }
icu_provider = { workspace = true, features = ["macros"] }
utf8_iter = { workspace = true }
Expand Down
Loading

0 comments on commit 380df55

Please sign in to comment.