Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into neo-months-linear
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 25, 2023
2 parents e072c81 + d06182a commit b874b09
Show file tree
Hide file tree
Showing 124 changed files with 6,917 additions and 279 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ members = [
"experimental/displaynames",
"experimental/personnames",
"experimental/relativetime",
"experimental/single_number_formatter",
"experimental/singlenumberformatter",
"experimental/transliterate",
"experimental/unicodeset_parse",
"experimental/unitsconversion",
Expand Down Expand Up @@ -162,7 +162,7 @@ icu_compactdecimal = { version = "0.2.2", path = "experimental/compactdecimal",
icu_displaynames = { version = "0.11.1", path = "experimental/displaynames", default-features = false }
icu_personnames = { version = "0.0.0", path = "experimental/personnames", default-features = false }
icu_relativetime = { version = "0.1.3", path = "experimental/relativetime", default-features = false }
icu_singlenumberformatter = { version = "0.0.0", path = "experimental/single_number_formatter", default-features = false }
icu_singlenumberformatter = { version = "0.0.0", path = "experimental/singlenumberformatter", default-features = false }
icu_transliterate = { version = "0.1.1", path = "experimental/transliterate", default-features = false }
icu_unicodeset_parse = { version = "0.1.1", path = "experimental/unicodeset_parse", default-features = false }
icu_unitsconversion = { version = "0.0.0", path = "experimental/unitsconversion", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/testing/patch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ icu_compactdecimal = { path = "../../experimental/compactdecimal" }
icu_displaynames = { path = "../../experimental/displaynames" }
icu_personnames = { path = "../../experimental/personnames" }
icu_relativetime = { path = "../../experimental/relativetime" }
icu_singlenumberformatter = { path = "../../experimental/single_number_formatter"}
icu_singlenumberformatter = { path = "../../experimental/singlenumberformatter"}
icu_transliterate = { path = "../../experimental/transliterate" }
icu_unicodeset_parse = { path = "../../experimental/unicodeset_parse" }
icu_unitsconversion = { path = "../../experimental/unitsconversion" }
Expand Down
File renamed without changes.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions provider/datagen/src/transform/cldr/calendar/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ impl crate::DatagenProvider {
"ca-japanese.json does not contain 'japanese' calendar",
))?
.eras
.as_ref()
.expect("japanese must have eras")
.abbr;

let era_dates_map = &self
Expand Down
11 changes: 9 additions & 2 deletions provider/datagen/src/transform/cldr/cldr_serde/ca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use serde::Deserialize;
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::collections::HashMap;

#[derive(Debug, PartialEq, Clone, Deserialize)]
Expand Down Expand Up @@ -235,6 +236,11 @@ impl DateTimeFormats {
#[derive(PartialEq, Clone, Debug, Deserialize)]
pub struct AvailableFormats(pub HashMap<String, String>);

#[derive(PartialEq, Clone, Debug, Deserialize)]
pub struct CyclicNameSets {
pub years: Option<Contexts<BTreeMap<u8, String>>>,
}

/// This struct represents a 1:1 mapping of the CLDR ca-gregorian.json data at the key
/// "main.LANGID.dates.calendars.gregorian" where "LANGID" is the identifier.
///
Expand All @@ -246,8 +252,9 @@ pub struct Dates {
#[serde(rename = "monthPatterns")]
pub month_patterns: Option<Contexts<MonthPatternSymbols>>,
pub days: Contexts<DaySymbols>,
#[serde(default)]
pub eras: Eras,
pub eras: Option<Eras>,
#[serde(rename = "cyclicNameSets")]
pub cyclic_name_sets: Option<CyclicNameSets>,
#[serde(rename = "dayPeriods")]
pub day_periods: Contexts<DayPeriodSymbols>,
#[serde(rename = "dateFormats")]
Expand Down
58 changes: 26 additions & 32 deletions provider/datagen/src/transform/cldr/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,34 @@ macro_rules! impl_data_provider {
.expect("CLDR ca-ethiopic-amete-alem.json contains the expected calendar")
.clone();

let mundi_name = ethioaa_data
.eras
let ethioaa_eras = ethioaa_data.eras.as_ref().expect("ethioaa must have eras");
let mundi_name = ethioaa_eras
.names
.get("0")
.expect("ethiopic-amete-alem calendar must have 0 era");
let mundi_abbr = ethioaa_data
.eras
let mundi_abbr = ethioaa_eras
.abbr
.get("0")
.expect("ethiopic-amete-alem calendar must have 0 era");
let mundi_narrow = ethioaa_data
.eras
let mundi_narrow = ethioaa_eras
.narrow
.get("0")
.expect("ethiopic-amete-alem calendar must have 0 era");

data.eras.names.insert("2".to_string(), mundi_name.clone());
data.eras.abbr.insert("2".to_string(), mundi_abbr.clone());
data.eras
.narrow
.insert("2".to_string(), mundi_narrow.clone());
let eras = data.eras.as_mut().expect("ethiopic must have eras");
eras.names.insert("2".to_string(), mundi_name.clone());
eras.abbr.insert("2".to_string(), mundi_abbr.clone());
eras.narrow.insert("2".to_string(), mundi_narrow.clone());
}

if calendar == value!("japanese") || calendar == value!("japanext") {
let eras = data.eras.as_mut().expect("japanese must have eras");
// Filter out non-modern eras
if calendar != value!("japanext") {
let modern_japanese_eras = self.cldr()?.modern_japanese_eras()?;
data.eras
.names
.retain(|e, _| modern_japanese_eras.contains(e));
data.eras
.abbr
.retain(|e, _| modern_japanese_eras.contains(e));
data.eras
.narrow
.retain(|e, _| modern_japanese_eras.contains(e));
eras.names.retain(|e, _| modern_japanese_eras.contains(e));
eras.abbr.retain(|e, _| modern_japanese_eras.contains(e));
eras.narrow.retain(|e, _| modern_japanese_eras.contains(e));
}

// Splice in gregorian data for pre-meiji
Expand All @@ -152,49 +144,51 @@ macro_rules! impl_data_provider {
.expect("CLDR file contains a gregorian calendar")
.clone();

data.eras.names.insert(
let greg_eras = greg.eras.as_ref().expect("gregorian must have eras");

eras.names.insert(
"-2".into(),
greg.eras
greg_eras
.names
.get("0")
.expect("Gregorian calendar must have data for BC")
.into(),
);
data.eras.names.insert(
eras.names.insert(
"-1".into(),
greg.eras
greg_eras
.names
.get("1")
.expect("Gregorian calendar must have data for AD")
.into(),
);
data.eras.abbr.insert(
eras.abbr.insert(
"-2".into(),
greg.eras
greg_eras
.abbr
.get("0")
.expect("Gregorian calendar must have data for BC")
.into(),
);
data.eras.abbr.insert(
eras.abbr.insert(
"-1".into(),
greg.eras
greg_eras
.abbr
.get("1")
.expect("Gregorian calendar must have data for AD")
.into(),
);
data.eras.narrow.insert(
eras.narrow.insert(
"-2".into(),
greg.eras
greg_eras
.narrow
.get("0")
.expect("Gregorian calendar must have data for BC")
.into(),
);
data.eras.narrow.insert(
eras.narrow.insert(
"-1".into(),
greg.eras
greg_eras
.narrow
.get("1")
.expect("Gregorian calendar must have data for AD")
Expand Down
59 changes: 46 additions & 13 deletions provider/datagen/src/transform/cldr/datetime/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,14 @@ fn dayperiods_convert(
})
}

fn years_convert(
fn eras_convert(
datagen: &DatagenProvider,
langid: &LanguageIdentifier,
data: &ca::Dates,
eras: &ca::Eras,
calendar: &Value,
context: Context,
length: Length,
) -> Result<YearSymbolsV1<'static>, DataError> {
assert_eq!(
context,
Context::Format,
"Eras do not participate in standalone formatting"
);

let eras = data.eras.load(length);

let eras = eras.load(length);
// Tostring can be removed when we delete symbols.rs, or we can perhaps refactor it to use Value
let calendar_str = calendar.to_string();
let map = super::symbols::get_era_code_map(&calendar_str);
Expand All @@ -332,6 +324,8 @@ fn years_convert(
Some(
ethioaa_data
.eras
.as_ref()
.expect("ethiopic-amete-alem must have eras")
.load(length)
.get("0")
.expect("ethiopic-amete-alem calendar must have 0 era"),
Expand Down Expand Up @@ -360,7 +354,11 @@ fn years_convert(
.get("gregorian")
.expect("CLDR gregorian.json contains the expected calendar");

let eras = greg_data.eras.load(length);
let eras = greg_data
.eras
.as_ref()
.expect("gregorian must have eras")
.load(length);
Some((
eras.get("0").expect("gregorian calendar must have 0 era"),
eras.get("1").expect("gregorian calendar must have 1 era"),
Expand Down Expand Up @@ -398,14 +396,49 @@ fn years_convert(
}
}

// Todo: Cyclic years (#3761)
Ok(YearSymbolsV1::Eras(
out_eras
.iter()
.map(|(k, v)| (UnvalidatedStr::from_str(k), &**v))
.collect(),
))
}
fn years_convert(
datagen: &DatagenProvider,
langid: &LanguageIdentifier,
data: &ca::Dates,
calendar: &Value,
context: Context,
length: Length,
) -> Result<YearSymbolsV1<'static>, DataError> {
assert_eq!(
context,
Context::Format,
"Eras and cyclic years do not participate in standalone formatting"
);

if let Some(ref eras) = data.eras {
eras_convert(datagen, langid, eras, calendar, length)
} else if let Some(years) = data
.cyclic_name_sets
.as_ref()
.and_then(|c| c.years.as_ref())
{
let years = years.get_symbols(context, length);

let years: Vec<_> = years.iter().enumerate().map(|(index, (key, value))| {
if *key as usize != index + 1 {
panic!("Calendar {calendar} in locale {langid} missing cyclic year name for index {index}");
}
&**value
}).collect();
Ok(YearSymbolsV1::Cyclic((&years).into()))
} else {
panic!(
"Calendar {calendar} in locale {langid} has neither eras nor cyclicNameSets for years"
)
}
}

/// Returns the number of regular months in a calendar, as well as whether it is
/// has leap months
Expand Down
7 changes: 6 additions & 1 deletion provider/datagen/src/transform/cldr/datetime/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ use std::collections::BTreeMap;
use tinystr::{tinystr, TinyStr16, TinyStr4};

pub fn convert_dates(other: &cldr_serde::ca::Dates, calendar: &str) -> DateSymbolsV1<'static> {
let eras = if let Some(ref eras) = other.eras {
convert_eras(eras, calendar)
} else {
Default::default()
};
DateSymbolsV1 {
months: other.months.get(&(get_month_code_map(calendar), calendar)),
weekdays: other.days.get(&()),
eras: convert_eras(&other.eras, calendar),
eras,
}
}

Expand Down

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

Loading

0 comments on commit b874b09

Please sign in to comment.