Skip to content

Commit

Permalink
Use duration formatter patterns for localized offset (#5684)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Oct 14, 2024
1 parent 4342699 commit 23dc5b2
Show file tree
Hide file tree
Showing 28 changed files with 117 additions and 197 deletions.
7 changes: 2 additions & 5 deletions components/datetime/src/provider/time_zones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ pub(crate) mod tz {
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct TimeZoneEssentialsV1<'data> {
/// The sign for positive offsets
pub offset_positive_sign: char,
/// The sign for negative offsets
pub offset_negative_sign: char,
/// The separator sign
pub offset_separator: char,
#[cfg_attr(feature = "serde", serde(borrow,))]
pub offset_separator: Cow<'data, str>,
/// The localized offset format.
#[cfg_attr(
feature = "serde",
Expand Down
19 changes: 6 additions & 13 deletions components/datetime/src/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ impl FormatOffset for LocalizedOffsetFormat {
} else {
struct FormattedOffset<'a> {
offset: UtcOffset,
sign: char,
separator: char,
separator: &'a str,
fdf: &'a FixedDecimalFormatter,
length: FieldLength,
}
Expand All @@ -385,11 +384,10 @@ impl FormatOffset for LocalizedOffsetFormat {
&self,
sink: &mut S,
) -> fmt::Result {
sink.write_char(self.sign)?;

self.fdf
.format(
&FixedDecimal::from(self.offset.hours_part().unsigned_abs())
&FixedDecimal::from(self.offset.hours_part())
.with_sign_display(fixed_decimal::SignDisplay::Always)
.padded_start(if self.length == FieldLength::Wide {
2
} else {
Expand All @@ -402,14 +400,14 @@ impl FormatOffset for LocalizedOffsetFormat {
|| self.offset.minutes_part() != 0
|| self.offset.seconds_part() != 0
{
sink.write_char(self.separator)?;
sink.write_str(self.separator)?;
self.fdf
.format(&FixedDecimal::from(self.offset.minutes_part()).padded_start(2))
.write_to(sink)?;
}

if self.offset.seconds_part() != 0 {
sink.write_char(self.separator)?;
sink.write_str(self.separator)?;
self.fdf
.format(&FixedDecimal::from(self.offset.seconds_part()).padded_start(2))
.write_to(sink)?;
Expand All @@ -423,12 +421,7 @@ impl FormatOffset for LocalizedOffsetFormat {
.offset_pattern
.interpolate([FormattedOffset {
offset,
sign: if offset.is_positive() {
essentials.offset_positive_sign
} else {
essentials.offset_negative_sign
},
separator: essentials.offset_separator,
separator: &essentials.offset_separator,
fdf,
length: self.0,
}])
Expand Down
10 changes: 5 additions & 5 deletions components/datetime/tests/patterns/tests/time_zones.json
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@
"configs": [
"SpecificNonLocationShort"
],
"expected": ["GMT+5:45"]
"expected": ["GMT+5.45"]
},
{
"patterns": [
Expand Down Expand Up @@ -769,7 +769,7 @@
"LocalizedOffsetShort"
],
"fallback_formats": ["LocalizedOffset"],
"expected": ["GMT+5:45"]
"expected": ["GMT+5.45"]
},
{
"patterns": [
Expand All @@ -778,7 +778,7 @@
"configs": [
"LocalizedOffsetLong"
],
"expected": ["GMT+05:45"]
"expected": ["GMT+05.45"]
},
{
"patterns": [
Expand Down Expand Up @@ -956,7 +956,7 @@
"LocalizedOffsetShort"
],
"fallback_formats": ["LocalizedOffset"],
"expected": ["GMT+3\u200e"]
"expected": ["GMT\u200e+3\u200e"]
},
{
"patterns": [
Expand All @@ -965,7 +965,7 @@
"configs": [
"LocalizedOffsetLong"
],
"expected": ["GMT+03:00\u200e"]
"expected": ["GMT\u200e+03:00\u200e"]
},
{
"patterns": [
Expand Down

Large diffs are not rendered by default.

81 changes: 40 additions & 41 deletions provider/data/datetime/fingerprints.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35217,56 +35217,55 @@ datetime/patterns/time_skeleton@1, zh/hms, -> ja/hms
datetime/patterns/time_skeleton@1, zh/j, -> yue-Hans/h0
datetime/patterns/time_skeleton@1, zu/hm, -> ak/hm
datetime/patterns/time_skeleton@1, zu/hms, -> az/hms
time_zone/essentials@1, <lookup>, 255B, 48 identifiers
time_zone/essentials@1, <total>, 3001B, 1051B, 35 unique payloads
time_zone/essentials@1, am, 93B, 37B, f2b1bee39ef5488d
time_zone/essentials@1, ar, 89B, 33B, 16a841948e053d18
time_zone/essentials@1, bg, 93B, 37B, 9bdf4a7fac977810
time_zone/essentials@1, blo, 70B, 14B, 51aa1523d3b31677
time_zone/essentials@1, bn, 72B, 16B, b837f61e17bc36a5
time_zone/essentials@1, brx, 106B, 50B, dcd1490ccfcfee71
time_zone/essentials@1, <lookup>, 245B, 47 identifiers
time_zone/essentials@1, <total>, 2914B, 844B, 30 unique payloads
time_zone/essentials@1, am, 102B, 33B, eeec6491fe2a415c
time_zone/essentials@1, ar, 98B, 29B, 505f9aa696f9dd39
time_zone/essentials@1, bg, 102B, 33B, fa1c26468e834b75
time_zone/essentials@1, blo, 79B, 10B, 75653557f36d1e0e
time_zone/essentials@1, bn, 81B, 12B, 28a3350769474069
time_zone/essentials@1, brx, 115B, 46B, b2d001218a3894c8
time_zone/essentials@1, bs, -> bn
time_zone/essentials@1, ceb, -> bn
time_zone/essentials@1, da, 71B, 15B, 259e0ab7129d70d8
time_zone/essentials@1, ee, 72B, 16B, 5cfbf00918af6383
time_zone/essentials@1, eo, 71B, 15B, f0bf056acbd6c584
time_zone/essentials@1, et, 72B, 18B, 9395dc6e107d77b
time_zone/essentials@1, eu, 71B, 17B, e1dae10934ac0ce5
time_zone/essentials@1, fa, 94B, 40B, a382b6493d4aac56
time_zone/essentials@1, ff-Adlm, 89B, 33B, 828621e35f4f128d
time_zone/essentials@1, fi, 71B, 15B, 2075096db15139df
time_zone/essentials@1, fr, 71B, 17B, c8b16ee8f93e034a
time_zone/essentials@1, ga, 71B, 15B, ca2c13d28da09944
time_zone/essentials@1, he, 74B, 18B, 4c6f5efd322c0f6e
time_zone/essentials@1, da, 80B, 11B, 9ba2a130c8f24f8e
time_zone/essentials@1, ee, 81B, 12B, 922b02c838f9c71a
time_zone/essentials@1, eo, 80B, 11B, 48be633fb5c77063
time_zone/essentials@1, et, -> bn
time_zone/essentials@1, fa, 103B, 34B, 89be37090c9631c9
time_zone/essentials@1, ff-Adlm, 98B, 29B, d70808dd19843367
time_zone/essentials@1, fi, 80B, 11B, b4c7714f888e80bd
time_zone/essentials@1, fr, -> eo
time_zone/essentials@1, ga, 80B, 11B, 4c641344cdbf85a2
time_zone/essentials@1, he, 83B, 14B, f79516635a378c8c
time_zone/essentials@1, id, -> da
time_zone/essentials@1, ie, 71B, 15B, fc8c009ab8337756
time_zone/essentials@1, ii, 101B, 45B, 36c5dbd658ed3785
time_zone/essentials@1, km, 114B, 58B, 955e09bed6c79182
time_zone/essentials@1, ks, 84B, 28B, 3db37f98cccffee8
time_zone/essentials@1, ks-Deva, 106B, 50B, 95476d9b4c060c03
time_zone/essentials@1, lij, -> fr
time_zone/essentials@1, lt, 71B, 17B, b78a323908777004
time_zone/essentials@1, mai, 101B, 45B, 6a1fcfd3f511c148
time_zone/essentials@1, ml, 102B, 46B, 4aeca9f23a34af99
time_zone/essentials@1, mni, 106B, 50B, 4be9e50c9c816a77
time_zone/essentials@1, mr, 75B, 19B, 94b2d30552ca276
time_zone/essentials@1, ms-ID, -> da
time_zone/essentials@1, nds, -> fi
time_zone/essentials@1, nqo, 81B, 25B, 502a05771f2354c0
time_zone/essentials@1, ie, 80B, 11B, 90a2160dae6c8287
time_zone/essentials@1, ii, 110B, 41B, f805b0542bbf0c2a
time_zone/essentials@1, km, 123B, 54B, ecbc112a0c3f8ecf
time_zone/essentials@1, ks, 93B, 24B, b1a48338faf1fd66
time_zone/essentials@1, ks-Deva, 115B, 46B, e857f46f058f0390
time_zone/essentials@1, lij, -> eo
time_zone/essentials@1, mai, 110B, 41B, cf5711a5c07f2f61
time_zone/essentials@1, ml, 111B, 42B, fe7ec7ffa2b97fe9
time_zone/essentials@1, mni, 115B, 46B, caf911f81a9049f
time_zone/essentials@1, mr, 84B, 15B, 7aef5ace67d79c44
time_zone/essentials@1, nds, -> eo
time_zone/essentials@1, nqo, 90B, 21B, 5dda8fd5cf84fb4f
time_zone/essentials@1, oc, -> eo
time_zone/essentials@1, sa, 108B, 52B, 478d56cfaf157147
time_zone/essentials@1, sat, 101B, 45B, d4d3e9d2763eb867
time_zone/essentials@1, sa, 117B, 48B, 59443105556570c
time_zone/essentials@1, sat, 110B, 41B, 80157cc7a94f5b9a
time_zone/essentials@1, sd-Deva, -> mai
time_zone/essentials@1, si, 113B, 57B, 9ce66d62a8ee7aea
time_zone/essentials@1, sl, 72B, 16B, 584cb58c891d341a
time_zone/essentials@1, sv, -> lt
time_zone/essentials@1, si, 122B, 53B, 3b5b9349782a751
time_zone/essentials@1, sl, -> bn
time_zone/essentials@1, sr, -> da
time_zone/essentials@1, sr-Latn, -> da
time_zone/essentials@1, su, -> da
time_zone/essentials@1, sw, -> bn
time_zone/essentials@1, und, 71B, 15B, 27534bd263d58646
time_zone/essentials@1, und, 80B, 11B, 3a4ac70aa2573ad3
time_zone/essentials@1, ur, -> bn
time_zone/essentials@1, ur-IN, -> und
time_zone/essentials@1, vec, -> eo
time_zone/essentials@1, xnr, 103B, 47B, f9d1a94cd718dec8
time_zone/essentials@1, yo, 71B, 15B, aea11aa5fa3f8bd9
time_zone/essentials@1, xnr, 112B, 43B, db00fa6e92b4b802
time_zone/essentials@1, yo, 80B, 11B, a7e6dbba7ca68060
time_zone/generic_long@1, <lookup>, 948B, 190 identifiers
time_zone/generic_long@1, <total>, 772943B, 756243B, 185 unique payloads
time_zone/generic_long@1, af, 3196B, 3106B, d1b9372d4aacbbbb
Expand Down
2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/ar-EG.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/ar.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/bn.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/ccp.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/en-001.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/en-ZA.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/en.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/es-AR.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/es.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/fil.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/fr.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/ja.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/ru.json

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

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

4 changes: 1 addition & 3 deletions provider/source/data/debug/time_zone/essentials@1/sr.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/th.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/tr.json

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

2 changes: 0 additions & 2 deletions provider/source/data/debug/time_zone/essentials@1/und.json

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

1 change: 0 additions & 1 deletion provider/source/src/cldr_serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub(crate) mod plurals;
pub(crate) mod time_zones;
#[cfg(feature = "experimental")]
pub(crate) mod transforms;
#[cfg(feature = "experimental")]
pub(crate) mod units;
pub(crate) mod week_data;

Expand Down
1 change: 1 addition & 0 deletions provider/source/src/cldr_serde/units/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

pub(crate) mod data;
#[cfg(feature = "experimental")]
pub(crate) mod info;
Loading

0 comments on commit 23dc5b2

Please sign in to comment.