Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename CustomZonedDateTime to ZonedDateTime #5983

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/datetime/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions components/datetime/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use icu_datetime::{fieldsets::enums::CompositeFieldSet, FixedCalendarDateTimeFor

use icu_calendar::{Date, DateTime, Gregorian, Time};
use icu_locale_core::Locale;
use icu_timezone::{CustomZonedDateTime, TimeZoneInfo, ZoneVariant};
use icu_timezone::{TimeZoneInfo, ZoneVariant, ZonedDateTime};
use writeable::Writeable;

#[path = "../tests/mock.rs"]
Expand All @@ -23,15 +23,15 @@ fn datetime_benches(c: &mut Criterion) {
group.bench_function(format!("semantic/{name}"), |b| {
b.iter(|| {
for fx in &fxs.0 {
let datetimes: Vec<CustomZonedDateTime<Gregorian, _>> = fx
let datetimes: Vec<ZonedDateTime<Gregorian, _>> = fx
.values
.iter()
.map(move |value| {
if has_zones {
mock::parse_zoned_gregorian_from_str(value)
} else {
let DateTime { date, time } = mock::parse_gregorian_from_str(value);
CustomZonedDateTime {
ZonedDateTime {
date,
time,
// zone is unused but we need to make the types match
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! 3. [`Time`](icu_calendar::Time)
//! 4. [`UtcOffset`](icu_timezone::UtcOffset)
//! 5. [`TimeZoneInfo`](icu_timezone::TimeZoneInfo)
//! 6. [`CustomZonedDateTime`](icu_timezone::CustomZonedDateTime)
//! 6. [`ZonedDateTime`](icu_timezone::ZonedDateTime)
//!
//! Not all inputs are valid for all field sets.
//!
Expand Down
15 changes: 6 additions & 9 deletions components/datetime/src/scaffold/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use icu_calendar::{
};
use icu_provider::marker::NeverMarker;
use icu_provider::prelude::*;
use icu_timezone::{CustomZonedDateTime, TimeZoneInfo, TimeZoneModel, UtcOffset};
use icu_timezone::{TimeZoneInfo, TimeZoneModel, UtcOffset, ZonedDateTime};

/// A calendar that can be found in CLDR.
///
Expand Down Expand Up @@ -416,13 +416,13 @@ impl<C: IntoAnyCalendar, A: AsCalendar<Calendar = C>> ConvertCalendar for DateTi
}

impl<C: IntoAnyCalendar, A: AsCalendar<Calendar = C>, Z: Copy> ConvertCalendar
for CustomZonedDateTime<A, Z>
for ZonedDateTime<A, Z>
{
type Converted<'a> = CustomZonedDateTime<Ref<'a, AnyCalendar>, Z>;
type Converted<'a> = ZonedDateTime<Ref<'a, AnyCalendar>, Z>;
#[inline]
fn to_calendar<'a>(&self, calendar: &'a AnyCalendar) -> Self::Converted<'a> {
let date = self.date.to_any().to_calendar(Ref(calendar));
CustomZonedDateTime {
ZonedDateTime {
date,
time: self.time,
zone: self.zone,
Expand Down Expand Up @@ -490,7 +490,7 @@ impl<C: Calendar, A: AsCalendar<Calendar = C>> InSameCalendar for DateTime<A> {
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> InSameCalendar for CustomZonedDateTime<A, Z> {
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> InSameCalendar for ZonedDateTime<A, Z> {
#[inline]
fn check_any_calendar_kind(&self, _: AnyCalendarKind) -> Result<(), MismatchedCalendarError> {
Ok(())
Expand Down Expand Up @@ -520,10 +520,7 @@ impl<C> InFixedCalendar<C> for Time {}

impl<C: CldrCalendar, A: AsCalendar<Calendar = C>> InFixedCalendar<C> for DateTime<A> {}

impl<C: CldrCalendar, A: AsCalendar<Calendar = C>, Z> InFixedCalendar<C>
for CustomZonedDateTime<A, Z>
{
}
impl<C: CldrCalendar, A: AsCalendar<Calendar = C>, Z> InFixedCalendar<C> for ZonedDateTime<A, Z> {}

impl<C> InFixedCalendar<C> for UtcOffset {}

Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/scaffold/fieldset_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub trait DateTimeMarkers: UnstableSealed + DateTimeNamesMarker {
/// - [`Date`](icu_calendar::Date)
/// - [`Time`](icu_calendar::Time)
/// - [`DateTime`](icu_calendar::DateTime)
/// - [`CustomZonedDateTime`](icu_timezone::CustomZonedDateTime)
/// - [`ZonedDateTime`](icu_timezone::ZonedDateTime)
/// - [`UtcOffset`](icu_timezone::UtcOffset)
/// - [`TimeZoneInfo`](icu_timezone::TimeZoneInfo)
///
Expand Down
48 changes: 16 additions & 32 deletions components/datetime/src/scaffold/get_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use icu_calendar::{
AsCalendar, Calendar, Date, DateTime, Iso, Time,
};
use icu_timezone::{
CustomZonedDateTime, TimeZoneBcp47Id, TimeZoneInfo, TimeZoneModel, UtcOffset, ZoneVariant,
TimeZoneBcp47Id, TimeZoneInfo, TimeZoneModel, UtcOffset, ZoneVariant, ZonedDateTime,
};

use super::UnstableSealed;
Expand Down Expand Up @@ -165,87 +165,73 @@ impl<C: Calendar, A: AsCalendar<Calendar = C>> GetField<NanoSecond> for DateTime
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> UnstableSealed for CustomZonedDateTime<A, Z> {}
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> UnstableSealed for ZonedDateTime<A, Z> {}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<YearInfo> for CustomZonedDateTime<A, Z> {
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<YearInfo> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> YearInfo {
self.date.year()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<MonthInfo>
for CustomZonedDateTime<A, Z>
{
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<MonthInfo> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> MonthInfo {
self.date.month()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<DayOfMonth>
for CustomZonedDateTime<A, Z>
{
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<DayOfMonth> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> DayOfMonth {
self.date.day_of_month()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoWeekday>
for CustomZonedDateTime<A, Z>
{
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoWeekday> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> IsoWeekday {
self.date.day_of_week()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<DayOfYearInfo>
for CustomZonedDateTime<A, Z>
{
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<DayOfYearInfo> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> DayOfYearInfo {
self.date.day_of_year_info()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoHour> for CustomZonedDateTime<A, Z> {
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoHour> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> IsoHour {
self.time.hour
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoMinute>
for CustomZonedDateTime<A, Z>
{
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoMinute> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> IsoMinute {
self.time.minute
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoSecond>
for CustomZonedDateTime<A, Z>
{
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<IsoSecond> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> IsoSecond {
self.time.second
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<NanoSecond>
for CustomZonedDateTime<A, Z>
{
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<NanoSecond> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) -> NanoSecond {
self.time.nanosecond
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<Option<UtcOffset>>
for CustomZonedDateTime<A, Z>
for ZonedDateTime<A, Z>
where
Z: GetField<Option<UtcOffset>>,
{
Expand All @@ -255,8 +241,7 @@ where
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<TimeZoneBcp47Id>
for CustomZonedDateTime<A, Z>
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<TimeZoneBcp47Id> for ZonedDateTime<A, Z>
where
Z: GetField<TimeZoneBcp47Id>,
{
Expand All @@ -266,8 +251,7 @@ where
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<ZoneVariant>
for CustomZonedDateTime<A, Z>
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<ZoneVariant> for ZonedDateTime<A, Z>
where
Z: GetField<ZoneVariant>,
{
Expand All @@ -278,7 +262,7 @@ where
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<(Date<Iso>, Time)>
for CustomZonedDateTime<A, Z>
for ZonedDateTime<A, Z>
where
Z: GetField<(Date<Iso>, Time)>,
{
Expand Down Expand Up @@ -354,7 +338,7 @@ impl<C: Calendar, A: AsCalendar<Calendar = C>> GetField<()> for DateTime<A> {
fn get_field(&self) {}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<()> for CustomZonedDateTime<A, Z> {
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<()> for ZonedDateTime<A, Z> {
#[inline]
fn get_field(&self) {}
}
Expand Down
10 changes: 5 additions & 5 deletions components/datetime/tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use icu_locale_core::{
Locale,
};
use icu_provider::prelude::*;
use icu_timezone::{CustomZonedDateTime, TimeZoneIdMapper, TimeZoneInfo, UtcOffset};
use icu_timezone::{TimeZoneIdMapper, TimeZoneInfo, UtcOffset, ZonedDateTime};
use patterns::{
dayperiods::{DayPeriodExpectation, DayPeriodTests},
time_zones::TimeZoneTests,
Expand Down Expand Up @@ -275,23 +275,23 @@ fn assert_fixture_element<A>(
input_value.date.calendar().debug_name()
);

let input_value = CustomZonedDateTime {
let input_value = ZonedDateTime {
date: input_value.date.clone(),
time: input_value.time,
zone: TimeZoneInfo::utc(),
};
let input_iso = CustomZonedDateTime {
let input_iso = ZonedDateTime {
date: input_iso.date,
time: input_iso.time,
zone: TimeZoneInfo::utc(),
};

let any_input = CustomZonedDateTime {
let any_input = ZonedDateTime {
date: input_value.date.to_any(),
time: input_value.time,
zone: TimeZoneInfo::utc(),
};
let iso_any_input = CustomZonedDateTime {
let iso_any_input = ZonedDateTime {
date: input_iso.date.to_any(),
time: input_iso.time,
zone: TimeZoneInfo::utc(),
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, IxdtfParser, TimeZoneInfo, ZoneVariant};
use icu_timezone::{models, IxdtfParser, TimeZoneInfo, ZoneVariant, ZonedDateTime};

/// Temporary function for parsing a `DateTime<Gregorian>`
///
Expand Down Expand Up @@ -56,13 +56,13 @@ pub fn parse_gregorian_from_str(input: &str) -> DateTime<Gregorian> {
/// ```
pub fn parse_zoned_gregorian_from_str(
input: &str,
) -> CustomZonedDateTime<Gregorian, TimeZoneInfo<models::Full>> {
) -> ZonedDateTime<Gregorian, TimeZoneInfo<models::Full>> {
match IxdtfParser::new().try_from_str(input, Gregorian) {
Ok(zdt) => zdt,
Err(icu_timezone::ParseError::MismatchedTimeZoneFields) => {
match IxdtfParser::new().try_loose_from_str(input, Gregorian) {
Ok(zdt) => {
CustomZonedDateTime {
ZonedDateTime {
date: zdt.date,
time: zdt.time,
// For fixture tests, set the zone variant to standard here
Expand Down
4 changes: 2 additions & 2 deletions components/icu/examples/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use icu::timezone::TimeZoneInfo;
use icu_collections::codepointinvlist::CodePointInversionListBuilder;
use icu_datetime::fieldsets::YMDT;
use icu_datetime::FixedCalendarDateTimeFormatter;
use icu_timezone::CustomZonedDateTime;
use icu_timezone::ZonedDateTime;
use std::env;

fn main() {
Expand Down Expand Up @@ -47,7 +47,7 @@ fn main() {
let time = Time::try_new(18, 56, 0, 0).unwrap();
let zone = TimeZoneInfo::utc();

let formatted_dt = dtf.format(&CustomZonedDateTime { date, time, zone });
let formatted_dt = dtf.format(&ZonedDateTime { date, time, zone });

println!("Today is: {}", formatted_dt);
}
Expand Down
Loading
Loading