Skip to content

Commit

Permalink
Handle japanese/japanext eras
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 21, 2023
1 parent 4e896f9 commit 6b307bd
Show file tree
Hide file tree
Showing 110 changed files with 425 additions and 12,691 deletions.
48 changes: 47 additions & 1 deletion provider/datagen/src/transform/cldr/datetime/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,61 @@ fn years_convert(
None
};

let modern_japanese_eras = if *calendar == value!("japanese") {
Some(datagen.cldr()?.modern_japanese_eras()?)
} else {
None
};

let extra_japanese = if *calendar == value!("japanese") || *calendar == value!("japanext") {
let greg: &ca::Resource = datagen
.cldr()?
.dates("gregorian")
.read_and_parse(&langid, "ca-gregorian.json")?;

let greg_data = greg
.main
.value
.dates
.calendars
.get("gregorian")
.expect("CLDR gregorian.json contains the expected calendar");

let eras = greg_data.eras.load(length);
Some((
eras.get("0").expect("gregorian calendar must have 0 era"),
eras.get("1").expect("gregorian calendar must have 1 era"),
))
} else {
None
};

for (cldr, code) in map {
if let Some(name) = eras.get(&*cldr) {
if let Some(modern_japanese_eras) = modern_japanese_eras {
if !modern_japanese_eras.contains(cldr) {
continue;
}
}
out_eras.insert(code, &**name);
} else if let Some(extra_ethiopic) = extra_ethiopic {
if cldr == "2" {
out_eras.insert(code, extra_ethiopic);
} else {
panic!("Unknown ethiopic era number {cldr}");
}
} else if let Some(extra_japanese) = extra_japanese {
if cldr == "-1" {
// AD era
out_eras.insert(code, extra_japanese.0);
} else if cldr == "-2" {
// BC era
out_eras.insert(code, extra_japanese.1);
} else {
panic!("Unknown japanese era number {cldr}");
}
} else {
// panic!("Did not find era data for era {code} (#{cldr}) for {calendar} and {langid}");
panic!("Did not find era data for era {code} (#{cldr}) for {calendar} and {langid}");
}
}

Expand Down

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

Loading

0 comments on commit 6b307bd

Please sign in to comment.