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

Fixing TZ exemplar city generation #3204

Merged
merged 10 commits into from
Mar 21, 2023
Merged
Changes from 1 commit
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
62 changes: 23 additions & 39 deletions provider/datagen/src/transform/cldr/time_zones/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,47 +119,31 @@ impl Location {

impl From<CldrTimeZonesData<'_>> for ExemplarCitiesV1<'static> {
fn from(other: CldrTimeZonesData<'_>) -> Self {
let time_zone_names_data = other.time_zone_names_resource;
let bcp47_tzid_data = &compute_bcp47_tzids_hashmap(other.bcp47_tzids_resource);
// Sorting this map before iterating. This is because multiple time zones might
// map to the same BCP-47 ID (such as Pacific/Enderbury and Pacific/Kanton to
// kipho). The `collect` lower down will use the latest value (Pacific/Kanton).
let bcp47_tzid_data = &compute_bcp47_tzids_hashmap(other.bcp47_tzids_resource)
.into_iter()
.collect::<std::collections::BTreeMap<_, _>>();
Self(
time_zone_names_data
.zone
.0
bcp47_tzid_data
.iter()
.flat_map(|(key, region)| {
region
.0
.iter()
.flat_map(move |(inner_key, place_or_region)| {
let mut key = key.clone();
key.push('/');
key.push_str(inner_key);
match place_or_region {
LocationOrSubRegion::Location(place) => {
match bcp47_tzid_data.get(&key) {
Some(bcp47) => place
.exemplar_city()
.map(|city| vec![(bcp47, city)])
.unwrap_or_default(),
None => panic!("Cannot find bcp47 for {key:?}."),
}
}
LocationOrSubRegion::SubRegion(region) => region
.iter()
.filter_map(|(inner_key, place)| {
let mut key = key.clone();
key.push('/');
key.push_str(inner_key);
match bcp47_tzid_data.get(&key) {
Some(bcp47) => {
place.exemplar_city().map(|city| (bcp47, city))
}
None => panic!("Cannot find bcp47 for {key:?}."),
}
})
.collect::<Vec<_>>(),
}
})
.filter_map(|(tzid, bcp47)| {
let mut tzid = tzid.split('/');
Some((
bcp47,
match other.time_zone_names_resource
.zone
.0
.get(tzid.next()?)?
.0
.get(tzid.next()?)?
{
LocationOrSubRegion::Location(place) => place,
LocationOrSubRegion::SubRegion(region) => region.get(tzid.next()?)?,
}
.exemplar_city()?,
))
})
.collect(),
)
Expand Down