Skip to content

Commit

Permalink
GetField impls for Combo
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Nov 12, 2024
1 parent 2e50fc6 commit 80729eb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
12 changes: 5 additions & 7 deletions components/datetime/src/combo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use core::marker::PhantomData;

use crate::{dynamic::*, format::neo::*, neo_skeleton::*, provider::neo::*, scaffold::*};
use crate::{format::neo::*, neo_skeleton::*, provider::neo::*, scaffold::*};

/// Struct for combining date, time, and zone fields.
///
Expand Down Expand Up @@ -104,6 +104,10 @@ impl<DT, Z> Combo<DT, Z> {
pub fn as_mut_dt(&mut self) -> &mut DT {
&mut self.date_time_field_set
}

pub(crate) fn dt(self) -> DT {
self.date_time_field_set
}
}

impl<DT, Z> DateTimeNamesMarker for Combo<DT, Z>
Expand Down Expand Up @@ -138,9 +142,3 @@ where
type TimePrecisionOption = DT::TimePrecisionOption;
type GluePatternV1Marker = datetime_marker_helper!(@glue, yes);
}

impl<DT, Z> GetField<CompositeFieldSet> for Combo<DT, Z> {
fn get_field(&self) -> CompositeFieldSet {
todo!()
}
}
49 changes: 45 additions & 4 deletions components/datetime/src/fieldset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,35 @@ macro_rules! impl_marker_with_options {
};
}

macro_rules! wrap {
($outer:path, $inner:expr) => {
$outer($inner)
};
}

macro_rules! no_wrap {
($_outer:path, $inner:expr) => {
$inner
};
}

macro_rules! impl_combo_zone_get_field {
($type:ident, $composite:ident, $enum:ident, $wrap:ident, $in:ident, $out:ident) => {
impl GetField<CompositeFieldSet> for Combo<$type, $in> {
#[inline]
fn get_field(&self) -> CompositeFieldSet {
CompositeFieldSet::$composite($wrap!($enum::$type, self.dt()), ZoneStyle::$out)
}
}
};
}

macro_rules! impl_zone_combo_helpers {
(
$type:ident
$type:ident,
$composite:ident,
$enum:ident,
$wrap:ident
) => {
impl $type {
/// Associates this field set with a specific non-location format time zone, as in
Expand All @@ -225,6 +251,10 @@ macro_rules! impl_zone_combo_helpers {
Combo::new(self)
}
}
impl_combo_zone_get_field!($type, $composite, $enum, $wrap, Zs, Z);
impl_combo_zone_get_field!($type, $composite, $enum, $wrap, O, O);
impl_combo_zone_get_field!($type, $composite, $enum, $wrap, Vs, V);
impl_combo_zone_get_field!($type, $composite, $enum, $wrap, L, L);
};
}

Expand Down Expand Up @@ -409,7 +439,7 @@ macro_rules! impl_date_marker {
$(input_any_calendar_kind = $any_calendar_kind_yes,)?
$(option_alignment = $option_alignment_yes,)?
);
impl_zone_combo_helpers!($type);
impl_zone_combo_helpers!($type, DateZone, DateFieldSet, wrap);
impl GetField<CompositeFieldSet> for $type {
#[inline]
fn get_field(&self) -> CompositeFieldSet {
Expand Down Expand Up @@ -471,7 +501,7 @@ macro_rules! impl_date_marker {
$(year_style: $year_yes,)?
time_precision: yes,
);
impl_zone_combo_helpers!($type_time);
impl_zone_combo_helpers!($type_time, DateTimeZone, DateAndTimeFieldSet, wrap);
impl UnstableSealed for $type_time {}
impl DateTimeNamesMarker for $type_time {
type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?);
Expand Down Expand Up @@ -674,7 +704,7 @@ macro_rules! impl_time_marker {
alignment: yes,
time_precision: yes,
);
impl_zone_combo_helpers!($type);
impl_zone_combo_helpers!($type, TimeZone, TimeFieldSet, wrap);
impl UnstableSealed for $type {}
impl DateTimeNamesMarker for $type {
type YearNames = datetime_marker_helper!(@names/year,);
Expand Down Expand Up @@ -1594,3 +1624,14 @@ impl_zoneddatetime_marker!(
datetime = YMDT,
zone = O,
);

impl_zone_combo_helpers!(DateFieldSet, DateZone, DateFieldSet, no_wrap);

impl_zone_combo_helpers!(TimeFieldSet, TimeZone, TimeFieldSet, no_wrap);

impl_zone_combo_helpers!(
DateAndTimeFieldSet,
DateTimeZone,
DateAndTimeFieldSet,
no_wrap
);

0 comments on commit 80729eb

Please sign in to comment.