From c4e1dd00610b7aa800230e22a29dc0fafb22a3f4 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Fri, 11 Oct 2024 14:04:15 -0700 Subject: [PATCH 1/2] secondss --- components/datetime/src/time_zone.rs | 17 ++++++++++++++++- components/datetime/tests/datetime.rs | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/components/datetime/src/time_zone.rs b/components/datetime/src/time_zone.rs index b8fa1beb2bf..3e26a42f8ba 100644 --- a/components/datetime/src/time_zone.rs +++ b/components/datetime/src/time_zone.rs @@ -402,7 +402,10 @@ impl FormatOffset for LocalizedOffsetFormat { ) .write_to(sink)?; - if self.length == FieldLength::Wide || self.offset.has_minutes() { + if self.length == FieldLength::Wide + || self.offset.has_minutes() + || self.offset.has_seconds() + { sink.write_char(self.separator)?; self.fdf .format( @@ -414,6 +417,18 @@ impl FormatOffset for LocalizedOffsetFormat { .write_to(sink)?; } + if self.offset.has_seconds() { + sink.write_char(self.separator)?; + self.fdf + .format( + &FixedDecimal::from( + (self.offset.offset_seconds() % 3600).unsigned_abs(), + ) + .padded_start(2), + ) + .write_to(sink)?; + } + Ok(()) } } diff --git a/components/datetime/tests/datetime.rs b/components/datetime/tests/datetime.rs index 801ef332769..e0ced66ec90 100644 --- a/components/datetime/tests/datetime.rs +++ b/components/datetime/tests/datetime.rs @@ -37,7 +37,7 @@ use icu_locale_core::{ locale, LanguageIdentifier, Locale, }; use icu_provider::prelude::*; -use icu_timezone::{CustomTimeZone, CustomZonedDateTime}; +use icu_timezone::{CustomTimeZone, CustomZonedDateTime, UtcOffset}; use patterns::{ dayperiods::{DayPeriodExpectation, DayPeriodTests}, time_zones::{TimeZoneExpectation, TimeZoneFormatterConfig, TimeZoneTests}, @@ -471,6 +471,22 @@ fn test_time_zone_format_configs() { } } +#[test] +fn test_time_zone_format_offset_seconds() { + use icu_datetime::{ + neo_marker::NeoTimeZoneOffsetMarker, neo_skeleton::NeoSkeletonLength, NeverCalendar, + }; + + let time_zone = + CustomTimeZone::new_with_offset(UtcOffset::try_from_offset_seconds(12).unwrap()); + let tzf = TypedNeoFormatter::::try_new( + &locale!("en").into(), + NeoTimeZoneOffsetMarker::with_length(NeoSkeletonLength::Medium), + ) + .unwrap(); + assert_try_writeable_eq!(tzf.format(&time_zone), "GMT+0:00:12",); +} + #[test] fn test_time_zone_format_offset_not_set_debug_assert_panic() { use icu_datetime::{ From 2bab5b960706f69022a0aca8a1b4ab29d5f91195 Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Mon, 14 Oct 2024 08:40:20 -0700 Subject: [PATCH 2/2] Update components/datetime/src/time_zone.rs Co-authored-by: Shane F. Carr --- components/datetime/src/time_zone.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/datetime/src/time_zone.rs b/components/datetime/src/time_zone.rs index 3e26a42f8ba..fce6ec0fea6 100644 --- a/components/datetime/src/time_zone.rs +++ b/components/datetime/src/time_zone.rs @@ -422,7 +422,7 @@ impl FormatOffset for LocalizedOffsetFormat { self.fdf .format( &FixedDecimal::from( - (self.offset.offset_seconds() % 3600).unsigned_abs(), + (self.offset.offset_seconds() % 60).unsigned_abs(), ) .padded_start(2), )