Skip to content

Commit

Permalink
of
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Feb 10, 2025
1 parent 957f599 commit 22799c5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/datetime/examples/timezone_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions components/datetime/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -476,6 +479,7 @@ impl_attrs! {
Zs,
O,
Os,
Of,
V,
Vs,
L,
Expand Down
9 changes: 9 additions & 0 deletions components/datetime/src/fieldsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/src/format/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions components/datetime/src/neo_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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()),
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/pattern/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2405,8 +2405,8 @@ impl<FSet: DateTimeNamesMarker> RawDateTimeNames<FSet> {
)?;
}

// 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);
}
Expand Down
12 changes: 12 additions & 0 deletions components/datetime/tests/patterns/tests/time_zones.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"VVVV": "Los Angeles Time",

"O": "GMT-7",
"OO": "GMT-07:00",
"OOOO": "GMT-07:00",

"x": "-07",
Expand Down Expand Up @@ -46,6 +47,7 @@
"VVVV": "UK Time",

"O": "GMT+1",
"OO": "GMT+01:00",
"OOOO": "GMT+01:00"
}
},
Expand Down Expand Up @@ -80,6 +82,7 @@
"VVVV": "日本時間",

"O": "GMT+9",
"OO": "GMT+09:00",
"OOOO": "GMT+09:00"
}
},
Expand All @@ -97,6 +100,7 @@
"VVVV": "Тролль",

"O": "GMT",
"OO": "GMT+00:00",
"OOOO": "GMT",

"X": "Z"
Expand All @@ -116,6 +120,7 @@
"VVVV": "Непал",

"O": "GMT+5.45",
"OO": "GMT+05.45",
"OOOO": "GMT+05.45"
}
},
Expand All @@ -124,6 +129,7 @@
"datetime": "2021-01-11T12:00:00.000+05:45[Asia/Kathmandu]",
"expectations": {
"O": "GMT +৫:৪৫",
"OO": "GMT +০৫:৪৫",
"OOOO": "GMT +০৫:৪৫",
"Z": "+0545"
}
Expand All @@ -142,6 +148,7 @@
"VVVV": "שעון ישראל",

"O": "GMT\u200e+3\u200e",
"OO": "GMT\u200e+03:00\u200e",
"OOOO": "GMT\u200e+03:00\u200e"
}
},
Expand All @@ -159,6 +166,7 @@
"VVVV": "GMT-07:00",

"O": "GMT-7",
"OO": "GMT-07:00",
"OOOO": "GMT-07:00",

"Z": "-0700",
Expand All @@ -179,6 +187,7 @@
"VVVV": "GMT-07:00",

"O": "GMT-7",
"OO": "GMT-07:00",
"OOOO": "GMT-07:00",

"Z": "-0700",
Expand All @@ -199,6 +208,7 @@
"VVVV": "GMT+?",

"O": "GMT+?",
"OO": "GMT+?",
"OOOO": "GMT+?",

"Z": "+?",
Expand All @@ -219,6 +229,7 @@
"VVVV": "GMT",

"O": "GMT",
"OO": "GMT+00:00",
"OOOO": "GMT",

"Z": "+0000",
Expand All @@ -239,6 +250,7 @@
"VVVV": "GMT",

"O": "GMT",
"OO": "GMT+00:00",
"OOOO": "GMT",

"Z": "+0000",
Expand Down

0 comments on commit 22799c5

Please sign in to comment.