Skip to content

Commit

Permalink
Make an IxdtfParser type (#5736)
Browse files Browse the repository at this point in the history
Based on #5735
  • Loading branch information
robertbastian authored Oct 29, 2024
1 parent b982957 commit 34807e6
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 256 deletions.
8 changes: 4 additions & 4 deletions components/datetime/src/combo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use icu_provider::marker::NeverMarker;
/// use icu::datetime::fieldset::{Combo, E, HM, L};
/// use icu::datetime::DateTimeFormatter;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let formatter = DateTimeFormatter::try_new(
Expand All @@ -28,7 +28,7 @@ use icu_provider::marker::NeverMarker;
/// )
/// .unwrap();
///
/// let zdt = CustomZonedDateTime::try_location_only_from_str(
/// let zdt = IxdtfParser::new().try_location_only_from_str(
/// "2024-10-18T15:44[America/Los_Angeles]",
/// )
/// .unwrap();
Expand All @@ -46,7 +46,7 @@ use icu_provider::marker::NeverMarker;
/// use icu::datetime::fieldset::{Combo, E, HM, L};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
Expand All @@ -55,7 +55,7 @@ use icu_provider::marker::NeverMarker;
/// )
/// .unwrap();
///
/// let zdt = CustomZonedDateTime::try_location_only_iso_from_str(
/// let zdt = IxdtfParser::new().try_location_only_iso_from_str(
/// "2024-10-18T15:44[America/Los_Angeles]",
/// )
/// .unwrap()
Expand Down
22 changes: 11 additions & 11 deletions components/datetime/src/fieldset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ macro_rules! impl_zone_marker {
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{CustomZonedDateTime, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::timezone::{TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
Expand Down Expand Up @@ -738,7 +738,7 @@ macro_rules! impl_zoneddatetime_marker {
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneInfo, CustomZonedDateTime};
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use icu::datetime::DateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
Expand All @@ -750,7 +750,7 @@ macro_rules! impl_zoneddatetime_marker {
/// )
/// .unwrap();
///
/// let mut dtz = CustomZonedDateTime::try_from_str("2024-05-17T15:47:50+01:00[Europe/London]").unwrap();
/// let mut dtz = IxdtfParser::new().try_from_str("2024-05-17T15:47:50+01:00[Europe/London]").unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dtz),
Expand All @@ -762,7 +762,7 @@ macro_rules! impl_zoneddatetime_marker {
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneInfo, CustomZonedDateTime};
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
Expand All @@ -775,7 +775,7 @@ macro_rules! impl_zoneddatetime_marker {
/// )
/// .unwrap();
///
/// let mut dtz = CustomZonedDateTime::try_from_str("2024-05-17T15:47:50+01:00[Europe/London]")
/// let mut dtz = IxdtfParser::new().try_from_str("2024-05-17T15:47:50+01:00[Europe/London]")
/// .unwrap()
/// .to_calendar(Gregorian);
///
Expand Down Expand Up @@ -981,7 +981,7 @@ impl_zone_marker!(
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{CustomZonedDateTime, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::timezone::{IxdtfParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::Z;
Expand Down Expand Up @@ -1056,7 +1056,7 @@ impl_zone_marker!(
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneInfo, CustomZonedDateTime};
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use icu::calendar::Gregorian;
/// use icu::datetime::DateTimeFormatter;
/// use icu::datetime::fieldset::MD;
Expand All @@ -1079,7 +1079,7 @@ impl_zone_marker!(
/// )
/// .unwrap();
///
/// let dtz = CustomZonedDateTime::try_from_str("2024-09-17T15:47:50-05:00[America/Chicago]").unwrap();
/// let dtz = IxdtfParser::new().try_from_str("2024-09-17T15:47:50-05:00[America/Chicago]").unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dtz),
Expand Down Expand Up @@ -1206,7 +1206,7 @@ impl_zone_marker!(
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{CustomZonedDateTime, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::timezone::{IxdtfParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::V;
Expand Down Expand Up @@ -1278,7 +1278,7 @@ impl_zone_marker!(
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneInfo, CustomZonedDateTime};
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use icu::calendar::Gregorian;
/// use icu::datetime::DateTimeFormatter;
/// use icu::datetime::fieldset::MD;
Expand All @@ -1301,7 +1301,7 @@ impl_zone_marker!(
/// )
/// .unwrap();
///
/// let dtz = CustomZonedDateTime::try_from_str("2024-09-17T15:47:50-05:00[America/Chicago]").unwrap();
/// let dtz = IxdtfParser::new().try_from_str("2024-09-17T15:47:50-05:00[America/Chicago]").unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dtz),
Expand Down
44 changes: 22 additions & 22 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ size_test!(
/// use icu::datetime::neo_pattern::DateTimePattern;
/// use icu::datetime::neo_skeleton::NeoSkeleton;
/// use icu::locale::locale;
/// use icu::timezone::{TimeZoneInfo, CustomZonedDateTime};
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use writeable::{Part, assert_try_writeable_parts_eq};
///
/// // Create an instance that can format all fields (NeoSkeleton):
Expand All @@ -340,7 +340,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 = CustomZonedDateTime::try_from_str("2023-11-20T11:35:03+00:00[Europe/London]").unwrap().to_calendar(Gregorian);
/// let mut dtz = IxdtfParser::new().try_from_str("2023-11-20T11:35:03+00:00[Europe/London]").unwrap().to_calendar(Gregorian);
///
/// // Missing data is filled in on a best-effort basis, and an error is signaled.
/// assert_try_writeable_parts_eq!(
Expand Down Expand Up @@ -967,15 +967,15 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// use icu::datetime::neo_skeleton::NeoTimeZoneSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str(
/// let mut zone_london_winter = IxdtfParser::new().try_from_str(
/// "2024-01-01T00:00:00+00:00[Europe/London]",
/// )
/// .unwrap()
/// .zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str(
/// let mut zone_london_summer = IxdtfParser::new().try_from_str(
/// "2024-07-01T00:00:00+01:00[Europe/London]",
/// )
/// .unwrap()
Expand Down Expand Up @@ -1070,10 +1070,10 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// use icu::datetime::neo_skeleton::NeoTimeZoneSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str(
/// let mut zone_london_winter = IxdtfParser::new().try_from_str(
/// "2024-01-01T00:00:00+00:00[Europe/London]",
/// )
/// .unwrap()
Expand Down Expand Up @@ -1137,15 +1137,15 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// use icu::datetime::neo_skeleton::NeoTimeZoneSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str(
/// let mut zone_london_winter = IxdtfParser::new().try_from_str(
/// "2024-01-01T00:00:00+00:00[Europe/London]",
/// )
/// .unwrap()
/// .zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str(
/// let mut zone_london_summer = IxdtfParser::new().try_from_str(
/// "2024-07-01T00:00:00+01:00[Europe/London]",
/// )
/// .unwrap()
Expand Down Expand Up @@ -1213,15 +1213,15 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// use icu::datetime::neo_skeleton::NeoTimeZoneSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str(
/// let mut zone_london_winter = IxdtfParser::new().try_from_str(
/// "2024-01-01T00:00:00+00:00[Europe/London]",
/// )
/// .unwrap()
/// .zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str(
/// let mut zone_london_summer = IxdtfParser::new().try_from_str(
/// "2024-07-01T00:00:00+01:00[Europe/London]",
/// )
/// .unwrap()
Expand Down Expand Up @@ -1289,15 +1289,15 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// use icu::datetime::neo_skeleton::NeoTimeZoneSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str(
/// let mut zone_london_winter = IxdtfParser::new().try_from_str(
/// "2024-01-01T00:00:00+00:00[Europe/London]",
/// )
/// .unwrap()
/// .zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str(
/// let mut zone_london_summer = IxdtfParser::new().try_from_str(
/// "2024-07-01T00:00:00+01:00[Europe/London]",
/// )
/// .unwrap()
Expand Down Expand Up @@ -1365,15 +1365,15 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// use icu::datetime::neo_skeleton::NeoTimeZoneSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str(
/// let mut zone_london_winter = IxdtfParser::new().try_from_str(
/// "2024-01-01T00:00:00+00:00[Europe/London]",
/// )
/// .unwrap()
/// .zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str(
/// let mut zone_london_summer = IxdtfParser::new().try_from_str(
/// "2024-07-01T00:00:00+01:00[Europe/London]",
/// )
/// .unwrap()
Expand Down Expand Up @@ -2393,15 +2393,15 @@ where
/// use icu::datetime::neo_skeleton::NeoTimeZoneSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::timezone::IxdtfParser;
/// use writeable::assert_try_writeable_eq;
///
/// let mut london_winter = CustomZonedDateTime::try_from_str(
/// let mut london_winter = IxdtfParser::new().try_from_str(
/// "2024-01-01T00:00:00+00:00[Europe/London]",
/// )
/// .unwrap()
/// .to_calendar(Gregorian);
/// let mut london_summer = CustomZonedDateTime::try_from_str(
/// let mut london_summer = IxdtfParser::new().try_from_str(
/// "2024-07-01T00:00:00+01:00[Europe/London]",
/// )
/// .unwrap()
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Some useful parsing functions for tests.

use icu_calendar::{DateTime, Gregorian};
use icu_timezone::{models, CustomZonedDateTime, TimeZoneInfo, ZoneVariant};
use icu_timezone::{models, CustomZonedDateTime, IxdtfParser, TimeZoneInfo, ZoneVariant};

/// Temporary function for parsing a `DateTime<Gregorian>`
///
Expand Down Expand Up @@ -58,10 +58,10 @@ pub fn parse_gregorian_from_str(input: &str) -> DateTime<Gregorian> {
pub fn parse_zoned_gregorian_from_str(
input: &str,
) -> CustomZonedDateTime<Gregorian, TimeZoneInfo<models::Full>> {
let iso_zdt = match CustomZonedDateTime::try_iso_from_str(input) {
let iso_zdt = match IxdtfParser::new().try_iso_from_str(input) {
Ok(zdt) => zdt,
Err(icu_timezone::ParseError::MismatchedTimeZoneFields) => {
match CustomZonedDateTime::try_loose_iso_from_str(input) {
match IxdtfParser::new().try_loose_iso_from_str(input) {
Ok(zdt) => {
CustomZonedDateTime {
date: zdt.date,
Expand Down
Loading

0 comments on commit 34807e6

Please sign in to comment.