Skip to content

Commit e729efa

Browse files
committed
jiff-icu: upgrade to ICU4X 2.0.0
This mostly just involved doing some renames.
1 parent 92f25e0 commit e729efa

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

crates/jiff-icu/src/lib.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let icu_zdt = ZonedDateTime::<Iso, _>::convert_from(&zdt);
5050
// Format for the en-GB locale:
5151
let formatter = DateTimeFormatter::try_new(
5252
locale!("en-GB").into(),
53-
fieldsets::YMDET::medium().zone(fieldsets::zone::SpecificLong),
53+
fieldsets::YMDET::medium().with_zone(fieldsets::zone::SpecificLong),
5454
)?;
5555
assert_eq!(
5656
formatter.format(&icu_zdt).to_string(),
@@ -60,17 +60,17 @@ assert_eq!(
6060
// Or in the en-US locale:
6161
let formatter = DateTimeFormatter::try_new(
6262
locale!("en-US").into(),
63-
fieldsets::YMDET::medium().zone(fieldsets::zone::SpecificShort),
63+
fieldsets::YMDET::medium().with_zone(fieldsets::zone::SpecificShort),
6464
)?;
6565
assert_eq!(
6666
formatter.format(&icu_zdt).to_string(),
6767
"Tue, Sep 10, 2024, 11:37:20 PM EDT",
6868
);
6969
70-
// Or in the default or "unknown" locale:
70+
// Or in the "unknown" locale:
7171
let formatter = DateTimeFormatter::try_new(
72-
icu::locale::Locale::default().into(),
73-
fieldsets::YMDET::medium().zone(fieldsets::zone::SpecificShort),
72+
icu::locale::Locale::UNKNOWN.into(),
73+
fieldsets::YMDET::medium().with_zone(fieldsets::zone::SpecificShort),
7474
)?;
7575
assert_eq!(
7676
formatter.format(&icu_zdt).to_string(),
@@ -163,15 +163,16 @@ use icu_calendar::{
163163
types::Weekday as IcuWeekday, AsCalendar as IcuAsCalendar,
164164
Date as IcuDate, Iso,
165165
};
166-
#[cfg(feature = "zoned")]
167-
use icu_time::{
168-
provider::TimeZoneVariant, zone::models::Full, TimeZone as IcuTimeZone,
169-
TimeZoneInfo as IcuTimeZoneInfo, ZonedDateTime as IcuZonedDateTime,
170-
};
171166
#[cfg(feature = "time")]
172167
use icu_time::{
173168
zone::UtcOffset as IcuUtcOffset, DateTime as IcuDateTime, Time as IcuTime,
174169
};
170+
#[cfg(feature = "zoned")]
171+
use icu_time::{
172+
zone::{models::Full, TimeZoneVariant},
173+
TimeZone as IcuTimeZone, TimeZoneInfo as IcuTimeZoneInfo,
174+
ZonedDateTime as IcuZonedDateTime,
175+
};
175176

176177
use jiff::civil::{Date as JiffDate, Weekday as JiffWeekday};
177178
#[cfg(feature = "time")]
@@ -354,7 +355,7 @@ impl<C: IcuAsCalendar> ConvertTryFrom<IcuDate<C>> for JiffDate {
354355

355356
fn convert_try_from(v: IcuDate<C>) -> Result<JiffDate, Error> {
356357
let v = v.to_iso();
357-
let year = v.year().extended_year;
358+
let year = v.extended_year();
358359
let year = i16::try_from(year).map_err(|_| {
359360
err!("failed to convert `icu` year of {year} to `i16`")
360361
})?;
@@ -420,7 +421,7 @@ impl<C: IcuAsCalendar> ConvertTryFrom<IcuDate<C>> for JiffDate {
420421
/// let icu_hebrew_date = icu_iso_date.to_calendar(icu_calendar::cal::Hebrew);
421422
/// assert_eq!(
422423
/// format!("{icu_hebrew_date:?}"),
423-
/// "Date(5785-5-4, hebrew era, for calendar Hebrew)",
424+
/// "Date(5785-5-4, am era, for calendar Hebrew)",
424425
/// );
425426
/// ```
426427
impl ConvertFrom<JiffDate> for IcuDate<Iso> {
@@ -611,14 +612,14 @@ impl ConvertTryFrom<JiffOffset> for IcuUtcOffset {
611612
/// let icu_tz = icu_time::TimeZone::convert_from(jiff_tz);
612613
/// assert_eq!(
613614
/// format!("{icu_tz:?}"),
614-
/// "TimeZone(\"usnyc\")",
615+
/// "TimeZone(Subtag(\"usnyc\"))",
615616
/// );
616617
///
617618
/// let jiff_tz = jiff::tz::TimeZone::get("us/eastern")?;
618619
/// let icu_tz = icu_time::TimeZone::convert_from(jiff_tz);
619620
/// assert_eq!(
620621
/// format!("{icu_tz:?}"),
621-
/// "TimeZone(\"usnyc\")",
622+
/// "TimeZone(Subtag(\"usnyc\"))",
622623
/// );
623624
///
624625
/// // If there's no IANA identifier for the Jiff time zone, then
@@ -627,7 +628,7 @@ impl ConvertTryFrom<JiffOffset> for IcuUtcOffset {
627628
/// let icu_tz = icu_time::TimeZone::convert_from(jiff_tz);
628629
/// assert_eq!(
629630
/// format!("{icu_tz:?}"),
630-
/// "TimeZone(\"unk\")",
631+
/// "TimeZone(Subtag(\"unk\"))",
631632
/// );
632633
///
633634
/// // An explicitly unknown Jiff time zone is equivalent to an
@@ -636,7 +637,7 @@ impl ConvertTryFrom<JiffOffset> for IcuUtcOffset {
636637
/// let icu_tz = icu_time::TimeZone::convert_from(jiff_tz);
637638
/// assert_eq!(
638639
/// format!("{icu_tz:?}"),
639-
/// "TimeZone(\"unk\")",
640+
/// "TimeZone(Subtag(\"unk\"))",
640641
/// );
641642
///
642643
/// # Ok::<(), Box<dyn std::error::Error>>(())
@@ -654,7 +655,7 @@ impl ConvertFrom<JiffTimeZone> for IcuTimeZone {
654655
impl<'a> ConvertFrom<&'a JiffTimeZone> for IcuTimeZone {
655656
fn convert_from(v: &'a JiffTimeZone) -> IcuTimeZone {
656657
let Some(iana_name) = v.iana_name() else {
657-
return IcuTimeZone::unknown();
658+
return IcuTimeZone::UNKNOWN;
658659
};
659660
icu_time::zone::iana::IanaParser::new().parse(iana_name)
660661
}
@@ -681,8 +682,8 @@ impl<'a> ConvertFrom<&'a JiffTimeZone> for IcuTimeZone {
681682
/// "Time { hour: Hour(17), minute: Minute(58), second: Second(30), subsecond: Nanosecond(0) }",
682683
/// );
683684
/// assert_eq!(
684-
/// format!("{:?}", (icu_zdt.zone.time_zone_id(), icu_zdt.zone.offset())),
685-
/// "(TimeZone(\"usnyc\"), Some(UtcOffset(-18000)))",
685+
/// format!("{:?}", (icu_zdt.zone.id(), icu_zdt.zone.offset())),
686+
/// "(TimeZone(Subtag(\"usnyc\")), Some(UtcOffset(-18000)))",
686687
/// );
687688
///
688689
/// # Ok::<(), Box<dyn std::error::Error>>(())
@@ -696,13 +697,14 @@ impl<'a> ConvertFrom<&'a JiffZoned>
696697
) -> IcuZonedDateTime<Iso, IcuTimeZoneInfo<Full>> {
697698
let date = IcuDate::convert_from(v.date());
698699
let time = IcuTime::convert_from(v.time());
700+
let datetime = IcuDateTime { date, time };
699701

700702
let tz = IcuTimeZone::convert_from(v.time_zone());
701703
let offset = IcuUtcOffset::convert_try_from(v.offset()).ok();
702704
let dst = v.time_zone().to_offset_info(v.timestamp()).dst().is_dst();
703705
let tz_info_base = tz.with_offset(offset);
704-
let tz_info_at = tz_info_base.at_time((date, time));
705-
let zone = tz_info_at.with_zone_variant(if dst {
706+
let tz_info_at = tz_info_base.at_date_time_iso(datetime);
707+
let zone = tz_info_at.with_variant(if dst {
706708
TimeZoneVariant::Daylight
707709
} else {
708710
TimeZoneVariant::Standard

0 commit comments

Comments
 (0)