Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 18, 2024
1 parent 3416eaf commit bb4aa7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 75 deletions.
54 changes: 5 additions & 49 deletions components/datetime/src/fieldset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ impl_zone_marker!(
/// All shapes of time zones can be formatted with this style.
///
/// ```
/// use icu::calendar::{DateTime, Iso};
/// use icu::calendar::{Date, Time};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::NeoTimeZoneOffsetMarker;
/// use icu::datetime::neo_skeleton::NeoSkeletonLength;
Expand All @@ -1087,41 +1087,17 @@ impl_zone_marker!(
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let datetime = DateTime::try_new_gregorian(2024, 10, 18, 0, 0, 0).unwrap();
///
/// let utc_offset = UtcOffset::from_eighths_of_hour(-6 * 8);
///
/// let zdt_utc_offset = CustomZonedDateTime {
/// date: datetime.date,
/// time: datetime.time,
/// zone: utc_offset
/// };
///
/// let time_zone_basic = utc_offset.with_id(TimeZoneBcp47Id(tinystr!(8, "uschi")));
///
/// let zdt_time_zone_basic = CustomZonedDateTime {
/// date: datetime.date,
/// time: datetime.time,
/// zone: time_zone_basic
/// };
///
/// let time_zone_at_time = time_zone_basic.at_time((datetime.date.to_iso(), datetime.time));
///
/// let zdt_time_zone_at_time = CustomZonedDateTime {
/// date: datetime.date,
/// time: datetime.time,
/// zone: time_zone_at_time
/// };
/// let date = Date::try_new_iso(2024, 10, 18).unwrap();
/// let time = Time::midnight();
/// let time_zone_at_time = time_zone_basic.at_time((date, time));
///
/// let time_zone_full = time_zone_at_time.with_zone_variant(ZoneVariant::standard());
///
/// let zdt_time_zone_full = CustomZonedDateTime {
/// date: datetime.date,
/// time: datetime.time,
/// zone: time_zone_full
/// };
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
/// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
/// &locale!("en-US").into(),
/// NeoTimeZoneOffsetMarker::with_length(NeoSkeletonLength::Medium),
/// )
Expand All @@ -1133,39 +1109,19 @@ impl_zone_marker!(
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&zdt_utc_offset),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&time_zone_basic),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&zdt_time_zone_basic),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&time_zone_at_time),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&zdt_time_zone_at_time),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&time_zone_full),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&zdt_time_zone_full),
/// "GMT-6"
/// );
/// ```
NeoTimeZoneOffsetMarker,
NeoTimeZoneStyle::Offset,
Expand Down
43 changes: 17 additions & 26 deletions components/datetime/src/scaffold/get_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,56 +295,47 @@ impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<NanoSecond>
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>> GetField<Option<UtcOffset>>
for CustomZonedDateTime<A, UtcOffset>
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<Option<UtcOffset>>
for CustomZonedDateTime<A, Z>
where
Z: GetField<Option<UtcOffset>>,
{
#[inline]
fn get_field(&self) -> Option<UtcOffset> {
Some(self.zone)
self.zone.get_field()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, O> GetField<TimeZoneBcp47Id>
for CustomZonedDateTime<A, TimeZoneInfo<O>>
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<TimeZoneBcp47Id>
for CustomZonedDateTime<A, Z>
where
O: TimeZoneModel,
Z: GetField<TimeZoneBcp47Id>,
{
#[inline]
fn get_field(&self) -> TimeZoneBcp47Id {
self.zone.time_zone_id
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, O> GetField<Option<UtcOffset>>
for CustomZonedDateTime<A, TimeZoneInfo<O>>
where
O: TimeZoneModel,
{
#[inline]
fn get_field(&self) -> Option<UtcOffset> {
self.zone.offset
self.zone.get_field()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, O> GetField<ZoneVariant>
for CustomZonedDateTime<A, TimeZoneInfo<O>>
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<ZoneVariant>
for CustomZonedDateTime<A, Z>
where
O: TimeZoneModel<ZoneVariant = ZoneVariant>,
Z: GetField<ZoneVariant>,
{
#[inline]
fn get_field(&self) -> ZoneVariant {
self.zone.zone_variant
self.zone.get_field()
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, O> GetField<(Date<Iso>, Time)>
for CustomZonedDateTime<A, TimeZoneInfo<O>>
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> GetField<(Date<Iso>, Time)>
for CustomZonedDateTime<A, Z>
where
O: TimeZoneModel<LocalTime = (Date<Iso>, Time)>,
Z: GetField<(Date<Iso>, Time)>,
{
#[inline]
fn get_field(&self) -> (Date<Iso>, Time) {
self.zone.local_time
self.zone.get_field()
}
}

Expand Down

0 comments on commit bb4aa7c

Please sign in to comment.