Skip to content

Commit

Permalink
dedupe against generic struct
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jan 21, 2025
1 parent c49896d commit 5531232
Show file tree
Hide file tree
Showing 44 changed files with 1,989 additions and 9,521 deletions.
19 changes: 15 additions & 4 deletions components/datetime/src/format/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,23 @@ impl FormatTimeZone for SpecificNonLocationFormat {
let Some(name) = names
.overrides
.get(&(time_zone_id, zone_variant))
.or_else(|| {
if zone_variant == ZoneVariant::Standard {
generic_names.overrides.get(&time_zone_id)
} else {
None
}
})
.or_else(|| {
let mz = metazone_period.resolve(time_zone_id, local_time)?;
names
.defaults
.get(&(mz, zone_variant))
.or_else(|| generic_names.defaults.get(&mz))
let mz = MetazoneId(mz.0.to_ascii_lowercase());
names.defaults.get(&(mz, zone_variant)).or_else(|| {
if zone_variant == ZoneVariant::Standard {
generic_names.defaults.get(&mz)
} else {
None
}
})
})
else {
return Ok(Err(FormatTimeZoneError::Fallback));
Expand Down
13 changes: 13 additions & 0 deletions components/datetime/src/provider/time_zones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ pub struct ExemplarCitiesV1<'data> {
#[yoke(prove_covariance_manually)]
pub struct MetazoneGenericNamesV1<'data> {
/// The default mapping between metazone id and localized metazone name.
///
/// This mapping may contain a MetazoneId twice:
/// * A lowercase ID means the time zone using the metazone does not use DST.
/// The value is the `-standard` display name.
/// * An uppercase ID means the time zone using the metazne uses DST. The value
/// is the `-generic` display name.
#[cfg_attr(feature = "serde", serde(borrow))]
pub defaults: ZeroMap<'data, MetazoneId, str>,
/// The override mapping between timezone id and localized metazone name.
Expand Down Expand Up @@ -192,9 +198,16 @@ pub struct MetazoneGenericNamesV1<'data> {
#[yoke(prove_covariance_manually)]
pub struct MetazoneSpecificNamesV1<'data> {
/// The default mapping between metazone id and localized metazone name.
///
/// This mapping only contains each MetazoneId once, lowercase. The
/// `ZoneVariant::Standard` values are deduplicated against the generic data
/// struct's lowercase entries.
#[cfg_attr(feature = "serde", serde(borrow))]
pub defaults: ZeroMap<'data, (MetazoneId, ZoneVariant), str>,
/// The override mapping between timezone id and localized metazone name.
///
/// The `ZoneVariant::Standard` values are deduplicated against the generic data
/// struct's lowercase entries.
#[cfg_attr(feature = "serde", serde(borrow))]
pub overrides: ZeroMap<'data, (TimeZoneBcp47Id, ZoneVariant), str>,
}
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/tests/patterns/tests/time_zones.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"zzzz": "日本標準時",

"v": "JST",
"vvvv": "日本時間",
"vvvv": "日本標準時",

"VVV": "東京",
"VVVV": "日本時間",
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/tz_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
|GMT+06:00 |Bhutan Time |Bhutan Standard Time |Bhutan Time |Thimphu |btthi |
|GMT+06:00 |Urumqi Time |Urumqi Standard Time |Urumqi Time |Urumqi |cnurc |
|GMT+06:00 |Indian Ocean Time |Indian Ocean Time |British Indian Ocean Territory Time |Chagos |iodga |
|GMT+06:00 |Kyrgyzstan Time |Kyrgyzstan Standard Time |Kyrgyzstan Time |Bishkek |kgfru |
|GMT+06:00 |Kyrgyzstan Time |Kyrgyzstan Time |Kyrgyzstan Time |Bishkek |kgfru |
|GMT+06:00 |Omsk Standard Time |Omsk Standard Time |Omsk Time |Omsk |ruoms |
|GMT+06:00 |GMT+06:00 |GMT+06:00 |GMT+06:00 |Unknown City |utce06 |
|GMT+05:45 |Nepal Time |Nepal Standard Time |Nepal Time |Kathmandu |npktm |
Expand All @@ -116,7 +116,7 @@
|GMT+05:00 |Pakistan Standard Time |Pakistan Standard Time |Pakistan Time |Karachi |pkkhi |
|GMT+05:00 |Yekaterinburg Standard Time |Yekaterinburg Standard Time |Yekaterinburg Time |Yekaterinburg |ruyek |
|GMT+05:00 |French Southern & Antarctic Time |French Southern & Antarctic Time |French Southern Territories Time |Kerguelen |tfpfr |
|GMT+05:00 |Tajikistan Time |Tajikistan Standard Time |Tajikistan Time |Dushanbe |tjdyu |
|GMT+05:00 |Tajikistan Time |Tajikistan Time |Tajikistan Time |Dushanbe |tjdyu |
|GMT+05:00 |Turkmenistan Standard Time |Turkmenistan Standard Time |Turkmenistan Time |Ashgabat |tmasb |
|GMT+05:00 |GMT+05:00 |GMT+05:00 |GMT+05:00 |Unknown City |utce05 |
|GMT+05:00 |Uzbekistan Standard Time |Uzbekistan Standard Time |Samarkand Time |Samarkand |uzskd |
Expand Down Expand Up @@ -386,7 +386,7 @@
|GMT-06:00 |Central Standard Time |Central Standard Time |Swift Current Time |Swift Current |cayyn |
|GMT-06:00/GMT-05:00|Easter Island Time |Easter Island Standard Time |Easter Time |Easter |clipc |
|GMT-06:00 |Central Standard Time |Central Standard Time |Costa Rica Time |Costa Rica |crsjo |
|GMT-06:00 |Galapagos Time |Galapagos Standard Time |Galapagos Time |Galapagos |ecgps |
|GMT-06:00 |Galapagos Time |Galapagos Time |Galapagos Time |Galapagos |ecgps |
|GMT-06:00 |Central Standard Time |Central Standard Time |Guatemala Time |Guatemala |gtgua |
|GMT-06:00 |Central Standard Time |Central Standard Time |Honduras Time |Tegucigalpa |hntgu |
|GMT-06:00 |Central Standard Time |Central Standard Time |Chihuahua Time |Chihuahua |mxchi |
Expand Down
Loading

0 comments on commit 5531232

Please sign in to comment.