Skip to content

Commit

Permalink
Rename IxdtfParser and methods (#6007)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Jan 16, 2025
1 parent 3d187da commit e271d95
Show file tree
Hide file tree
Showing 26 changed files with 415 additions and 402 deletions.
24 changes: 12 additions & 12 deletions components/datetime/src/combo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!(
Expand All @@ -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
Expand All @@ -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!(
Expand All @@ -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
Expand All @@ -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!(
Expand All @@ -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(
Expand All @@ -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!(
Expand Down
8 changes: 4 additions & 4 deletions components/datetime/src/fieldsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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!(
Expand Down
10 changes: 5 additions & 5 deletions components/datetime/src/pattern/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Gregorian, ZoneFieldSet>::try_new(
Expand Down
60 changes: 30 additions & 30 deletions components/datetime/src/pattern/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
///
Expand All @@ -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!(
Expand Down Expand Up @@ -1012,15 +1012,15 @@ impl<C: CldrCalendar, FSet: DateTimeNamesMarker> TypedDateTimeNames<C, FSet> {
/// 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;
///
Expand Down Expand Up @@ -1124,11 +1124,11 @@ impl<C: CldrCalendar, FSet: DateTimeNamesMarker> TypedDateTimeNames<C, FSet> {
/// 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;
///
Expand Down Expand Up @@ -1191,15 +1191,15 @@ impl<C: CldrCalendar, FSet: DateTimeNamesMarker> TypedDateTimeNames<C, FSet> {
/// 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;
///
Expand Down Expand Up @@ -1268,15 +1268,15 @@ impl<C: CldrCalendar, FSet: DateTimeNamesMarker> TypedDateTimeNames<C, FSet> {
/// 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;
///
Expand Down Expand Up @@ -1345,15 +1345,15 @@ impl<C: CldrCalendar, FSet: DateTimeNamesMarker> TypedDateTimeNames<C, FSet> {
/// 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;
///
Expand Down Expand Up @@ -1422,15 +1422,15 @@ impl<C: CldrCalendar, FSet: DateTimeNamesMarker> TypedDateTimeNames<C, FSet> {
/// 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;
///
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::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.
///
Expand All @@ -28,10 +28,10 @@ use icu_timezone::{models, IxdtfParser, TimeZoneInfo, ZoneVariant, ZonedDateTime
pub fn parse_zoned_gregorian_from_str(
input: &str,
) -> ZonedDateTime<Gregorian, TimeZoneInfo<models::Full>> {
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,
Expand Down
8 changes: 5 additions & 3 deletions components/icu/examples/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn core::error::Error>> {
Expand Down Expand Up @@ -47,8 +49,8 @@ fn main() -> Result<(), Box<dyn core::error::Error>> {

// 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
);
Expand Down
Loading

0 comments on commit e271d95

Please sign in to comment.