diff --git a/components/datetime/README.md b/components/datetime/README.md index c8b850c1e8b..4b14330bc8e 100644 --- a/components/datetime/README.md +++ b/components/datetime/README.md @@ -29,7 +29,7 @@ The formatters accept input types from the [`calendar`](icu_calendar) and 3. [`Time`](icu_calendar::Time) 4. [`UtcOffset`](icu_timezone::UtcOffset) 5. [`TimeZoneInfo`](icu_timezone::TimeZoneInfo) -6. [`CustomZonedDateTime`](icu_timezone::CustomZonedDateTime) +6. [`ZonedDateTime`](icu_timezone::ZonedDateTime) Not all inputs are valid for all field sets. diff --git a/components/datetime/benches/datetime.rs b/components/datetime/benches/datetime.rs index 1442b955991..a8348814d30 100644 --- a/components/datetime/benches/datetime.rs +++ b/components/datetime/benches/datetime.rs @@ -9,7 +9,7 @@ use icu_datetime::{fieldsets::enums::CompositeFieldSet, FixedCalendarDateTimeFor use icu_calendar::{Date, DateTime, Gregorian, Time}; use icu_locale_core::Locale; -use icu_timezone::{CustomZonedDateTime, TimeZoneInfo, ZoneVariant}; +use icu_timezone::{TimeZoneInfo, ZoneVariant, ZonedDateTime}; use writeable::Writeable; #[path = "../tests/mock.rs"] @@ -23,7 +23,7 @@ fn datetime_benches(c: &mut Criterion) { group.bench_function(format!("semantic/{name}"), |b| { b.iter(|| { for fx in &fxs.0 { - let datetimes: Vec> = fx + let datetimes: Vec> = fx .values .iter() .map(move |value| { @@ -31,7 +31,7 @@ fn datetime_benches(c: &mut Criterion) { mock::parse_zoned_gregorian_from_str(value) } else { let DateTime { date, time } = mock::parse_gregorian_from_str(value); - CustomZonedDateTime { + ZonedDateTime { date, time, // zone is unused but we need to make the types match diff --git a/components/datetime/src/lib.rs b/components/datetime/src/lib.rs index 6cdaa70af36..5e3f73222ee 100644 --- a/components/datetime/src/lib.rs +++ b/components/datetime/src/lib.rs @@ -29,7 +29,7 @@ //! 3. [`Time`](icu_calendar::Time) //! 4. [`UtcOffset`](icu_timezone::UtcOffset) //! 5. [`TimeZoneInfo`](icu_timezone::TimeZoneInfo) -//! 6. [`CustomZonedDateTime`](icu_timezone::CustomZonedDateTime) +//! 6. [`ZonedDateTime`](icu_timezone::ZonedDateTime) //! //! Not all inputs are valid for all field sets. //! diff --git a/components/datetime/src/scaffold/calendar.rs b/components/datetime/src/scaffold/calendar.rs index 6996e960862..8f589b299c9 100644 --- a/components/datetime/src/scaffold/calendar.rs +++ b/components/datetime/src/scaffold/calendar.rs @@ -20,7 +20,7 @@ use icu_calendar::{ }; use icu_provider::marker::NeverMarker; use icu_provider::prelude::*; -use icu_timezone::{CustomZonedDateTime, TimeZoneInfo, TimeZoneModel, UtcOffset}; +use icu_timezone::{TimeZoneInfo, TimeZoneModel, UtcOffset, ZonedDateTime}; /// A calendar that can be found in CLDR. /// @@ -416,13 +416,13 @@ impl> ConvertCalendar for DateTi } impl, Z: Copy> ConvertCalendar - for CustomZonedDateTime + for ZonedDateTime { - type Converted<'a> = CustomZonedDateTime, Z>; + type Converted<'a> = ZonedDateTime, Z>; #[inline] fn to_calendar<'a>(&self, calendar: &'a AnyCalendar) -> Self::Converted<'a> { let date = self.date.to_any().to_calendar(Ref(calendar)); - CustomZonedDateTime { + ZonedDateTime { date, time: self.time, zone: self.zone, @@ -490,7 +490,7 @@ impl> InSameCalendar for DateTime { } } -impl, Z> InSameCalendar for CustomZonedDateTime { +impl, Z> InSameCalendar for ZonedDateTime { #[inline] fn check_any_calendar_kind(&self, _: AnyCalendarKind) -> Result<(), MismatchedCalendarError> { Ok(()) @@ -520,10 +520,7 @@ impl InFixedCalendar for Time {} impl> InFixedCalendar for DateTime {} -impl, Z> InFixedCalendar - for CustomZonedDateTime -{ -} +impl, Z> InFixedCalendar for ZonedDateTime {} impl InFixedCalendar for UtcOffset {} diff --git a/components/datetime/src/scaffold/fieldset_traits.rs b/components/datetime/src/scaffold/fieldset_traits.rs index bb0f46fefac..e59f20be48c 100644 --- a/components/datetime/src/scaffold/fieldset_traits.rs +++ b/components/datetime/src/scaffold/fieldset_traits.rs @@ -151,7 +151,7 @@ pub trait DateTimeMarkers: UnstableSealed + DateTimeNamesMarker { /// - [`Date`](icu_calendar::Date) /// - [`Time`](icu_calendar::Time) /// - [`DateTime`](icu_calendar::DateTime) -/// - [`CustomZonedDateTime`](icu_timezone::CustomZonedDateTime) +/// - [`ZonedDateTime`](icu_timezone::ZonedDateTime) /// - [`UtcOffset`](icu_timezone::UtcOffset) /// - [`TimeZoneInfo`](icu_timezone::TimeZoneInfo) /// diff --git a/components/datetime/src/scaffold/get_field.rs b/components/datetime/src/scaffold/get_field.rs index f1d382f3e8d..6c80bde36d6 100644 --- a/components/datetime/src/scaffold/get_field.rs +++ b/components/datetime/src/scaffold/get_field.rs @@ -10,7 +10,7 @@ use icu_calendar::{ AsCalendar, Calendar, Date, DateTime, Iso, Time, }; use icu_timezone::{ - CustomZonedDateTime, TimeZoneBcp47Id, TimeZoneInfo, TimeZoneModel, UtcOffset, ZoneVariant, + TimeZoneBcp47Id, TimeZoneInfo, TimeZoneModel, UtcOffset, ZoneVariant, ZonedDateTime, }; use super::UnstableSealed; @@ -165,79 +165,65 @@ impl> GetField for DateTime } } -impl, Z> UnstableSealed for CustomZonedDateTime {} +impl, Z> UnstableSealed for ZonedDateTime {} -impl, Z> GetField for CustomZonedDateTime { +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> YearInfo { self.date.year() } } -impl, Z> GetField - for CustomZonedDateTime -{ +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> MonthInfo { self.date.month() } } -impl, Z> GetField - for CustomZonedDateTime -{ +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> DayOfMonth { self.date.day_of_month() } } -impl, Z> GetField - for CustomZonedDateTime -{ +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> IsoWeekday { self.date.day_of_week() } } -impl, Z> GetField - for CustomZonedDateTime -{ +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> DayOfYearInfo { self.date.day_of_year_info() } } -impl, Z> GetField for CustomZonedDateTime { +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> IsoHour { self.time.hour } } -impl, Z> GetField - for CustomZonedDateTime -{ +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> IsoMinute { self.time.minute } } -impl, Z> GetField - for CustomZonedDateTime -{ +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> IsoSecond { self.time.second } } -impl, Z> GetField - for CustomZonedDateTime -{ +impl, Z> GetField for ZonedDateTime { #[inline] fn get_field(&self) -> NanoSecond { self.time.nanosecond @@ -245,7 +231,7 @@ impl, Z> GetField } impl, Z> GetField> - for CustomZonedDateTime + for ZonedDateTime where Z: GetField>, { @@ -255,8 +241,7 @@ where } } -impl, Z> GetField - for CustomZonedDateTime +impl, Z> GetField for ZonedDateTime where Z: GetField, { @@ -266,8 +251,7 @@ where } } -impl, Z> GetField - for CustomZonedDateTime +impl, Z> GetField for ZonedDateTime where Z: GetField, { @@ -278,7 +262,7 @@ where } impl, Z> GetField<(Date, Time)> - for CustomZonedDateTime + for ZonedDateTime where Z: GetField<(Date, Time)>, { @@ -354,7 +338,7 @@ impl> GetField<()> for DateTime { fn get_field(&self) {} } -impl, Z> GetField<()> for CustomZonedDateTime { +impl, Z> GetField<()> for ZonedDateTime { #[inline] fn get_field(&self) {} } diff --git a/components/datetime/tests/datetime.rs b/components/datetime/tests/datetime.rs index f8951052bba..dcadadb2ef7 100644 --- a/components/datetime/tests/datetime.rs +++ b/components/datetime/tests/datetime.rs @@ -28,7 +28,7 @@ use icu_locale_core::{ Locale, }; use icu_provider::prelude::*; -use icu_timezone::{CustomZonedDateTime, TimeZoneIdMapper, TimeZoneInfo, UtcOffset}; +use icu_timezone::{TimeZoneIdMapper, TimeZoneInfo, UtcOffset, ZonedDateTime}; use patterns::{ dayperiods::{DayPeriodExpectation, DayPeriodTests}, time_zones::TimeZoneTests, @@ -275,23 +275,23 @@ fn assert_fixture_element( input_value.date.calendar().debug_name() ); - let input_value = CustomZonedDateTime { + let input_value = ZonedDateTime { date: input_value.date.clone(), time: input_value.time, zone: TimeZoneInfo::utc(), }; - let input_iso = CustomZonedDateTime { + let input_iso = ZonedDateTime { date: input_iso.date, time: input_iso.time, zone: TimeZoneInfo::utc(), }; - let any_input = CustomZonedDateTime { + let any_input = ZonedDateTime { date: input_value.date.to_any(), time: input_value.time, zone: TimeZoneInfo::utc(), }; - let iso_any_input = CustomZonedDateTime { + let iso_any_input = ZonedDateTime { date: input_iso.date.to_any(), time: input_iso.time, zone: TimeZoneInfo::utc(), diff --git a/components/datetime/tests/mock.rs b/components/datetime/tests/mock.rs index 00e5bcb1a05..a0a47383d02 100644 --- a/components/datetime/tests/mock.rs +++ b/components/datetime/tests/mock.rs @@ -5,7 +5,7 @@ //! Some useful parsing functions for tests. use icu_calendar::{DateTime, Gregorian}; -use icu_timezone::{models, CustomZonedDateTime, IxdtfParser, TimeZoneInfo, ZoneVariant}; +use icu_timezone::{models, IxdtfParser, TimeZoneInfo, ZoneVariant, ZonedDateTime}; /// Temporary function for parsing a `DateTime` /// @@ -56,13 +56,13 @@ pub fn parse_gregorian_from_str(input: &str) -> DateTime { /// ``` pub fn parse_zoned_gregorian_from_str( input: &str, -) -> CustomZonedDateTime> { +) -> ZonedDateTime> { match IxdtfParser::new().try_from_str(input, Gregorian) { Ok(zdt) => zdt, Err(icu_timezone::ParseError::MismatchedTimeZoneFields) => { match IxdtfParser::new().try_loose_from_str(input, Gregorian) { Ok(zdt) => { - CustomZonedDateTime { + ZonedDateTime { date: zdt.date, time: zdt.time, // For fixture tests, set the zone variant to standard here diff --git a/components/icu/examples/tui.rs b/components/icu/examples/tui.rs index f26f6034764..c4f347a43fa 100644 --- a/components/icu/examples/tui.rs +++ b/components/icu/examples/tui.rs @@ -12,7 +12,7 @@ use icu::timezone::TimeZoneInfo; use icu_collections::codepointinvlist::CodePointInversionListBuilder; use icu_datetime::fieldsets::YMDT; use icu_datetime::FixedCalendarDateTimeFormatter; -use icu_timezone::CustomZonedDateTime; +use icu_timezone::ZonedDateTime; use std::env; fn main() { @@ -47,7 +47,7 @@ fn main() { let time = Time::try_new(18, 56, 0, 0).unwrap(); let zone = TimeZoneInfo::utc(); - let formatted_dt = dtf.format(&CustomZonedDateTime { date, time, zone }); + let formatted_dt = dtf.format(&ZonedDateTime { date, time, zone }); println!("Today is: {}", formatted_dt); } diff --git a/components/timezone/src/ixdtf.rs b/components/timezone/src/ixdtf.rs index 1fc73c9b600..f23000a0f38 100644 --- a/components/timezone/src/ixdtf.rs +++ b/components/timezone/src/ixdtf.rs @@ -5,9 +5,8 @@ use crate::{ provider::{names::IanaToBcp47MapV3Marker, ZoneOffsetPeriodV1Marker}, time_zone::models, - CustomZonedDateTime, InvalidOffsetError, TimeZoneBcp47Id, TimeZoneIdMapper, - TimeZoneIdMapperBorrowed, TimeZoneInfo, UtcOffset, ZoneOffsetCalculator, ZoneOffsets, - ZoneVariant, + InvalidOffsetError, TimeZoneBcp47Id, TimeZoneIdMapper, TimeZoneIdMapperBorrowed, TimeZoneInfo, + UtcOffset, ZoneOffsetCalculator, ZoneOffsets, ZoneVariant, ZonedDateTime, }; use icu_calendar::{ AnyCalendarKind, AsCalendar, Calendar, Date, DateError, DateTime, Iso, RangeError, Time, @@ -402,53 +401,53 @@ impl<'a> Intermediate<'a> { } impl IxdtfParser { - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. /// /// This function is "strict": the string should have only an offset and no named time zone. pub fn try_offset_only_iso_from_str( &self, ixdtf_str: &str, - ) -> Result, ParseError> { + ) -> Result, ParseError> { self.try_offset_only_iso_from_utf8(ixdtf_str.as_bytes()) } - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. /// /// This function is "strict": the string should have only an offset and no named time zone. pub fn try_offset_only_iso_from_utf8( &self, ixdtf_str: &[u8], - ) -> Result, ParseError> { + ) -> Result, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.offset_only()?; self.try_iso_from_ixdtf_record(&ixdtf_record, time_zone) } - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. /// /// This function is "strict": the string should have only a named time zone and no offset. pub fn try_location_only_iso_from_str( &self, ixdtf_str: &str, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { self.try_location_only_iso_from_utf8(ixdtf_str.as_bytes()) } - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. /// /// This function is "strict": the string should have only a named time zone and no offset. pub fn try_location_only_iso_from_utf8( &self, ixdtf_str: &[u8], - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.location_only(self.mapper.as_borrowed())?; self.try_iso_from_ixdtf_record(&ixdtf_record, time_zone) } - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. /// /// This function is "loose": the string can have an offset, and named time zone, both, or /// neither. If the named time zone is missing, it is returned as Etc/Unknown. @@ -458,11 +457,11 @@ impl IxdtfParser { pub fn try_loose_iso_from_str( &self, ixdtf_str: &str, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { self.try_loose_iso_from_utf8(ixdtf_str.as_bytes()) } - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. /// /// This function is "loose": the string can have an offset, and named time zone, both, or /// neither. If the named time zone is missing, it is returned as Etc/Unknown. @@ -472,14 +471,14 @@ impl IxdtfParser { pub fn try_loose_iso_from_utf8( &self, ixdtf_str: &[u8], - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.loose(self.mapper.as_borrowed())?; self.try_iso_from_ixdtf_record(&ixdtf_record, time_zone) } - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from an IXDTF syntax string. /// /// The string should have both an offset and a named time zone. /// @@ -521,11 +520,11 @@ impl IxdtfParser { pub fn try_iso_from_str( &self, ixdtf_str: &str, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { self.try_iso_from_utf8(ixdtf_str.as_bytes()) } - /// Create a [`CustomZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in ISO-8601 calendar from IXDTF syntax UTF-8 bytes. /// /// The string should have both an offset and a named time zone. /// @@ -533,64 +532,64 @@ impl IxdtfParser { pub fn try_iso_from_utf8( &self, ixdtf_str: &[u8], - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.full(self.mapper.as_borrowed(), &self.offsets)?; self.try_iso_from_ixdtf_record(&ixdtf_record, time_zone) } - /// Create a [`CustomZonedDateTime`] in any calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in any calendar from an IXDTF syntax string. /// /// This function is "strict": the string should have only an offset and no named time zone. pub fn try_offset_only_from_str( &self, ixdtf_str: &str, calendar: A, - ) -> Result, ParseError> { + ) -> Result, ParseError> { self.try_offset_only_from_utf8(ixdtf_str.as_bytes(), calendar) } - /// Create a [`CustomZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// /// This function is "strict": the string should have only an offset and no named time zone. pub fn try_offset_only_from_utf8( &self, ixdtf_str: &[u8], calendar: A, - ) -> Result, ParseError> { + ) -> Result, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.offset_only()?; self.try_from_ixdtf_record(&ixdtf_record, time_zone, calendar) } - /// Create a [`CustomZonedDateTime`] in any calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in any calendar from an IXDTF syntax string. /// /// This function is "strict": the string should have only a named time zone and no offset. pub fn try_location_only_from_str( &self, ixdtf_str: &str, calendar: A, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { self.try_location_only_from_utf8(ixdtf_str.as_bytes(), calendar) } - /// Create a [`CustomZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// /// This function is "strict": the string should have only a named time zone and no offset. pub fn try_location_only_from_utf8( &self, ixdtf_str: &[u8], calendar: A, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.location_only(self.mapper.as_borrowed())?; self.try_from_ixdtf_record(&ixdtf_record, time_zone, calendar) } - /// Create a [`CustomZonedDateTime`] in any calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in any calendar from an IXDTF syntax string. /// /// This function is "loose": the string can have an offset, and named time zone, both, or /// neither. If the named time zone is missing, it is returned as Etc/Unknown. @@ -601,11 +600,11 @@ impl IxdtfParser { &self, ixdtf_str: &str, calendar: A, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { self.try_loose_from_utf8(ixdtf_str.as_bytes(), calendar) } - /// Create a [`CustomZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// /// This function is "loose": the string can have an offset, and named time zone, both, or /// neither. If the named time zone is missing, it is returned as Etc/Unknown. @@ -616,14 +615,14 @@ impl IxdtfParser { &self, ixdtf_str: &[u8], calendar: A, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.loose(self.mapper.as_borrowed())?; self.try_from_ixdtf_record(&ixdtf_record, time_zone, calendar) } - /// Create a [`CustomZonedDateTime`] in any calendar from an IXDTF syntax string. + /// Create a [`ZonedDateTime`] in any calendar from an IXDTF syntax string. /// /// The string should have both an offset and a named time zone. /// @@ -790,11 +789,11 @@ impl IxdtfParser { &self, ixdtf_str: &str, calendar: A, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { self.try_from_utf8(ixdtf_str.as_bytes(), calendar) } - /// Create a [`CustomZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. + /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// /// The string should have both an offset and a named time zone. /// @@ -803,7 +802,7 @@ impl IxdtfParser { &self, ixdtf_str: &[u8], calendar: A, - ) -> Result>, ParseError> { + ) -> Result>, ParseError> { let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; let intermediate = Intermediate::try_from_ixdtf_record(&ixdtf_record)?; let time_zone = intermediate.full(self.mapper.as_borrowed(), &self.offsets)?; @@ -815,7 +814,7 @@ impl IxdtfParser { ixdtf_record: &IxdtfParseRecord, zone: Z, calendar: A, - ) -> Result, ParseError> { + ) -> Result, ParseError> { let iso_zdt = self.try_iso_from_ixdtf_record(ixdtf_record, zone)?; if let Some(ixdtf_calendar) = ixdtf_record.calendar { let parsed_calendar = @@ -832,7 +831,7 @@ impl IxdtfParser { )); } } - Ok(CustomZonedDateTime { + Ok(ZonedDateTime { date: iso_zdt.date.to_calendar(calendar), time: iso_zdt.time, zone: iso_zdt.zone, @@ -843,7 +842,7 @@ impl IxdtfParser { &self, ixdtf_record: &IxdtfParseRecord, zone: Z, - ) -> Result, ParseError> { + ) -> Result, ParseError> { let date_record = ixdtf_record.date.ok_or(ParseError::MissingFields)?; let date = Date::try_new_iso(date_record.year, date_record.month, date_record.day)?; let time_record = ixdtf_record.time.ok_or(ParseError::MissingFields)?; @@ -854,7 +853,7 @@ impl IxdtfParser { time_record.nanosecond, )?; - Ok(CustomZonedDateTime { date, time, zone }) + Ok(ZonedDateTime { date, time, zone }) } } diff --git a/components/timezone/src/lib.rs b/components/timezone/src/lib.rs index f4003589541..bd28758696e 100644 --- a/components/timezone/src/lib.rs +++ b/components/timezone/src/lib.rs @@ -109,7 +109,6 @@ mod time_zone; mod types; mod windows_tz; mod zone_offset; -mod zoned_datetime; #[cfg(feature = "ixdtf")] mod ixdtf; @@ -125,10 +124,9 @@ pub use provider::TimeZoneBcp47Id; pub use time_zone::models; pub use time_zone::TimeZoneInfo; pub use time_zone::TimeZoneModel; -pub use types::{UtcOffset, ZoneVariant}; +pub use types::{UtcOffset, ZoneVariant, ZonedDateTime}; pub use windows_tz::{WindowsTimeZoneMapper, WindowsTimeZoneMapperBorrowed}; pub use zone_offset::{ZoneOffsetCalculator, ZoneOffsets}; -pub use zoned_datetime::CustomZonedDateTime; #[cfg(all(feature = "ixdtf", feature = "compiled_data"))] pub use crate::ixdtf::ParseError; diff --git a/components/timezone/src/types.rs b/components/timezone/src/types.rs index 3838840cbdc..6874088e514 100644 --- a/components/timezone/src/types.rs +++ b/components/timezone/src/types.rs @@ -4,6 +4,19 @@ use crate::error::InvalidOffsetError; use core::str::FromStr; +use icu_calendar::{AsCalendar, Date, Time}; + +/// A date and time local to a specified custom time zone. +#[derive(Debug)] +#[allow(clippy::exhaustive_structs)] // this type is stable +pub struct ZonedDateTime { + /// The date, local to the time zone + pub date: Date, + /// The time, local to the time zone + pub time: Time, + /// The time zone + pub zone: Z, +} /// An offset from Coordinated Universal Time (UTC) #[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] diff --git a/components/timezone/src/zoned_datetime.rs b/components/timezone/src/zoned_datetime.rs deleted file mode 100644 index 204d0c81571..00000000000 --- a/components/timezone/src/zoned_datetime.rs +++ /dev/null @@ -1,39 +0,0 @@ -// This file is part of ICU4X. For terms of use, please see the file -// called LICENSE at the top level of the ICU4X source tree -// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). - -use icu_calendar::{AsCalendar, Date, Iso, Time}; - -/// A date and time local to a specified custom time zone. -#[derive(Debug)] -#[allow(clippy::exhaustive_structs)] // this type is stable -pub struct CustomZonedDateTime { - /// The date, local to the time zone - pub date: Date, - /// The time, local to the time zone - pub time: Time, - /// The time zone - pub zone: Z, -} - -impl CustomZonedDateTime { - /// Convert the CustomZonedDateTime to an ISO CustomZonedDateTime - #[inline] - pub fn to_iso(&self) -> CustomZonedDateTime { - CustomZonedDateTime { - date: self.date.to_iso(), - time: self.time, - zone: self.zone, - } - } - - /// Convert the CustomZonedDateTime to a CustomZonedDateTime in a different calendar - #[inline] - pub fn to_calendar(&self, calendar: A2) -> CustomZonedDateTime { - CustomZonedDateTime { - date: self.date.to_calendar(calendar), - time: self.time, - zone: self.zone, - } - } -} diff --git a/ffi/capi/src/zoned_formatter.rs b/ffi/capi/src/zoned_formatter.rs index 1c962137120..833275b0c06 100644 --- a/ffi/capi/src/zoned_formatter.rs +++ b/ffi/capi/src/zoned_formatter.rs @@ -84,7 +84,7 @@ pub mod ffi { write: &mut diplomat_runtime::DiplomatWrite, ) -> Result<(), DateTimeFormatError> { let greg = icu_calendar::DateTime::new_from_iso(datetime.0, icu_calendar::Gregorian); - let zdt = icu_timezone::CustomZonedDateTime { + let zdt = icu_timezone::ZonedDateTime { date: greg.date, time: greg.time, zone: time_zone @@ -151,7 +151,7 @@ pub mod ffi { time_zone: &TimeZoneInfo, write: &mut diplomat_runtime::DiplomatWrite, ) -> Result<(), DateTimeFormatError> { - let zdt = icu_timezone::CustomZonedDateTime { + let zdt = icu_timezone::ZonedDateTime { date: datetime.0.date.clone(), time: datetime.0.time, zone: time_zone @@ -175,7 +175,7 @@ pub mod ffi { time_zone: &TimeZoneInfo, write: &mut diplomat_runtime::DiplomatWrite, ) -> Result<(), DateTimeFormatError> { - let zdt = icu_timezone::CustomZonedDateTime { + let zdt = icu_timezone::ZonedDateTime { date: datetime.0.date, time: datetime.0.time, zone: time_zone diff --git a/ffi/capi/tests/missing_apis.txt b/ffi/capi/tests/missing_apis.txt index 50a84216ff4..aaeb28bb47b 100644 --- a/ffi/capi/tests/missing_apis.txt +++ b/ffi/capi/tests/missing_apis.txt @@ -751,9 +751,6 @@ icu::properties::PropertyNamesShortBorrowed::get_locale_script#FnInStruct icu::properties::PropertyNamesShortBorrowed::new#FnInStruct icu::properties::props::BidiMirroringGlyph#Struct icu::properties::props::BidiPairedBracketType#Enum -icu::timezone::CustomZonedDateTime#Struct -icu::timezone::CustomZonedDateTime::to_calendar#FnInStruct -icu::timezone::CustomZonedDateTime::to_iso#FnInStruct icu::timezone::IxdtfParser#Struct icu::timezone::IxdtfParser::new#FnInStruct icu::timezone::IxdtfParser::try_from_str#FnInStruct @@ -791,6 +788,7 @@ icu::timezone::ZoneOffsetCalculator::compute_offsets_from_time_zone#FnInStruct icu::timezone::ZoneOffsetCalculator::new#FnInStruct icu::timezone::ZoneOffsets#Struct icu::timezone::ZoneVariant::into_option#FnInEnum +icu::timezone::ZonedDateTime#Struct icu::timezone::models::AtTime#Enum icu::timezone::models::Base#Enum icu::timezone::models::Full#Enum