From 22799c5e4d5bc7fddf80b0a9a31224c76ecc33ed Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Mon, 10 Feb 2025 12:42:13 +0100 Subject: [PATCH] of --- components/datetime/examples/timezone_picker.rs | 2 +- components/datetime/src/dynamic.rs | 4 ++++ components/datetime/src/fieldsets.rs | 9 +++++++++ components/datetime/src/format/time_zone.rs | 6 +++--- components/datetime/src/neo_serde.rs | 2 ++ components/datetime/src/pattern/names.rs | 4 ++-- .../datetime/tests/patterns/tests/time_zones.json | 12 ++++++++++++ 7 files changed, 33 insertions(+), 6 deletions(-) diff --git a/components/datetime/examples/timezone_picker.rs b/components/datetime/examples/timezone_picker.rs index 468dfbb635a..5ae6bac77f2 100644 --- a/components/datetime/examples/timezone_picker.rs +++ b/components/datetime/examples/timezone_picker.rs @@ -15,7 +15,7 @@ fn main() { let prefs = locale!("en").into(); - let offset_formatter = DateTimeFormatter::try_new(prefs, fieldsets::O::new()).unwrap(); + let offset_formatter = DateTimeFormatter::try_new(prefs, fieldsets::Of::new()).unwrap(); let non_location_formatter = DateTimeFormatter::try_new(prefs, fieldsets::V::new()).unwrap(); let city_formatter = DateTimeFormatter::try_new(prefs, fieldsets::X::new()).unwrap(); diff --git a/components/datetime/src/dynamic.rs b/components/datetime/src/dynamic.rs index 0732f889335..1ca2f4f81e7 100644 --- a/components/datetime/src/dynamic.rs +++ b/components/datetime/src/dynamic.rs @@ -156,6 +156,9 @@ pub enum ZoneFieldSet { /// The short offset format, as in /// “GMT−8”. Os(fieldsets::Os), + /// The fixed-length offset format, as in + /// “GMT−00:00”. + Of(fieldsets::Of), /// The long generic non-location format, as in /// “Pacific Time”. V(fieldsets::V), @@ -476,6 +479,7 @@ impl_attrs! { Zs, O, Os, + Of, V, Vs, L, diff --git a/components/datetime/src/fieldsets.rs b/components/datetime/src/fieldsets.rs index f0427c674d7..6701fdb1a87 100644 --- a/components/datetime/src/fieldsets.rs +++ b/components/datetime/src/fieldsets.rs @@ -1392,6 +1392,15 @@ impl_zone_marker!( zone_essentials = yes, ); +impl_zone_marker!( + Of, + description = "UTC offset, fixed-length", + length_override = Long, + sample = "GMT-05:00", + field = (fields::TimeZone::LocalizedOffset, fields::FieldLength::Two), + zone_essentials = yes, +); + // TODO: Add short/long UTC offset? impl_zone_marker!( diff --git a/components/datetime/src/format/time_zone.rs b/components/datetime/src/format/time_zone.rs index f6b0f0631a9..e9d419b66c9 100644 --- a/components/datetime/src/format/time_zone.rs +++ b/components/datetime/src/format/time_zone.rs @@ -227,7 +227,7 @@ impl FormatTimeZone for LocalizedOffsetFormat { sink.write_str(&essentials.offset_unknown)?; return Ok(Ok(())); }; - Ok(if offset.is_zero() { + Ok(if offset.is_zero() && self.0 != FieldLength::Two { sink.write_str(&essentials.offset_zero)?; Ok(()) } else { @@ -246,7 +246,7 @@ impl FormatTimeZone for LocalizedOffsetFormat { let fd = { let mut fd = SignedFixedDecimal::from(self.offset.hours_part()) .with_sign_display(fixed_decimal::SignDisplay::Always); - fd.pad_start(if self.length == FieldLength::Four { + fd.pad_start(if self.length != FieldLength::One { 2 } else { 0 @@ -255,7 +255,7 @@ impl FormatTimeZone for LocalizedOffsetFormat { }; self.fdf.format(&fd).write_to(sink)?; - if self.length == FieldLength::Four + if self.length != FieldLength::One || self.offset.minutes_part() != 0 || self.offset.seconds_part() != 0 { diff --git a/components/datetime/src/neo_serde.rs b/components/datetime/src/neo_serde.rs index 33914c16a83..f4833055fdb 100644 --- a/components/datetime/src/neo_serde.rs +++ b/components/datetime/src/neo_serde.rs @@ -586,6 +586,7 @@ impl FieldSetSerde { (ZoneFieldSet::Zs(v), true) => (Self::ZONE_SPECIFIC, v.to_raw_options()), (ZoneFieldSet::O(v), true) => (Self::ZONE_OFFSET, v.to_raw_options()), (ZoneFieldSet::Os(v), true) => (Self::ZONE_OFFSET, v.to_raw_options()), + (ZoneFieldSet::Of(v), true) => (Self::ZONE_OFFSET, v.to_raw_options()), (ZoneFieldSet::V(v), true) => (Self::ZONE_GENERIC, v.to_raw_options()), (ZoneFieldSet::Vs(v), true) => (Self::ZONE_GENERIC, v.to_raw_options()), (ZoneFieldSet::L(v), true) => (Self::ZONE_LOCATION, v.to_raw_options()), @@ -595,6 +596,7 @@ impl FieldSetSerde { (ZoneFieldSet::Zs(v), false) => (Self::ZONE_SPECIFIC, v.to_raw_options()), (ZoneFieldSet::O(v), false) => (Self::ZONE_OFFSET_LONG, v.to_raw_options()), (ZoneFieldSet::Os(v), false) => (Self::ZONE_OFFSET, v.to_raw_options()), + (ZoneFieldSet::Of(v), false) => (Self::ZONE_OFFSET, v.to_raw_options()), (ZoneFieldSet::V(v), false) => (Self::ZONE_GENERIC_LONG, v.to_raw_options()), (ZoneFieldSet::Vs(v), false) => (Self::ZONE_GENERIC, v.to_raw_options()), (ZoneFieldSet::L(v), false) => (Self::ZONE_LOCATION, v.to_raw_options()), diff --git a/components/datetime/src/pattern/names.rs b/components/datetime/src/pattern/names.rs index e4543f19987..ba7e6a9ccd9 100644 --- a/components/datetime/src/pattern/names.rs +++ b/components/datetime/src/pattern/names.rs @@ -2405,8 +2405,8 @@ impl RawDateTimeNames { )?; } - // O, OOOO - (FS::TimeZone(TimeZone::LocalizedOffset), One | Four) => { + // O, OO, OOOO + (FS::TimeZone(TimeZone::LocalizedOffset), One | Two | Four) => { self.load_time_zone_essentials(zone_essentials_provider, prefs)?; numeric_field = Some(field); } diff --git a/components/datetime/tests/patterns/tests/time_zones.json b/components/datetime/tests/patterns/tests/time_zones.json index 540349038ed..869c3582fbc 100644 --- a/components/datetime/tests/patterns/tests/time_zones.json +++ b/components/datetime/tests/patterns/tests/time_zones.json @@ -13,6 +13,7 @@ "VVVV": "Los Angeles Time", "O": "GMT-7", + "OO": "GMT-07:00", "OOOO": "GMT-07:00", "x": "-07", @@ -46,6 +47,7 @@ "VVVV": "UK Time", "O": "GMT+1", + "OO": "GMT+01:00", "OOOO": "GMT+01:00" } }, @@ -80,6 +82,7 @@ "VVVV": "日本時間", "O": "GMT+9", + "OO": "GMT+09:00", "OOOO": "GMT+09:00" } }, @@ -97,6 +100,7 @@ "VVVV": "Тролль", "O": "GMT", + "OO": "GMT+00:00", "OOOO": "GMT", "X": "Z" @@ -116,6 +120,7 @@ "VVVV": "Непал", "O": "GMT+5.45", + "OO": "GMT+05.45", "OOOO": "GMT+05.45" } }, @@ -124,6 +129,7 @@ "datetime": "2021-01-11T12:00:00.000+05:45[Asia/Kathmandu]", "expectations": { "O": "GMT +৫:৪৫", + "OO": "GMT +০৫:৪৫", "OOOO": "GMT +০৫:৪৫", "Z": "+0545" } @@ -142,6 +148,7 @@ "VVVV": "שעון ישראל", "O": "GMT\u200e+3\u200e", + "OO": "GMT\u200e+03:00\u200e", "OOOO": "GMT\u200e+03:00\u200e" } }, @@ -159,6 +166,7 @@ "VVVV": "GMT-07:00", "O": "GMT-7", + "OO": "GMT-07:00", "OOOO": "GMT-07:00", "Z": "-0700", @@ -179,6 +187,7 @@ "VVVV": "GMT-07:00", "O": "GMT-7", + "OO": "GMT-07:00", "OOOO": "GMT-07:00", "Z": "-0700", @@ -199,6 +208,7 @@ "VVVV": "GMT+?", "O": "GMT+?", + "OO": "GMT+?", "OOOO": "GMT+?", "Z": "+?", @@ -219,6 +229,7 @@ "VVVV": "GMT", "O": "GMT", + "OO": "GMT+00:00", "OOOO": "GMT", "Z": "+0000", @@ -239,6 +250,7 @@ "VVVV": "GMT", "O": "GMT", + "OO": "GMT+00:00", "OOOO": "GMT", "Z": "+0000",