From e271d9503dc2c447145e7f2043f36d5ac4c8d057 Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Thu, 16 Jan 2025 09:42:06 +0100 Subject: [PATCH] Rename `IxdtfParser` and methods (#6007) --- components/datetime/src/combo.rs | 24 ++-- components/datetime/src/fieldsets.rs | 8 +- components/datetime/src/parts.rs | 4 +- components/datetime/src/pattern/formatter.rs | 10 +- components/datetime/src/pattern/names.rs | 60 ++++---- components/datetime/tests/mock.rs | 6 +- components/icu/examples/jiff.rs | 8 +- components/timezone/src/ixdtf.rs | 132 +++++++++--------- components/timezone/src/lib.rs | 2 +- ffi/capi/bindings/c/IxdtfParser.d.h | 19 --- ffi/capi/bindings/c/IxdtfParser.h | 42 ------ ffi/capi/bindings/c/ZonedDateTimeParser.d.h | 19 +++ ffi/capi/bindings/c/ZonedDateTimeParser.h | 42 ++++++ ffi/capi/bindings/cpp/icu4x/IxdtfParser.d.hpp | 59 -------- ffi/capi/bindings/cpp/icu4x/IxdtfParser.hpp | 87 ------------ .../cpp/icu4x/ZonedDateTimeParser.d.hpp | 59 ++++++++ .../cpp/icu4x/ZonedDateTimeParser.hpp | 87 ++++++++++++ ...rser.g.dart => ZonedDateTimeParser.g.dart} | 54 +++---- ffi/capi/bindings/dart/lib.g.dart | 2 +- ...tfParser.d.ts => ZonedDateTimeParser.d.ts} | 6 +- ...xdtfParser.mjs => ZonedDateTimeParser.mjs} | 24 ++-- ffi/capi/bindings/js/index.d.ts | 2 +- ffi/capi/bindings/js/index.mjs | 2 +- ffi/capi/src/zoned_datetime.rs | 43 +++--- ffi/capi/tests/missing_apis.txt | 14 +- ffi/dart/test/icu_test.dart | 2 +- 26 files changed, 415 insertions(+), 402 deletions(-) delete mode 100644 ffi/capi/bindings/c/IxdtfParser.d.h delete mode 100644 ffi/capi/bindings/c/IxdtfParser.h create mode 100644 ffi/capi/bindings/c/ZonedDateTimeParser.d.h create mode 100644 ffi/capi/bindings/c/ZonedDateTimeParser.h delete mode 100644 ffi/capi/bindings/cpp/icu4x/IxdtfParser.d.hpp delete mode 100644 ffi/capi/bindings/cpp/icu4x/IxdtfParser.hpp create mode 100644 ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.d.hpp create mode 100644 ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.hpp rename ffi/capi/bindings/dart/{IxdtfParser.g.dart => ZonedDateTimeParser.g.dart} (53%) rename ffi/capi/bindings/js/{IxdtfParser.d.ts => ZonedDateTimeParser.d.ts} (67%) rename ffi/capi/bindings/js/{IxdtfParser.mjs => ZonedDateTimeParser.mjs} (75%) diff --git a/components/datetime/src/combo.rs b/components/datetime/src/combo.rs index 2974cd097cf..a664cd30f7b 100644 --- a/components/datetime/src/combo.rs +++ b/components/datetime/src/combo.rs @@ -25,7 +25,7 @@ use crate::{provider::neo::*, scaffold::*}; /// use icu::datetime::fieldsets::{Combo, ET, L}; /// use icu::datetime::DateTimeFormatter; /// use icu::locale::locale; -/// use icu::timezone::IxdtfParser; +/// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_writeable_eq; /// /// // Note: Combo type can be elided, but it is shown here for demonstration @@ -35,8 +35,8 @@ use crate::{provider::neo::*, scaffold::*}; /// ) /// .unwrap(); /// -/// let zdt = IxdtfParser::new() -/// .try_location_only_from_str("2024-10-18T15:44[America/Los_Angeles]", formatter.calendar()) +/// let zdt = ZonedDateTimeParser::new() +/// .parse_location_only("2024-10-18T15:44[America/Los_Angeles]", formatter.calendar()) /// .unwrap(); /// /// assert_writeable_eq!( @@ -52,7 +52,7 @@ use crate::{provider::neo::*, scaffold::*}; /// use icu::datetime::fieldsets::{Combo, ET, L}; /// use icu::datetime::FixedCalendarDateTimeFormatter; /// use icu::locale::locale; -/// use icu::timezone::{IxdtfParser, ZonedDateTime}; +/// use icu::timezone::{ZonedDateTimeParser, ZonedDateTime}; /// use writeable::assert_writeable_eq; /// /// // Note: Combo type can be elided, but it is shown here for demonstration @@ -62,8 +62,8 @@ use crate::{provider::neo::*, scaffold::*}; /// ) /// .unwrap(); /// -/// let zdt = IxdtfParser::new() -/// .try_location_only_from_str("2024-10-18T15:44[America/Los_Angeles]", Gregorian) +/// let zdt = ZonedDateTimeParser::new() +/// .parse_location_only("2024-10-18T15:44[America/Los_Angeles]", Gregorian) /// .unwrap(); /// /// assert_writeable_eq!( @@ -79,7 +79,7 @@ use crate::{provider::neo::*, scaffold::*}; /// use icu::datetime::fieldsets::{enums::DateFieldSet, Combo, Vs, YMD}; /// use icu::datetime::DateTimeFormatter; /// use icu::locale::locale; -/// use icu::timezone::IxdtfParser; +/// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_writeable_eq; /// /// // Note: Combo type can be elided, but it is shown here for demonstration @@ -89,8 +89,8 @@ use crate::{provider::neo::*, scaffold::*}; /// ) /// .unwrap(); /// -/// let zdt = IxdtfParser::new() -/// .try_location_only_from_str("2024-10-18T15:44[America/Los_Angeles]", formatter.calendar()) +/// let zdt = ZonedDateTimeParser::new() +/// .parse_location_only("2024-10-18T15:44[America/Los_Angeles]", formatter.calendar()) /// .unwrap(); /// /// assert_writeable_eq!( @@ -106,7 +106,7 @@ use crate::{provider::neo::*, scaffold::*}; /// use icu::datetime::fieldsets::T; /// use icu::datetime::FixedCalendarDateTimeFormatter; /// use icu::locale::locale; -/// use icu::timezone::{IxdtfParser, ZonedDateTime}; +/// use icu::timezone::{ZonedDateTimeParser, ZonedDateTime}; /// use writeable::assert_writeable_eq; /// /// let formatter = FixedCalendarDateTimeFormatter::try_new( @@ -115,8 +115,8 @@ use crate::{provider::neo::*, scaffold::*}; /// ) /// .unwrap(); /// -/// let zdt = IxdtfParser::new() -/// .try_from_str("2024-10-18T15:44-0700[America/Los_Angeles]", Gregorian) +/// let zdt = ZonedDateTimeParser::new() +/// .parse("2024-10-18T15:44-0700[America/Los_Angeles]", Gregorian) /// .unwrap(); /// /// assert_writeable_eq!( diff --git a/components/datetime/src/fieldsets.rs b/components/datetime/src/fieldsets.rs index 6e459cfbd93..9a4c3c7223d 100644 --- a/components/datetime/src/fieldsets.rs +++ b/components/datetime/src/fieldsets.rs @@ -1188,7 +1188,7 @@ impl_zone_marker!( /// /// ``` /// use icu::calendar::Date; - /// use icu::timezone::{IxdtfParser, Time, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant}; + /// use icu::timezone::{ZonedDateTimeParser, Time, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant}; /// use icu::calendar::Gregorian; /// use icu::datetime::FixedCalendarDateTimeFormatter; /// use icu::datetime::fieldsets::{Z, Zs}; @@ -1378,7 +1378,7 @@ impl_zone_marker!( /// /// ``` /// use icu::calendar::Date; - /// use icu::timezone::{IxdtfParser, Time, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant}; + /// use icu::timezone::{Time, TimeZoneBcp47Id}; /// use icu::calendar::Gregorian; /// use icu::datetime::FixedCalendarDateTimeFormatter; /// use icu::datetime::fieldsets::Vs; @@ -1407,7 +1407,7 @@ impl_zone_marker!( /// /// ``` /// use icu::calendar::Date; - /// use icu::timezone::{Time, TimeZoneInfo, UtcOffset, TimeZoneIdMapper, TimeZoneBcp47Id}; + /// use icu::timezone::{Time, TimeZoneIdMapper}; /// use icu::datetime::TimeFormatter; /// use icu::datetime::fieldsets::Vs; /// use icu::datetime::DateTimeWriteError; @@ -1460,7 +1460,7 @@ impl_zone_marker!( /// use icu::calendar::{DateTime, Iso}; /// use icu::datetime::TimeFormatter; /// use icu::datetime::fieldsets::V; - /// use icu::timezone::{TimeZoneBcp47Id, UtcOffset}; + /// use icu::timezone::TimeZoneBcp47Id; /// use tinystr::tinystr; /// use icu::locale::locale; /// use writeable::assert_writeable_eq; diff --git a/components/datetime/src/parts.rs b/components/datetime/src/parts.rs index e55e4de1f9b..61b4d56a7f1 100644 --- a/components/datetime/src/parts.rs +++ b/components/datetime/src/parts.rs @@ -16,7 +16,7 @@ //! use icu::datetime::DateTimeFormatter; //! use icu::decimal::parts as decimal_parts; //! use icu::locale::locale; -//! use icu::timezone::{IxdtfParser, Time}; +//! use icu::timezone::{ZonedDateTimeParser, Time}; //! use writeable::assert_writeable_parts_eq; //! //! let dtf = DateTimeFormatter::try_new( @@ -25,7 +25,7 @@ //! ) //! .unwrap(); //! -//! let dtz = IxdtfParser::new().try_from_str("2023-11-20T11:35:03.5+00:00[Europe/London]", dtf.calendar()).unwrap(); +//! let dtz = ZonedDateTimeParser::new().parse("2023-11-20T11:35:03.5+00:00[Europe/London]", dtf.calendar()).unwrap(); //! //! // Missing data is filled in on a best-effort basis, and an error is signaled. //! assert_writeable_parts_eq!( diff --git a/components/datetime/src/pattern/formatter.rs b/components/datetime/src/pattern/formatter.rs index 80586b42130..db00e756113 100644 --- a/components/datetime/src/pattern/formatter.rs +++ b/components/datetime/src/pattern/formatter.rs @@ -157,14 +157,14 @@ where /// use icu::datetime::pattern::DateTimePattern; /// use icu::datetime::pattern::TypedDateTimeNames; /// use icu::locale::locale; - /// use icu::timezone::IxdtfParser; + /// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_try_writeable_eq; /// - /// let mut london_winter = IxdtfParser::new() - /// .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) + /// let mut london_winter = ZonedDateTimeParser::new() + /// .parse("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) /// .unwrap(); - /// let mut london_summer = IxdtfParser::new() - /// .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) + /// let mut london_summer = ZonedDateTimeParser::new() + /// .parse("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) /// .unwrap(); /// /// let mut names = TypedDateTimeNames::::try_new( diff --git a/components/datetime/src/pattern/names.rs b/components/datetime/src/pattern/names.rs index 3a91205cee2..2258772a658 100644 --- a/components/datetime/src/pattern/names.rs +++ b/components/datetime/src/pattern/names.rs @@ -432,7 +432,7 @@ size_test!( /// use icu::datetime::pattern::{DateTimePattern, PatternLoadError}; /// use icu::datetime::fieldsets::enums::CompositeFieldSet; /// use icu::locale::locale; -/// use icu::timezone::{Time, TimeZoneInfo, IxdtfParser, ZonedDateTime}; +/// use icu::timezone::{Time, TimeZoneInfo, ZonedDateTimeParser, ZonedDateTime}; /// use icu_provider_adapters::empty::EmptyDataProvider; /// use writeable::{Part, assert_try_writeable_parts_eq}; /// @@ -450,7 +450,7 @@ size_test!( /// // The pattern string contains lots of symbols including "E", "MMM", and "a", /// // but we did not load any data! /// -/// let mut dtz = IxdtfParser::new().try_from_str("2023-11-20T11:35:03+00:00[Europe/London]", Gregorian).unwrap(); +/// let mut dtz = ZonedDateTimeParser::new().parse("2023-11-20T11:35:03+00:00[Europe/London]", Gregorian).unwrap(); /// /// // Missing data is filled in on a best-effort basis, and an error is signaled. /// assert_try_writeable_parts_eq!( @@ -1012,15 +1012,15 @@ impl TypedDateTimeNames { /// use icu::datetime::pattern::DateTimePattern; /// use icu::datetime::pattern::TypedDateTimeNames; /// use icu::locale::locale; - /// use icu::timezone::IxdtfParser; + /// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_try_writeable_eq; /// - /// let mut zone_london_winter = IxdtfParser::new() - /// .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) + /// let mut zone_london_winter = ZonedDateTimeParser::new() + /// .parse("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; - /// let mut zone_london_summer = IxdtfParser::new() - /// .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) + /// let mut zone_london_summer = ZonedDateTimeParser::new() + /// .parse("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; /// @@ -1124,11 +1124,11 @@ impl TypedDateTimeNames { /// use icu::datetime::pattern::DateTimePattern; /// use icu::datetime::pattern::TypedDateTimeNames; /// use icu::locale::locale; - /// use icu::timezone::IxdtfParser; + /// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_try_writeable_eq; /// - /// let mut zone_london_winter = IxdtfParser::new() - /// .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) + /// let mut zone_london_winter = ZonedDateTimeParser::new() + /// .parse("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; /// @@ -1191,15 +1191,15 @@ impl TypedDateTimeNames { /// use icu::datetime::pattern::DateTimePattern; /// use icu::datetime::pattern::TypedDateTimeNames; /// use icu::locale::locale; - /// use icu::timezone::IxdtfParser; + /// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_try_writeable_eq; /// - /// let mut zone_london_winter = IxdtfParser::new() - /// .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) + /// let mut zone_london_winter = ZonedDateTimeParser::new() + /// .parse("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; - /// let mut zone_london_summer = IxdtfParser::new() - /// .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) + /// let mut zone_london_summer = ZonedDateTimeParser::new() + /// .parse("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; /// @@ -1268,15 +1268,15 @@ impl TypedDateTimeNames { /// use icu::datetime::pattern::DateTimePattern; /// use icu::datetime::pattern::TypedDateTimeNames; /// use icu::locale::locale; - /// use icu::timezone::IxdtfParser; + /// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_try_writeable_eq; /// - /// let mut zone_london_winter = IxdtfParser::new() - /// .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) + /// let mut zone_london_winter = ZonedDateTimeParser::new() + /// .parse("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; - /// let mut zone_london_summer = IxdtfParser::new() - /// .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) + /// let mut zone_london_summer = ZonedDateTimeParser::new() + /// .parse("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; /// @@ -1345,15 +1345,15 @@ impl TypedDateTimeNames { /// use icu::datetime::pattern::DateTimePattern; /// use icu::datetime::pattern::TypedDateTimeNames; /// use icu::locale::locale; - /// use icu::timezone::IxdtfParser; + /// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_try_writeable_eq; /// - /// let mut zone_london_winter = IxdtfParser::new() - /// .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) + /// let mut zone_london_winter = ZonedDateTimeParser::new() + /// .parse("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; - /// let mut zone_london_summer = IxdtfParser::new() - /// .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) + /// let mut zone_london_summer = ZonedDateTimeParser::new() + /// .parse("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; /// @@ -1422,15 +1422,15 @@ impl TypedDateTimeNames { /// use icu::datetime::pattern::DateTimePattern; /// use icu::datetime::pattern::TypedDateTimeNames; /// use icu::locale::locale; - /// use icu::timezone::IxdtfParser; + /// use icu::timezone::ZonedDateTimeParser; /// use writeable::assert_try_writeable_eq; /// - /// let mut zone_london_winter = IxdtfParser::new() - /// .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) + /// let mut zone_london_winter = ZonedDateTimeParser::new() + /// .parse("2024-01-01T00:00:00+00:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; - /// let mut zone_london_summer = IxdtfParser::new() - /// .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) + /// let mut zone_london_summer = ZonedDateTimeParser::new() + /// .parse("2024-07-01T00:00:00+01:00[Europe/London]", Gregorian) /// .unwrap() /// .zone; /// diff --git a/components/datetime/tests/mock.rs b/components/datetime/tests/mock.rs index 50f43266930..a824575f79a 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::Gregorian; -use icu_timezone::{models, IxdtfParser, TimeZoneInfo, ZoneVariant, ZonedDateTime}; +use icu_timezone::{models, TimeZoneInfo, ZoneVariant, ZonedDateTime, ZonedDateTimeParser}; /// Parse a [`DateTime`] and [`TimeZoneInfo`] from a string. /// @@ -28,10 +28,10 @@ use icu_timezone::{models, IxdtfParser, TimeZoneInfo, ZoneVariant, ZonedDateTime pub fn parse_zoned_gregorian_from_str( input: &str, ) -> ZonedDateTime> { - match IxdtfParser::new().try_from_str(input, Gregorian) { + match ZonedDateTimeParser::new().parse(input, Gregorian) { Ok(zdt) => zdt, Err(icu_timezone::ParseError::MismatchedTimeZoneFields) => { - match IxdtfParser::new().try_loose_from_str(input, Gregorian) { + match ZonedDateTimeParser::new().parse_loose(input, Gregorian) { Ok(zdt) => { ZonedDateTime { date: zdt.date, diff --git a/components/icu/examples/jiff.rs b/components/icu/examples/jiff.rs index f2f22a69d60..0940aa68b4f 100644 --- a/components/icu/examples/jiff.rs +++ b/components/icu/examples/jiff.rs @@ -6,7 +6,9 @@ use icu::{ calendar::Date, datetime::{fieldsets, DateTimeFormatter}, locale::locale, - timezone::{IxdtfParser, Time, TimeZoneIdMapper, UtcOffset, ZoneVariant, ZonedDateTime}, + timezone::{ + Time, TimeZoneIdMapper, UtcOffset, ZoneVariant, ZonedDateTime, ZonedDateTimeParser, + }, }; fn main() -> Result<(), Box> { @@ -47,8 +49,8 @@ fn main() -> Result<(), Box> { // Alternatively, the ICU ZonedDateTime can be parsed from a serialized IXDTF string. assert_eq!( - IxdtfParser::new() - .try_from_str(&zoned.to_string(), icu::calendar::Iso) + ZonedDateTimeParser::new() + .parse(&zoned.to_string(), icu::calendar::Iso) .unwrap(), zoned_date_time ); diff --git a/components/timezone/src/ixdtf.rs b/components/timezone/src/ixdtf.rs index 4b3ba0b04d5..afb2049b73f 100644 --- a/components/timezone/src/ixdtf.rs +++ b/components/timezone/src/ixdtf.rs @@ -13,9 +13,12 @@ use core::str::FromStr; use icu_calendar::{AnyCalendarKind, AsCalendar, Date, DateError, Iso, RangeError}; use icu_provider::prelude::*; use ixdtf::{ - parsers::records::{ - DateRecord, IxdtfParseRecord, TimeRecord, TimeZoneAnnotation, TimeZoneRecord, - UtcOffsetRecord, UtcOffsetRecordOrZ, + parsers::{ + records::{ + DateRecord, IxdtfParseRecord, TimeRecord, TimeZoneAnnotation, TimeZoneRecord, + UtcOffsetRecord, UtcOffsetRecordOrZ, + }, + IxdtfParser, }, ParseError as IxdtfParseError, }; @@ -54,17 +57,17 @@ pub enum ParseError { /// # Example /// ``` /// use icu::calendar::Iso; - /// use icu::timezone::{IxdtfParser, ParseError}; + /// use icu::timezone::{ZonedDateTimeParser, ParseError}; /// /// // This timestamp is in UTC, and requires a time zone calculation in order to display a Zurich time. /// assert_eq!( - /// IxdtfParser::new().try_loose_from_str("2024-08-12T12:32:00Z[Europe/Zurich]", Iso).unwrap_err(), + /// ZonedDateTimeParser::new().parse_loose("2024-08-12T12:32:00Z[Europe/Zurich]", Iso).unwrap_err(), /// ParseError::RequiresCalculation, /// ); /// /// // These timestamps are in local time - /// IxdtfParser::new().try_loose_from_str("2024-08-12T14:32:00+02:00[Europe/Zurich]", Iso).unwrap(); - /// IxdtfParser::new().try_loose_from_str("2024-08-12T14:32:00[Europe/Zurich]", Iso).unwrap(); + /// ZonedDateTimeParser::new().parse_loose("2024-08-12T14:32:00+02:00[Europe/Zurich]", Iso).unwrap(); + /// ZonedDateTimeParser::new().parse_loose("2024-08-12T14:32:00[Europe/Zurich]", Iso).unwrap(); /// ``` #[displaydoc( "A timezone calculation is required to interpret this string, which is not supported" @@ -130,13 +133,13 @@ impl UtcOffset { /// argument. /// /// ✨ *Enabled with the `ixdtf` Cargo feature.* -pub struct IxdtfParser { +pub struct ZonedDateTimeParser { mapper: TimeZoneIdMapper, offsets: ZoneOffsetCalculator, } -impl IxdtfParser { - /// Creates a new `IxdtfParser` from compiled data. +impl ZonedDateTimeParser { + /// Creates a new [`ZonedDateTimeParser`] from compiled data. #[cfg(feature = "compiled_data")] #[allow(clippy::new_without_default)] pub fn new() -> Self { @@ -418,30 +421,30 @@ impl<'a> Intermediate<'a> { } } -impl IxdtfParser { +impl ZonedDateTimeParser { /// Create a [`ZonedDateTime`] in any calendar from an IXDTF syntax string. /// /// Returns an error if the string has a calendar annotation that does not /// match the calendar argument, unless the argument is [`Iso`]. /// /// This function is "strict": the string should have only an offset and no named time zone. - pub fn try_offset_only_from_str( + pub fn parse_offset_only( &self, ixdtf_str: &str, calendar: A, ) -> Result, ParseError> { - self.try_offset_only_from_utf8(ixdtf_str.as_bytes(), calendar) + self.parse_offset_only_from_utf8(ixdtf_str.as_bytes(), calendar) } /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// - /// See [`Self::try_offset_only_from_str`]. - pub fn try_offset_only_from_utf8( + /// See [`Self::parse_offset_only`]. + pub fn parse_offset_only_from_utf8( &self, ixdtf_str: &[u8], calendar: A, ) -> Result, ParseError> { - let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; + let ixdtf_record = IxdtfParser::from_utf8(ixdtf_str).parse()?; let date = Date::try_from_ixdtf_record(&ixdtf_record, calendar)?; let time = Time::try_from_ixdtf_record(&ixdtf_record)?; let zone = Intermediate::try_from_ixdtf_record(&ixdtf_record)?.offset_only()?; @@ -454,23 +457,23 @@ impl IxdtfParser { /// match the calendar argument, unless the argument is [`Iso`]. /// /// This function is "strict": the string should have only a named time zone and no offset. - pub fn try_location_only_from_str( + pub fn parse_location_only( &self, ixdtf_str: &str, calendar: A, ) -> Result>, ParseError> { - self.try_location_only_from_utf8(ixdtf_str.as_bytes(), calendar) + self.parse_location_only_from_utf8(ixdtf_str.as_bytes(), calendar) } /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// - /// See [`Self::try_location_only_from_str`]. - pub fn try_location_only_from_utf8( + /// See [`Self::parse_location_only`]. + pub fn parse_location_only_from_utf8( &self, ixdtf_str: &[u8], calendar: A, ) -> Result>, ParseError> { - let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; + let ixdtf_record = IxdtfParser::from_utf8(ixdtf_str).parse()?; let date = Date::try_from_ixdtf_record(&ixdtf_record, calendar)?; let time = Time::try_from_ixdtf_record(&ixdtf_record)?; let zone = Intermediate::try_from_ixdtf_record(&ixdtf_record)? @@ -487,24 +490,24 @@ impl IxdtfParser { /// neither. If the named time zone is missing, it is returned as Etc/Unknown. /// /// The zone variant is _not_ calculated with this function. If you need it, use - /// [`Self::try_from_str`]. - pub fn try_loose_from_str( + /// [`Self::parse`]. + pub fn parse_loose( &self, ixdtf_str: &str, calendar: A, ) -> Result>, ParseError> { - self.try_loose_from_utf8(ixdtf_str.as_bytes(), calendar) + self.parse_loose_from_utf8(ixdtf_str.as_bytes(), calendar) } /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// - /// See [`Self::try_loose_from_str`]. - pub fn try_loose_from_utf8( + /// See [`Self::parse_loose`]. + pub fn parse_loose_from_utf8( &self, ixdtf_str: &[u8], calendar: A, ) -> Result>, ParseError> { - let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; + let ixdtf_record = IxdtfParser::from_utf8(ixdtf_str).parse()?; let date = Date::try_from_ixdtf_record(&ixdtf_record, calendar)?; let time = Time::try_from_ixdtf_record(&ixdtf_record)?; let zone = @@ -528,12 +531,12 @@ impl IxdtfParser { /// ``` /// use icu_calendar::cal::Hebrew; /// use icu_timezone::{ - /// IxdtfParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant, + /// ZonedDateTimeParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant, /// }; /// use tinystr::tinystr; /// - /// let zoneddatetime = IxdtfParser::new() - /// .try_from_str("2024-08-08T12:08:19-05:00[America/Chicago][u-ca=hebrew]", Hebrew) + /// let zoneddatetime = ZonedDateTimeParser::new() + /// .parse("2024-08-08T12:08:19-05:00[America/Chicago][u-ca=hebrew]", Hebrew) /// .unwrap(); /// /// assert_eq!(zoneddatetime.date.year().extended_year, 5784); @@ -571,10 +574,10 @@ impl IxdtfParser { /// /// ``` /// use icu_calendar::Iso; - /// use icu_timezone::{IxdtfParser, TimeZoneInfo, UtcOffset}; + /// use icu_timezone::{ZonedDateTimeParser, TimeZoneInfo, UtcOffset}; /// - /// let tz_from_offset = IxdtfParser::new() - /// .try_offset_only_from_str("2024-08-08T12:08:19-05:00", Iso) + /// let tz_from_offset = ZonedDateTimeParser::new() + /// .parse_offset_only("2024-08-08T12:08:19-05:00", Iso) /// .unwrap(); /// /// assert_eq!( @@ -590,15 +593,15 @@ impl IxdtfParser { /// ``` /// use icu_calendar::Iso; /// use icu_timezone::{ - /// IxdtfParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant, + /// ZonedDateTimeParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant, /// }; /// use tinystr::tinystr; /// - /// let tz_from_offset_annotation = IxdtfParser::new() - /// .try_offset_only_from_str("2024-08-08T12:08:19[-05:00]", Iso) + /// let tz_from_offset_annotation = ZonedDateTimeParser::new() + /// .parse_offset_only("2024-08-08T12:08:19[-05:00]", Iso) /// .unwrap(); - /// let tz_from_iana_annotation = IxdtfParser::new() - /// .try_location_only_from_str("2024-08-08T12:08:19[America/Chicago]", Iso) + /// let tz_from_iana_annotation = ZonedDateTimeParser::new() + /// .parse_location_only("2024-08-08T12:08:19[America/Chicago]", Iso) /// .unwrap(); /// /// assert_eq!( @@ -624,10 +627,10 @@ impl IxdtfParser { /// /// ``` /// use icu_calendar::Iso; - /// use icu_timezone::{TimeZoneInfo, IxdtfParser, UtcOffset, TimeZoneBcp47Id, ZoneVariant, ParseError}; + /// use icu_timezone::{TimeZoneInfo, ZonedDateTimeParser, UtcOffset, TimeZoneBcp47Id, ZoneVariant, ParseError}; /// use tinystr::tinystr; /// - /// let consistent_tz_from_both = IxdtfParser::new().try_from_str("2024-08-08T12:08:19-05:00[America/Chicago]", Iso).unwrap(); + /// let consistent_tz_from_both = ZonedDateTimeParser::new().parse("2024-08-08T12:08:19-05:00[America/Chicago]", Iso).unwrap(); /// /// /// assert_eq!(consistent_tz_from_both.zone.time_zone_id(), TimeZoneBcp47Id(tinystr!(8, "uschi"))); @@ -637,13 +640,13 @@ impl IxdtfParser { /// /// // We know that America/Los_Angeles never used a -05:00 offset at any time of the year 2024 /// assert_eq!( - /// IxdtfParser::new().try_from_str("2024-08-08T12:08:19-05:00[America/Los_Angeles]", Iso).unwrap_err(), + /// ZonedDateTimeParser::new().parse("2024-08-08T12:08:19-05:00[America/Los_Angeles]", Iso).unwrap_err(), /// ParseError::InvalidOffsetError /// ); /// /// // We don't know that America/Los_Angeles didn't use standard time (-08:00) in August /// assert!( - /// IxdtfParser::new().try_from_str("2024-08-08T12:08:19-08:00[America/Los_Angeles]", Iso).is_ok() + /// ZonedDateTimeParser::new().parse("2024-08-08T12:08:19-08:00[America/Los_Angeles]", Iso).is_ok() /// ); /// ``` /// @@ -654,12 +657,12 @@ impl IxdtfParser { /// ``` /// use icu_calendar::Iso; /// use icu_timezone::{ - /// IxdtfParser, ParseError, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, + /// ZonedDateTimeParser, ParseError, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, /// }; /// use tinystr::tinystr; /// - /// let consistent_tz_from_both = IxdtfParser::new() - /// .try_offset_only_from_str("2024-08-08T12:08:19-05:00[-05:00]", Iso) + /// let consistent_tz_from_both = ZonedDateTimeParser::new() + /// .parse_offset_only("2024-08-08T12:08:19-05:00[-05:00]", Iso) /// .unwrap(); /// /// assert_eq!( @@ -667,35 +670,36 @@ impl IxdtfParser { /// UtcOffset::try_from_seconds(-18000).unwrap() /// ); /// - /// let inconsistent_tz_from_both = IxdtfParser::new() - /// .try_offset_only_from_str("2024-08-08T12:08:19-05:00[+05:00]", Iso); + /// let inconsistent_tz_from_both = ZonedDateTimeParser::new() + /// .parse_offset_only("2024-08-08T12:08:19-05:00[+05:00]", Iso); /// /// assert!(matches!( /// inconsistent_tz_from_both, /// Err(ParseError::InconsistentTimeZoneOffsets) /// )); /// ``` - pub fn try_from_str( + pub fn parse( &self, ixdtf_str: &str, calendar: A, ) -> Result>, ParseError> { - self.try_from_utf8(ixdtf_str.as_bytes(), calendar) + self.parse_from_utf8(ixdtf_str.as_bytes(), calendar) } /// Create a [`ZonedDateTime`] in any calendar from IXDTF syntax UTF-8 bytes. /// - /// See [`Self::try_from_str`]. - pub fn try_from_utf8( + /// See [`Self::parse`]. + pub fn parse_from_utf8( &self, ixdtf_str: &[u8], calendar: A, ) -> Result>, ParseError> { - let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; + let ixdtf_record = IxdtfParser::from_utf8(ixdtf_str).parse()?; let date = Date::try_from_ixdtf_record(&ixdtf_record, calendar)?; let time = Time::try_from_ixdtf_record(&ixdtf_record)?; let zone = Intermediate::try_from_ixdtf_record(&ixdtf_record)? .full(self.mapper.as_borrowed(), &self.offsets)?; + Ok(ZonedDateTime { date, time, zone }) } } @@ -746,7 +750,7 @@ impl DateTime { /// /// ✨ *Enabled with the `ixdtf` Cargo feature.* pub fn try_from_utf8(ixdtf_str: &[u8], calendar: A) -> Result { - let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse()?; + let ixdtf_record = IxdtfParser::from_utf8(ixdtf_str).parse()?; let date = Date::try_from_ixdtf_record(&ixdtf_record, calendar)?; let time = Time::try_from_ixdtf_record(&ixdtf_record)?; Ok(Self { date, time }) @@ -782,7 +786,7 @@ impl Time { /// /// See [`Self::try_from_str()`]. pub fn try_from_utf8(ixdtf_str: &[u8]) -> Result { - let ixdtf_record = ixdtf::parsers::IxdtfParser::from_utf8(ixdtf_str).parse_time()?; + let ixdtf_record = IxdtfParser::from_utf8(ixdtf_str).parse_time()?; Self::try_from_ixdtf_record(&ixdtf_record) } @@ -813,8 +817,8 @@ mod test { #[test] fn max_possible_ixdtf_utc_offset() { assert_eq!( - IxdtfParser::new() - .try_offset_only_from_str("2024-08-08T12:08:19+23:59:60.999999999", Iso) + ZonedDateTimeParser::new() + .parse_offset_only("2024-08-08T12:08:19+23:59:60.999999999", Iso) .unwrap_err(), ParseError::InvalidOffsetError ); @@ -822,18 +826,18 @@ mod test { #[test] fn zone_calculations() { - IxdtfParser::new() - .try_offset_only_from_str("2024-08-08T12:08:19Z", Iso) + ZonedDateTimeParser::new() + .parse_offset_only("2024-08-08T12:08:19Z", Iso) .unwrap(); assert_eq!( - IxdtfParser::new() - .try_offset_only_from_str("2024-08-08T12:08:19Z[+08:00]", Iso) + ZonedDateTimeParser::new() + .parse_offset_only("2024-08-08T12:08:19Z[+08:00]", Iso) .unwrap_err(), ParseError::RequiresCalculation ); assert_eq!( - IxdtfParser::new() - .try_offset_only_from_str("2024-08-08T12:08:19Z[Europe/Zurich]", Iso) + ZonedDateTimeParser::new() + .parse_offset_only("2024-08-08T12:08:19Z[Europe/Zurich]", Iso) .unwrap_err(), ParseError::MismatchedTimeZoneFields ); @@ -841,8 +845,8 @@ mod test { #[test] fn future_zone() { - let result = IxdtfParser::new() - .try_loose_from_str("2024-08-08T12:08:19[Future/Zone]", Iso) + let result = ZonedDateTimeParser::new() + .parse_loose("2024-08-08T12:08:19[Future/Zone]", Iso) .unwrap(); assert_eq!(result.zone.time_zone_id(), TimeZoneBcp47Id::unknown()); assert_eq!(result.zone.offset(), None); diff --git a/components/timezone/src/lib.rs b/components/timezone/src/lib.rs index 4bd3e3fbb50..3f37c1ca504 100644 --- a/components/timezone/src/lib.rs +++ b/components/timezone/src/lib.rs @@ -115,7 +115,7 @@ mod zone_offset; #[cfg(feature = "ixdtf")] mod ixdtf; #[cfg(feature = "ixdtf")] -pub use self::ixdtf::IxdtfParser; +pub use self::ixdtf::ZonedDateTimeParser; pub use error::InvalidOffsetError; pub use ids::{ diff --git a/ffi/capi/bindings/c/IxdtfParser.d.h b/ffi/capi/bindings/c/IxdtfParser.d.h deleted file mode 100644 index 74a43b5f565..00000000000 --- a/ffi/capi/bindings/c/IxdtfParser.d.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef IxdtfParser_D_H -#define IxdtfParser_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - - - - -typedef struct IxdtfParser IxdtfParser; - - - - -#endif // IxdtfParser_D_H diff --git a/ffi/capi/bindings/c/IxdtfParser.h b/ffi/capi/bindings/c/IxdtfParser.h deleted file mode 100644 index eea8ec0afe5..00000000000 --- a/ffi/capi/bindings/c/IxdtfParser.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef IxdtfParser_H -#define IxdtfParser_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Calendar.d.h" -#include "CalendarParseError.d.h" -#include "DataError.d.h" -#include "DataProvider.d.h" -#include "ZonedDateTime.d.h" -#include "ZonedIsoDateTime.d.h" - -#include "IxdtfParser.d.h" - - - - - - -IxdtfParser* icu4x_IxdtfParser_create_mv1(void); - -typedef struct icu4x_IxdtfParser_create_with_provider_mv1_result {union {IxdtfParser* ok; DataError err;}; bool is_ok;} icu4x_IxdtfParser_create_with_provider_mv1_result; -icu4x_IxdtfParser_create_with_provider_mv1_result icu4x_IxdtfParser_create_with_provider_mv1(const DataProvider* provider); - -typedef struct icu4x_IxdtfParser_try_iso_from_str_mv1_result {union {ZonedIsoDateTime ok; CalendarParseError err;}; bool is_ok;} icu4x_IxdtfParser_try_iso_from_str_mv1_result; -icu4x_IxdtfParser_try_iso_from_str_mv1_result icu4x_IxdtfParser_try_iso_from_str_mv1(const IxdtfParser* self, DiplomatStringView v); - -typedef struct icu4x_IxdtfParser_try_from_str_mv1_result {union {ZonedDateTime ok; CalendarParseError err;}; bool is_ok;} icu4x_IxdtfParser_try_from_str_mv1_result; -icu4x_IxdtfParser_try_from_str_mv1_result icu4x_IxdtfParser_try_from_str_mv1(const IxdtfParser* self, DiplomatStringView v, const Calendar* calendar); - - -void icu4x_IxdtfParser_destroy_mv1(IxdtfParser* self); - - - - - -#endif // IxdtfParser_H diff --git a/ffi/capi/bindings/c/ZonedDateTimeParser.d.h b/ffi/capi/bindings/c/ZonedDateTimeParser.d.h new file mode 100644 index 00000000000..ed15fe607f1 --- /dev/null +++ b/ffi/capi/bindings/c/ZonedDateTimeParser.d.h @@ -0,0 +1,19 @@ +#ifndef ZonedDateTimeParser_D_H +#define ZonedDateTimeParser_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + + + + +typedef struct ZonedDateTimeParser ZonedDateTimeParser; + + + + +#endif // ZonedDateTimeParser_D_H diff --git a/ffi/capi/bindings/c/ZonedDateTimeParser.h b/ffi/capi/bindings/c/ZonedDateTimeParser.h new file mode 100644 index 00000000000..0f14727fc38 --- /dev/null +++ b/ffi/capi/bindings/c/ZonedDateTimeParser.h @@ -0,0 +1,42 @@ +#ifndef ZonedDateTimeParser_H +#define ZonedDateTimeParser_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#include "Calendar.d.h" +#include "CalendarParseError.d.h" +#include "DataError.d.h" +#include "DataProvider.d.h" +#include "ZonedDateTime.d.h" +#include "ZonedIsoDateTime.d.h" + +#include "ZonedDateTimeParser.d.h" + + + + + + +ZonedDateTimeParser* icu4x_ZonedDateTimeParser_create_mv1(void); + +typedef struct icu4x_ZonedDateTimeParser_create_with_provider_mv1_result {union {ZonedDateTimeParser* ok; DataError err;}; bool is_ok;} icu4x_ZonedDateTimeParser_create_with_provider_mv1_result; +icu4x_ZonedDateTimeParser_create_with_provider_mv1_result icu4x_ZonedDateTimeParser_create_with_provider_mv1(const DataProvider* provider); + +typedef struct icu4x_ZonedDateTimeParser_try_iso_from_str_mv1_result {union {ZonedIsoDateTime ok; CalendarParseError err;}; bool is_ok;} icu4x_ZonedDateTimeParser_try_iso_from_str_mv1_result; +icu4x_ZonedDateTimeParser_try_iso_from_str_mv1_result icu4x_ZonedDateTimeParser_try_iso_from_str_mv1(const ZonedDateTimeParser* self, DiplomatStringView v); + +typedef struct icu4x_ZonedDateTimeParser_try_from_str_mv1_result {union {ZonedDateTime ok; CalendarParseError err;}; bool is_ok;} icu4x_ZonedDateTimeParser_try_from_str_mv1_result; +icu4x_ZonedDateTimeParser_try_from_str_mv1_result icu4x_ZonedDateTimeParser_try_from_str_mv1(const ZonedDateTimeParser* self, DiplomatStringView v, const Calendar* calendar); + + +void icu4x_ZonedDateTimeParser_destroy_mv1(ZonedDateTimeParser* self); + + + + + +#endif // ZonedDateTimeParser_H diff --git a/ffi/capi/bindings/cpp/icu4x/IxdtfParser.d.hpp b/ffi/capi/bindings/cpp/icu4x/IxdtfParser.d.hpp deleted file mode 100644 index 8db492fe88d..00000000000 --- a/ffi/capi/bindings/cpp/icu4x/IxdtfParser.d.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef icu4x_IxdtfParser_D_HPP -#define icu4x_IxdtfParser_D_HPP - -#include -#include -#include -#include -#include -#include -#include "../diplomat_runtime.hpp" - -namespace icu4x { -namespace capi { struct Calendar; } -class Calendar; -namespace capi { struct DataProvider; } -class DataProvider; -namespace capi { struct IxdtfParser; } -class IxdtfParser; -struct ZonedDateTime; -struct ZonedIsoDateTime; -class CalendarParseError; -class DataError; -} - - -namespace icu4x { -namespace capi { - struct IxdtfParser; -} // namespace capi -} // namespace - -namespace icu4x { -class IxdtfParser { -public: - - inline static std::unique_ptr create(); - - inline static diplomat::result, icu4x::DataError> create_with_provider(const icu4x::DataProvider& provider); - - inline diplomat::result try_iso_from_str(std::string_view v) const; - - inline diplomat::result try_from_str(std::string_view v, const icu4x::Calendar& calendar) const; - - inline const icu4x::capi::IxdtfParser* AsFFI() const; - inline icu4x::capi::IxdtfParser* AsFFI(); - inline static const icu4x::IxdtfParser* FromFFI(const icu4x::capi::IxdtfParser* ptr); - inline static icu4x::IxdtfParser* FromFFI(icu4x::capi::IxdtfParser* ptr); - inline static void operator delete(void* ptr); -private: - IxdtfParser() = delete; - IxdtfParser(const icu4x::IxdtfParser&) = delete; - IxdtfParser(icu4x::IxdtfParser&&) noexcept = delete; - IxdtfParser operator=(const icu4x::IxdtfParser&) = delete; - IxdtfParser operator=(icu4x::IxdtfParser&&) noexcept = delete; - static void operator delete[](void*, size_t) = delete; -}; - -} // namespace -#endif // icu4x_IxdtfParser_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/IxdtfParser.hpp b/ffi/capi/bindings/cpp/icu4x/IxdtfParser.hpp deleted file mode 100644 index 0f7d78da733..00000000000 --- a/ffi/capi/bindings/cpp/icu4x/IxdtfParser.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef icu4x_IxdtfParser_HPP -#define icu4x_IxdtfParser_HPP - -#include "IxdtfParser.d.hpp" - -#include -#include -#include -#include -#include -#include -#include "../diplomat_runtime.hpp" -#include "Calendar.hpp" -#include "CalendarParseError.hpp" -#include "DataError.hpp" -#include "DataProvider.hpp" -#include "ZonedDateTime.hpp" -#include "ZonedIsoDateTime.hpp" - - -namespace icu4x { -namespace capi { - extern "C" { - - icu4x::capi::IxdtfParser* icu4x_IxdtfParser_create_mv1(void); - - typedef struct icu4x_IxdtfParser_create_with_provider_mv1_result {union {icu4x::capi::IxdtfParser* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_IxdtfParser_create_with_provider_mv1_result; - icu4x_IxdtfParser_create_with_provider_mv1_result icu4x_IxdtfParser_create_with_provider_mv1(const icu4x::capi::DataProvider* provider); - - typedef struct icu4x_IxdtfParser_try_iso_from_str_mv1_result {union {icu4x::capi::ZonedIsoDateTime ok; icu4x::capi::CalendarParseError err;}; bool is_ok;} icu4x_IxdtfParser_try_iso_from_str_mv1_result; - icu4x_IxdtfParser_try_iso_from_str_mv1_result icu4x_IxdtfParser_try_iso_from_str_mv1(const icu4x::capi::IxdtfParser* self, diplomat::capi::DiplomatStringView v); - - typedef struct icu4x_IxdtfParser_try_from_str_mv1_result {union {icu4x::capi::ZonedDateTime ok; icu4x::capi::CalendarParseError err;}; bool is_ok;} icu4x_IxdtfParser_try_from_str_mv1_result; - icu4x_IxdtfParser_try_from_str_mv1_result icu4x_IxdtfParser_try_from_str_mv1(const icu4x::capi::IxdtfParser* self, diplomat::capi::DiplomatStringView v, const icu4x::capi::Calendar* calendar); - - - void icu4x_IxdtfParser_destroy_mv1(IxdtfParser* self); - - } // extern "C" -} // namespace capi -} // namespace - -inline std::unique_ptr icu4x::IxdtfParser::create() { - auto result = icu4x::capi::icu4x_IxdtfParser_create_mv1(); - return std::unique_ptr(icu4x::IxdtfParser::FromFFI(result)); -} - -inline diplomat::result, icu4x::DataError> icu4x::IxdtfParser::create_with_provider(const icu4x::DataProvider& provider) { - auto result = icu4x::capi::icu4x_IxdtfParser_create_with_provider_mv1(provider.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::DataError>(diplomat::Ok>(std::unique_ptr(icu4x::IxdtfParser::FromFFI(result.ok)))) : diplomat::result, icu4x::DataError>(diplomat::Err(icu4x::DataError::FromFFI(result.err))); -} - -inline diplomat::result icu4x::IxdtfParser::try_iso_from_str(std::string_view v) const { - auto result = icu4x::capi::icu4x_IxdtfParser_try_iso_from_str_mv1(this->AsFFI(), - {v.data(), v.size()}); - return result.is_ok ? diplomat::result(diplomat::Ok(icu4x::ZonedIsoDateTime::FromFFI(result.ok))) : diplomat::result(diplomat::Err(icu4x::CalendarParseError::FromFFI(result.err))); -} - -inline diplomat::result icu4x::IxdtfParser::try_from_str(std::string_view v, const icu4x::Calendar& calendar) const { - auto result = icu4x::capi::icu4x_IxdtfParser_try_from_str_mv1(this->AsFFI(), - {v.data(), v.size()}, - calendar.AsFFI()); - return result.is_ok ? diplomat::result(diplomat::Ok(icu4x::ZonedDateTime::FromFFI(result.ok))) : diplomat::result(diplomat::Err(icu4x::CalendarParseError::FromFFI(result.err))); -} - -inline const icu4x::capi::IxdtfParser* icu4x::IxdtfParser::AsFFI() const { - return reinterpret_cast(this); -} - -inline icu4x::capi::IxdtfParser* icu4x::IxdtfParser::AsFFI() { - return reinterpret_cast(this); -} - -inline const icu4x::IxdtfParser* icu4x::IxdtfParser::FromFFI(const icu4x::capi::IxdtfParser* ptr) { - return reinterpret_cast(ptr); -} - -inline icu4x::IxdtfParser* icu4x::IxdtfParser::FromFFI(icu4x::capi::IxdtfParser* ptr) { - return reinterpret_cast(ptr); -} - -inline void icu4x::IxdtfParser::operator delete(void* ptr) { - icu4x::capi::icu4x_IxdtfParser_destroy_mv1(reinterpret_cast(ptr)); -} - - -#endif // icu4x_IxdtfParser_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.d.hpp b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.d.hpp new file mode 100644 index 00000000000..647ca0a2ac7 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.d.hpp @@ -0,0 +1,59 @@ +#ifndef icu4x_ZonedDateTimeParser_D_HPP +#define icu4x_ZonedDateTimeParser_D_HPP + +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + +namespace icu4x { +namespace capi { struct Calendar; } +class Calendar; +namespace capi { struct DataProvider; } +class DataProvider; +namespace capi { struct ZonedDateTimeParser; } +class ZonedDateTimeParser; +struct ZonedDateTime; +struct ZonedIsoDateTime; +class CalendarParseError; +class DataError; +} + + +namespace icu4x { +namespace capi { + struct ZonedDateTimeParser; +} // namespace capi +} // namespace + +namespace icu4x { +class ZonedDateTimeParser { +public: + + inline static std::unique_ptr create(); + + inline static diplomat::result, icu4x::DataError> create_with_provider(const icu4x::DataProvider& provider); + + inline diplomat::result try_iso_from_str(std::string_view v) const; + + inline diplomat::result try_from_str(std::string_view v, const icu4x::Calendar& calendar) const; + + inline const icu4x::capi::ZonedDateTimeParser* AsFFI() const; + inline icu4x::capi::ZonedDateTimeParser* AsFFI(); + inline static const icu4x::ZonedDateTimeParser* FromFFI(const icu4x::capi::ZonedDateTimeParser* ptr); + inline static icu4x::ZonedDateTimeParser* FromFFI(icu4x::capi::ZonedDateTimeParser* ptr); + inline static void operator delete(void* ptr); +private: + ZonedDateTimeParser() = delete; + ZonedDateTimeParser(const icu4x::ZonedDateTimeParser&) = delete; + ZonedDateTimeParser(icu4x::ZonedDateTimeParser&&) noexcept = delete; + ZonedDateTimeParser operator=(const icu4x::ZonedDateTimeParser&) = delete; + ZonedDateTimeParser operator=(icu4x::ZonedDateTimeParser&&) noexcept = delete; + static void operator delete[](void*, size_t) = delete; +}; + +} // namespace +#endif // icu4x_ZonedDateTimeParser_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.hpp b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.hpp new file mode 100644 index 00000000000..8aacda4a253 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeParser.hpp @@ -0,0 +1,87 @@ +#ifndef icu4x_ZonedDateTimeParser_HPP +#define icu4x_ZonedDateTimeParser_HPP + +#include "ZonedDateTimeParser.d.hpp" + +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" +#include "Calendar.hpp" +#include "CalendarParseError.hpp" +#include "DataError.hpp" +#include "DataProvider.hpp" +#include "ZonedDateTime.hpp" +#include "ZonedIsoDateTime.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + icu4x::capi::ZonedDateTimeParser* icu4x_ZonedDateTimeParser_create_mv1(void); + + typedef struct icu4x_ZonedDateTimeParser_create_with_provider_mv1_result {union {icu4x::capi::ZonedDateTimeParser* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_ZonedDateTimeParser_create_with_provider_mv1_result; + icu4x_ZonedDateTimeParser_create_with_provider_mv1_result icu4x_ZonedDateTimeParser_create_with_provider_mv1(const icu4x::capi::DataProvider* provider); + + typedef struct icu4x_ZonedDateTimeParser_try_iso_from_str_mv1_result {union {icu4x::capi::ZonedIsoDateTime ok; icu4x::capi::CalendarParseError err;}; bool is_ok;} icu4x_ZonedDateTimeParser_try_iso_from_str_mv1_result; + icu4x_ZonedDateTimeParser_try_iso_from_str_mv1_result icu4x_ZonedDateTimeParser_try_iso_from_str_mv1(const icu4x::capi::ZonedDateTimeParser* self, diplomat::capi::DiplomatStringView v); + + typedef struct icu4x_ZonedDateTimeParser_try_from_str_mv1_result {union {icu4x::capi::ZonedDateTime ok; icu4x::capi::CalendarParseError err;}; bool is_ok;} icu4x_ZonedDateTimeParser_try_from_str_mv1_result; + icu4x_ZonedDateTimeParser_try_from_str_mv1_result icu4x_ZonedDateTimeParser_try_from_str_mv1(const icu4x::capi::ZonedDateTimeParser* self, diplomat::capi::DiplomatStringView v, const icu4x::capi::Calendar* calendar); + + + void icu4x_ZonedDateTimeParser_destroy_mv1(ZonedDateTimeParser* self); + + } // extern "C" +} // namespace capi +} // namespace + +inline std::unique_ptr icu4x::ZonedDateTimeParser::create() { + auto result = icu4x::capi::icu4x_ZonedDateTimeParser_create_mv1(); + return std::unique_ptr(icu4x::ZonedDateTimeParser::FromFFI(result)); +} + +inline diplomat::result, icu4x::DataError> icu4x::ZonedDateTimeParser::create_with_provider(const icu4x::DataProvider& provider) { + auto result = icu4x::capi::icu4x_ZonedDateTimeParser_create_with_provider_mv1(provider.AsFFI()); + return result.is_ok ? diplomat::result, icu4x::DataError>(diplomat::Ok>(std::unique_ptr(icu4x::ZonedDateTimeParser::FromFFI(result.ok)))) : diplomat::result, icu4x::DataError>(diplomat::Err(icu4x::DataError::FromFFI(result.err))); +} + +inline diplomat::result icu4x::ZonedDateTimeParser::try_iso_from_str(std::string_view v) const { + auto result = icu4x::capi::icu4x_ZonedDateTimeParser_try_iso_from_str_mv1(this->AsFFI(), + {v.data(), v.size()}); + return result.is_ok ? diplomat::result(diplomat::Ok(icu4x::ZonedIsoDateTime::FromFFI(result.ok))) : diplomat::result(diplomat::Err(icu4x::CalendarParseError::FromFFI(result.err))); +} + +inline diplomat::result icu4x::ZonedDateTimeParser::try_from_str(std::string_view v, const icu4x::Calendar& calendar) const { + auto result = icu4x::capi::icu4x_ZonedDateTimeParser_try_from_str_mv1(this->AsFFI(), + {v.data(), v.size()}, + calendar.AsFFI()); + return result.is_ok ? diplomat::result(diplomat::Ok(icu4x::ZonedDateTime::FromFFI(result.ok))) : diplomat::result(diplomat::Err(icu4x::CalendarParseError::FromFFI(result.err))); +} + +inline const icu4x::capi::ZonedDateTimeParser* icu4x::ZonedDateTimeParser::AsFFI() const { + return reinterpret_cast(this); +} + +inline icu4x::capi::ZonedDateTimeParser* icu4x::ZonedDateTimeParser::AsFFI() { + return reinterpret_cast(this); +} + +inline const icu4x::ZonedDateTimeParser* icu4x::ZonedDateTimeParser::FromFFI(const icu4x::capi::ZonedDateTimeParser* ptr) { + return reinterpret_cast(ptr); +} + +inline icu4x::ZonedDateTimeParser* icu4x::ZonedDateTimeParser::FromFFI(icu4x::capi::ZonedDateTimeParser* ptr) { + return reinterpret_cast(ptr); +} + +inline void icu4x::ZonedDateTimeParser::operator delete(void* ptr) { + icu4x::capi::icu4x_ZonedDateTimeParser_destroy_mv1(reinterpret_cast(ptr)); +} + + +#endif // icu4x_ZonedDateTimeParser_HPP diff --git a/ffi/capi/bindings/dart/IxdtfParser.g.dart b/ffi/capi/bindings/dart/ZonedDateTimeParser.g.dart similarity index 53% rename from ffi/capi/bindings/dart/IxdtfParser.g.dart rename to ffi/capi/bindings/dart/ZonedDateTimeParser.g.dart index 56cc43531d0..dc05459d3da 100644 --- a/ffi/capi/bindings/dart/IxdtfParser.g.dart +++ b/ffi/capi/bindings/dart/ZonedDateTimeParser.g.dart @@ -2,8 +2,8 @@ part of 'lib.g.dart'; -/// See the [Rust documentation for `IxdtfParser`](https://docs.rs/icu/latest/icu/timezone/struct.IxdtfParser.html) for more information. -final class IxdtfParser implements ffi.Finalizable { +/// See the [Rust documentation for `ZonedDateTimeParser`](https://docs.rs/icu/latest/icu/timezone/struct.ZonedDateTimeParser.html) for more information. +final class ZonedDateTimeParser implements ffi.Finalizable { final ffi.Pointer _ffi; // These are "used" in the sense that they keep dependencies alive @@ -14,43 +14,43 @@ final class IxdtfParser implements ffi.Finalizable { // corresponding to data this may borrow from. These should be flat arrays containing // references to objects, and this object will hold on to them to keep them alive and // maintain borrow validity. - IxdtfParser._fromFfi(this._ffi, this._selfEdge) { + ZonedDateTimeParser._fromFfi(this._ffi, this._selfEdge) { if (_selfEdge.isEmpty) { _finalizer.attach(this, _ffi.cast()); } } - static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_icu4x_IxdtfParser_destroy_mv1)); + static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_icu4x_ZonedDateTimeParser_destroy_mv1)); - /// Construct a new [`IxdtfParser`] instance using compiled data. + /// Construct a new [`ZonedDateTimeParser`] instance using compiled data. /// - /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.IxdtfParser.html#method.new) for more information. - factory IxdtfParser() { - final result = _icu4x_IxdtfParser_create_mv1(); - return IxdtfParser._fromFfi(result, []); + /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.ZonedDateTimeParser.html#method.new) for more information. + factory ZonedDateTimeParser() { + final result = _icu4x_ZonedDateTimeParser_create_mv1(); + return ZonedDateTimeParser._fromFfi(result, []); } - /// Construct a new [`IxdtfParser`] instance using a particular data source. + /// Construct a new [`ZonedDateTimeParser`] instance using a particular data source. /// - /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.IxdtfParser.html#method.new) for more information. + /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.ZonedDateTimeParser.html#method.new) for more information. /// /// Throws [DataError] on failure. - factory IxdtfParser.withProvider(DataProvider provider) { - final result = _icu4x_IxdtfParser_create_with_provider_mv1(provider._ffi); + factory ZonedDateTimeParser.withProvider(DataProvider provider) { + final result = _icu4x_ZonedDateTimeParser_create_with_provider_mv1(provider._ffi); if (!result.isOk) { throw DataError.values[result.union.err]; } - return IxdtfParser._fromFfi(result.union.ok, []); + return ZonedDateTimeParser._fromFfi(result.union.ok, []); } /// Creates a new [`ZonedIsoDateTime`] from an IXDTF string. /// - /// See the [Rust documentation for `try_from_str`](https://docs.rs/icu/latest/icu/timezone/struct.IxdtfParser.html#method.try_from_str) for more information. + /// See the [Rust documentation for `try_from_str`](https://docs.rs/icu/latest/icu/timezone/struct.ZonedDateTimeParser.html#method.try_from_str) for more information. /// /// Throws [CalendarParseError] on failure. ZonedIsoDateTime tryIsoFromStr(String v) { final temp = _FinalizedArena(); - final result = _icu4x_IxdtfParser_try_iso_from_str_mv1(_ffi, v._utf8AllocIn(temp.arena)); + final result = _icu4x_ZonedDateTimeParser_try_iso_from_str_mv1(_ffi, v._utf8AllocIn(temp.arena)); if (!result.isOk) { throw CalendarParseError.values[result.union.err]; } @@ -64,7 +64,7 @@ final class IxdtfParser implements ffi.Finalizable { /// Throws [CalendarParseError] on failure. ZonedDateTime tryFromStr(String v, Calendar calendar) { final temp = _FinalizedArena(); - final result = _icu4x_IxdtfParser_try_from_str_mv1(_ffi, v._utf8AllocIn(temp.arena), calendar._ffi); + final result = _icu4x_ZonedDateTimeParser_try_from_str_mv1(_ffi, v._utf8AllocIn(temp.arena), calendar._ffi); if (!result.isOk) { throw CalendarParseError.values[result.union.err]; } @@ -73,26 +73,26 @@ final class IxdtfParser implements ffi.Finalizable { } @meta.RecordUse() -@ffi.Native)>(isLeaf: true, symbol: 'icu4x_IxdtfParser_destroy_mv1') +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_ZonedDateTimeParser_destroy_mv1') // ignore: non_constant_identifier_names -external void _icu4x_IxdtfParser_destroy_mv1(ffi.Pointer self); +external void _icu4x_ZonedDateTimeParser_destroy_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native Function()>(isLeaf: true, symbol: 'icu4x_IxdtfParser_create_mv1') +@ffi.Native Function()>(isLeaf: true, symbol: 'icu4x_ZonedDateTimeParser_create_mv1') // ignore: non_constant_identifier_names -external ffi.Pointer _icu4x_IxdtfParser_create_mv1(); +external ffi.Pointer _icu4x_ZonedDateTimeParser_create_mv1(); @meta.RecordUse() -@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_IxdtfParser_create_with_provider_mv1') +@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_ZonedDateTimeParser_create_with_provider_mv1') // ignore: non_constant_identifier_names -external _ResultOpaqueInt32 _icu4x_IxdtfParser_create_with_provider_mv1(ffi.Pointer provider); +external _ResultOpaqueInt32 _icu4x_ZonedDateTimeParser_create_with_provider_mv1(ffi.Pointer provider); @meta.RecordUse() -@ffi.Native<_ResultZonedIsoDateTimeFfiInt32 Function(ffi.Pointer, _SliceUtf8)>(isLeaf: true, symbol: 'icu4x_IxdtfParser_try_iso_from_str_mv1') +@ffi.Native<_ResultZonedIsoDateTimeFfiInt32 Function(ffi.Pointer, _SliceUtf8)>(isLeaf: true, symbol: 'icu4x_ZonedDateTimeParser_try_iso_from_str_mv1') // ignore: non_constant_identifier_names -external _ResultZonedIsoDateTimeFfiInt32 _icu4x_IxdtfParser_try_iso_from_str_mv1(ffi.Pointer self, _SliceUtf8 v); +external _ResultZonedIsoDateTimeFfiInt32 _icu4x_ZonedDateTimeParser_try_iso_from_str_mv1(ffi.Pointer self, _SliceUtf8 v); @meta.RecordUse() -@ffi.Native<_ResultZonedDateTimeFfiInt32 Function(ffi.Pointer, _SliceUtf8, ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_IxdtfParser_try_from_str_mv1') +@ffi.Native<_ResultZonedDateTimeFfiInt32 Function(ffi.Pointer, _SliceUtf8, ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_ZonedDateTimeParser_try_from_str_mv1') // ignore: non_constant_identifier_names -external _ResultZonedDateTimeFfiInt32 _icu4x_IxdtfParser_try_from_str_mv1(ffi.Pointer self, _SliceUtf8 v, ffi.Pointer calendar); +external _ResultZonedDateTimeFfiInt32 _icu4x_ZonedDateTimeParser_try_from_str_mv1(ffi.Pointer self, _SliceUtf8 v, ffi.Pointer calendar); diff --git a/ffi/capi/bindings/dart/lib.g.dart b/ffi/capi/bindings/dart/lib.g.dart index 14cdc6a6e1e..dc0e952d283 100644 --- a/ffi/capi/bindings/dart/lib.g.dart +++ b/ffi/capi/bindings/dart/lib.g.dart @@ -83,7 +83,6 @@ part 'IndicSyllabicCategory.g.dart'; part 'IsoDate.g.dart'; part 'IsoDateTime.g.dart'; part 'IsoWeekday.g.dart'; -part 'IxdtfParser.g.dart'; part 'JoiningType.g.dart'; part 'LanguageDisplay.g.dart'; part 'LeadingAdjustment.g.dart'; @@ -153,6 +152,7 @@ part 'WordBreakIteratorUtf8.g.dart'; part 'WordSegmenter.g.dart'; part 'ZonedDateTime.g.dart'; part 'ZonedDateTimeFormatter.g.dart'; +part 'ZonedDateTimeParser.g.dart'; part 'ZonedIsoDateTime.g.dart'; /// A [Rune] is a Unicode code point, such as `a`, or `💡`. diff --git a/ffi/capi/bindings/js/IxdtfParser.d.ts b/ffi/capi/bindings/js/ZonedDateTimeParser.d.ts similarity index 67% rename from ffi/capi/bindings/js/IxdtfParser.d.ts rename to ffi/capi/bindings/js/ZonedDateTimeParser.d.ts index 6649a07e426..5217a6ae36a 100644 --- a/ffi/capi/bindings/js/IxdtfParser.d.ts +++ b/ffi/capi/bindings/js/ZonedDateTimeParser.d.ts @@ -8,15 +8,15 @@ import type { ZonedIsoDateTime } from "./ZonedIsoDateTime" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; -/** See the [Rust documentation for `IxdtfParser`](https://docs.rs/icu/latest/icu/timezone/struct.IxdtfParser.html) for more information. +/** See the [Rust documentation for `ZonedDateTimeParser`](https://docs.rs/icu/latest/icu/timezone/struct.ZonedDateTimeParser.html) for more information. */ -export class IxdtfParser { +export class ZonedDateTimeParser { get ffiValue(): pointer; - static createWithProvider(provider: DataProvider): IxdtfParser; + static createWithProvider(provider: DataProvider): ZonedDateTimeParser; tryIsoFromStr(v: string): ZonedIsoDateTime; diff --git a/ffi/capi/bindings/js/IxdtfParser.mjs b/ffi/capi/bindings/js/ZonedDateTimeParser.mjs similarity index 75% rename from ffi/capi/bindings/js/IxdtfParser.mjs rename to ffi/capi/bindings/js/ZonedDateTimeParser.mjs index 4eb3fca7a64..e31a80f8b1f 100644 --- a/ffi/capi/bindings/js/IxdtfParser.mjs +++ b/ffi/capi/bindings/js/ZonedDateTimeParser.mjs @@ -9,13 +9,13 @@ import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; -/** See the [Rust documentation for `IxdtfParser`](https://docs.rs/icu/latest/icu/timezone/struct.IxdtfParser.html) for more information. +/** See the [Rust documentation for `ZonedDateTimeParser`](https://docs.rs/icu/latest/icu/timezone/struct.ZonedDateTimeParser.html) for more information. */ -const IxdtfParser_box_destroy_registry = new FinalizationRegistry((ptr) => { - wasm.icu4x_IxdtfParser_destroy_mv1(ptr); +const ZonedDateTimeParser_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.icu4x_ZonedDateTimeParser_destroy_mv1(ptr); }); -export class IxdtfParser { +export class ZonedDateTimeParser { // Internal ptr reference: #ptr = null; @@ -26,7 +26,7 @@ export class IxdtfParser { #internalConstructor(symbol, ptr, selfEdge) { if (symbol !== diplomatRuntime.internalConstructor) { - console.error("IxdtfParser is an Opaque type. You cannot call its constructor."); + console.error("ZonedDateTimeParser is an Opaque type. You cannot call its constructor."); return; } @@ -35,7 +35,7 @@ export class IxdtfParser { // Are we being borrowed? If not, we can register. if (this.#selfEdge.length === 0) { - IxdtfParser_box_destroy_registry.register(this, this.#ptr); + ZonedDateTimeParser_box_destroy_registry.register(this, this.#ptr); } return this; @@ -45,10 +45,10 @@ export class IxdtfParser { } #defaultConstructor() { - const result = wasm.icu4x_IxdtfParser_create_mv1(); + const result = wasm.icu4x_ZonedDateTimeParser_create_mv1(); try { - return new IxdtfParser(diplomatRuntime.internalConstructor, result, []); + return new ZonedDateTimeParser(diplomatRuntime.internalConstructor, result, []); } finally {} @@ -57,14 +57,14 @@ export class IxdtfParser { static createWithProvider(provider) { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_IxdtfParser_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); + const result = wasm.icu4x_ZonedDateTimeParser_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); try { if (!diplomatReceive.resultFlag) { const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } - return new IxdtfParser(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); + return new ZonedDateTimeParser(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } finally { @@ -79,7 +79,7 @@ export class IxdtfParser { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 13, 4, true); - const result = wasm.icu4x_IxdtfParser_try_iso_from_str_mv1(diplomatReceive.buffer, this.ffiValue, ...vSlice.splat()); + const result = wasm.icu4x_ZonedDateTimeParser_try_iso_from_str_mv1(diplomatReceive.buffer, this.ffiValue, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { @@ -103,7 +103,7 @@ export class IxdtfParser { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 13, 4, true); - const result = wasm.icu4x_IxdtfParser_try_from_str_mv1(diplomatReceive.buffer, this.ffiValue, ...vSlice.splat(), calendar.ffiValue); + const result = wasm.icu4x_ZonedDateTimeParser_try_from_str_mv1(diplomatReceive.buffer, this.ffiValue, ...vSlice.splat(), calendar.ffiValue); try { if (!diplomatReceive.resultFlag) { diff --git a/ffi/capi/bindings/js/index.d.ts b/ffi/capi/bindings/js/index.d.ts index a8de5e9cfc8..7eca3d7037d 100644 --- a/ffi/capi/bindings/js/index.d.ts +++ b/ffi/capi/bindings/js/index.d.ts @@ -186,7 +186,7 @@ export { UnitsConverterFactory } from "./UnitsConverterFactory" export { WeekCalculator } from "./WeekCalculator" -export { IxdtfParser } from "./IxdtfParser" +export { ZonedDateTimeParser } from "./ZonedDateTimeParser" export { GregorianZonedDateTimeFormatter } from "./GregorianZonedDateTimeFormatter" diff --git a/ffi/capi/bindings/js/index.mjs b/ffi/capi/bindings/js/index.mjs index ed59d1a22f0..2014d72a028 100644 --- a/ffi/capi/bindings/js/index.mjs +++ b/ffi/capi/bindings/js/index.mjs @@ -184,7 +184,7 @@ export { UnitsConverterFactory } from "./UnitsConverterFactory.mjs" export { WeekCalculator } from "./WeekCalculator.mjs" -export { IxdtfParser } from "./IxdtfParser.mjs" +export { ZonedDateTimeParser } from "./ZonedDateTimeParser.mjs" export { GregorianZonedDateTimeFormatter } from "./GregorianZonedDateTimeFormatter.mjs" diff --git a/ffi/capi/src/zoned_datetime.rs b/ffi/capi/src/zoned_datetime.rs index f467e5b43f2..6aad97c3607 100644 --- a/ffi/capi/src/zoned_datetime.rs +++ b/ffi/capi/src/zoned_datetime.rs @@ -19,27 +19,27 @@ pub mod ffi { use crate::time::ffi::Time; use crate::timezone::ffi::TimeZoneInfo; - #[diplomat::rust_link(icu::timezone::IxdtfParser, Struct)] + #[diplomat::rust_link(icu::timezone::ZonedDateTimeParser, Struct)] #[diplomat::opaque] - pub struct IxdtfParser(icu_timezone::IxdtfParser); + pub struct ZonedDateTimeParser(icu_timezone::ZonedDateTimeParser); - impl IxdtfParser { - /// Construct a new [`IxdtfParser`] instance using compiled data. - #[diplomat::rust_link(icu::timezone::IxdtfParser::new, FnInStruct)] + impl ZonedDateTimeParser { + /// Construct a new [`ZonedDateTimeParser`] instance using compiled data. + #[diplomat::rust_link(icu::timezone::ZonedDateTimeParser::new, FnInStruct)] #[diplomat::attr(auto, constructor)] #[cfg(feature = "compiled_data")] - pub fn create() -> Box { - Box::new(IxdtfParser(icu_timezone::IxdtfParser::new())) + pub fn create() -> Box { + Box::new(ZonedDateTimeParser(icu_timezone::ZonedDateTimeParser::new())) } - /// Construct a new [`IxdtfParser`] instance using a particular data source. - #[diplomat::rust_link(icu::timezone::IxdtfParser::new, FnInStruct)] + /// Construct a new [`ZonedDateTimeParser`] instance using a particular data source. + #[diplomat::rust_link(icu::timezone::ZonedDateTimeParser::new, FnInStruct)] #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "with_provider")] #[cfg(feature = "buffer_provider")] pub fn create_with_provider( provider: &DataProvider, - ) -> Result, DataError> { - Ok(Box::new(IxdtfParser( - icu_timezone::IxdtfParser::try_new_with_buffer_provider(provider.get()?)?, + ) -> Result, DataError> { + Ok(Box::new(ZonedDateTimeParser( + icu_timezone::ZonedDateTimeParser::try_new_with_buffer_provider(provider.get()?)?, ))) } } @@ -53,16 +53,21 @@ pub mod ffi { pub zone: Box, } - impl IxdtfParser { + impl ZonedDateTimeParser { /// Creates a new [`ZonedIsoDateTime`] from an IXDTF string. - #[diplomat::rust_link(icu::timezone::IxdtfParser::try_from_str, FnInStruct)] - #[diplomat::rust_link(icu::timezone::IxdtfParser::try_from_utf8, FnInStruct, hidden)] - #[diplomat::rust_link(icu::timezone::IxdtfParser::from_str, FnInStruct, hidden)] + #[diplomat::rust_link(icu::timezone::ZonedDateTimeParser::try_from_str, FnInStruct)] + #[diplomat::rust_link( + icu::timezone::ZonedDateTimeParser::try_from_utf8, + FnInStruct, + hidden + )] + #[diplomat::rust_link(icu::timezone::ZonedDateTimeParser::from_str, FnInStruct, hidden)] pub fn try_iso_from_str( &self, v: &DiplomatStr, ) -> Result { - let icu_timezone::ZonedDateTime { date, time, zone } = self.0.try_from_utf8(v, Iso)?; + let icu_timezone::ZonedDateTime { date, time, zone } = + self.0.parse_from_utf8(v, Iso)?; Ok(ZonedIsoDateTime { date: Box::new(IsoDate(date)), time: Box::new(Time(time)), @@ -80,7 +85,7 @@ pub mod ffi { pub zone: Box, } - impl IxdtfParser { + impl ZonedDateTimeParser { /// Creates a new [`ZonedDateTime`] from an IXDTF string. #[diplomat::rust_link(icu::timezone::DateTime::try_from_str, FnInStruct)] #[diplomat::rust_link(icu::timezone::DateTime::try_from_utf8, FnInStruct, hidden)] @@ -91,7 +96,7 @@ pub mod ffi { calendar: &Calendar, ) -> Result { let icu_timezone::ZonedDateTime { date, time, zone } = - self.0.try_from_utf8(v, calendar.0.clone())?; + self.0.parse_from_utf8(v, calendar.0.clone())?; Ok(ZonedDateTime { date: Box::new(Date(date)), time: Box::new(Time(time)), diff --git a/ffi/capi/tests/missing_apis.txt b/ffi/capi/tests/missing_apis.txt index 380a11a40ff..83ef42500a4 100644 --- a/ffi/capi/tests/missing_apis.txt +++ b/ffi/capi/tests/missing_apis.txt @@ -766,12 +766,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::IxdtfParser::try_location_only_from_str#FnInStruct -icu::timezone::IxdtfParser::try_location_only_from_utf8#FnInStruct -icu::timezone::IxdtfParser::try_loose_from_str#FnInStruct -icu::timezone::IxdtfParser::try_loose_from_utf8#FnInStruct -icu::timezone::IxdtfParser::try_offset_only_from_str#FnInStruct -icu::timezone::IxdtfParser::try_offset_only_from_utf8#FnInStruct icu::timezone::TimeZoneBcp47Id::into_option#FnInStruct icu::timezone::TimeZoneBcp47Iter#Struct icu::timezone::TimeZoneBcp47Iter::next#FnInStruct @@ -790,6 +784,14 @@ 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::ZonedDateTimeParser::parse#FnInStruct +icu::timezone::ZonedDateTimeParser::parse_from_utf8#FnInStruct +icu::timezone::ZonedDateTimeParser::parse_location_only#FnInStruct +icu::timezone::ZonedDateTimeParser::parse_location_only_from_utf8#FnInStruct +icu::timezone::ZonedDateTimeParser::parse_loose#FnInStruct +icu::timezone::ZonedDateTimeParser::parse_loose_from_utf8#FnInStruct +icu::timezone::ZonedDateTimeParser::parse_offset_only#FnInStruct +icu::timezone::ZonedDateTimeParser::parse_offset_only_from_utf8#FnInStruct icu::timezone::models::AtTime#Enum icu::timezone::models::Base#Enum icu::timezone::models::Full#Enum diff --git a/ffi/dart/test/icu_test.dart b/ffi/dart/test/icu_test.dart index 9dfd461f2c0..6b62cd43a27 100644 --- a/ffi/dart/test/icu_test.dart +++ b/ffi/dart/test/icu_test.dart @@ -57,7 +57,7 @@ void main() { test('DateTime formatting', () { final zonedDateTime = - IxdtfParser().tryIsoFromStr('2025-01-15T14:32:12.34+01[Europe/Zurich]'); + ZonedDateTimeParser().tryIsoFromStr('2025-01-15T14:32:12.34+01[Europe/Zurich]'); var locale = Locale.fromString('de');