Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update data model for non-gregorian calendars #1300

Merged
merged 22 commits into from
Nov 17, 2021

Conversation

Manishearth
Copy link
Member

Progress on #1115

Previously, date data was stored as gregory_symbols@1/en.json (etc). We'd like to use the same data format for all of the calendars, so now data is stored under symbols@1/gregorian/en.json, with "gregorian" being the variant. Datetime data now requires a variant referring to the calendar.

Datetime formatting code has not been modified to support other calendars; it hardcodes "gregorian" instead. This will be updated in a future PR; this PR is just setting the stage for these changes.

The full changes here are:

  • The CLDR provider has been refactored to share code between the three different data keys. It also uses LiteMap instead of manually binary searching a vector
  • CldrPaths supports yielding multiple calendars, though only gregorian is hooked up right now.
  • The CLDR provider now produces date formatting data for all calendars hooked into CldrPaths, sorted under variants
  • The GREGORY_FOO_BAR keys have been renamed to remove "gregory" from the name
  • The gregory data struct module has been renamed to calendar

zbraniecki
zbraniecki previously approved these changes Nov 16, 2021
provider/cldr/src/transform/dates/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for "gregorian" -> "gregory" when used as a string identifier

components/datetime/src/datetime.rs Outdated Show resolved Hide resolved
provider/cldr/src/cldr_paths.rs Show resolved Hide resolved
provider/cldr/src/transform/dates/common.rs Outdated Show resolved Hide resolved
Ok(idx) => &self.data[idx].1.dates,
Err(_) => return Err(DataError::MissingResourceOptions(req.clone())),
};
let dates = self.0.dates_for(req)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: I like the way you refactored this code

@@ -37,7 +37,7 @@ impl TryFrom<&dyn CldrPaths> for TimeZonesProvider {
fn try_from(cldr_paths: &dyn CldrPaths) -> Result<Self, Self::Error> {
let mut data = vec![];

let path = cldr_paths.cldr_dates()?.join("main");
let path = cldr_paths.cldr_dates("gregorian")?.join("main");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is there time zone data in other calendars, or is it always stored in the gregorian calendar data bundle?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I linked to the wrong repo, but the point still stands when looking at the cldr-json repo)

let list: Vec<ResourceOptions> = self
.data
.iter()
.flat_map(|(cal, map)| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This is the "magic" that informs the data exporter to loop over both variants and locales when putting together the data tree.

gregtatum
gregtatum previously approved these changes Nov 16, 2021
Copy link
Member

@gregtatum gregtatum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks reasonable to me.

provider/core/src/error.rs Outdated Show resolved Hide resolved
@Manishearth Manishearth merged commit 608fbd4 into unicode-org:main Nov 17, 2021
@Manishearth Manishearth deleted the gregorian-variant branch November 17, 2021 02:29
@Manishearth Manishearth linked an issue Nov 17, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add non-Gregorian calendar formatting data
4 participants