#[path = "dynamic.rs"]
pub mod enums;
pub use crate::combo::Combo;
use crate::{
fields,
options::*,
provider::{neo::*, time_zones::tz, *},
raw::neo::RawOptions,
scaffold::*,
};
use enums::*;
use icu_calendar::{
types::{
DayOfMonth, IsoHour, IsoMinute, IsoSecond, IsoWeekday, MonthInfo, NanoSecond, YearInfo,
},
Date, Iso, Time,
};
use icu_provider::marker::NeverMarker;
use icu_timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
#[cfg(all(feature = "experimental", feature = "serde"))]
pub mod serde {
pub use crate::neo_serde::CompositeFieldSetSerde;
pub use crate::neo_serde::CompositeFieldSetSerdeError;
}
#[cfg(doc)]
use icu_timezone::TimeZoneInfo;
macro_rules! yes_to {
($any:expr, yes) => {
$any
};
() => {
unreachable!() };
}
macro_rules! yes_or {
($fallback:expr, $actual:expr) => {
$actual
};
($fallback:expr,) => {
$fallback
};
}
macro_rules! ternary {
($present:expr, $missing:expr, yes) => {
$present
};
($present:expr, $missing:expr, $any:literal) => {
$present
};
($present:expr, $missing:expr,) => {
$missing
};
}
macro_rules! length_option_helper {
($type:ty, $length:ident) => {
concat!(stringify!($type), "::", stringify!($length), "()")
};
}
macro_rules! impl_composite {
($type:ident, $variant:ident, $enum:ident) => {
impl $type {
#[inline]
pub(crate) fn to_enum(self) -> $enum {
$enum::$type(self)
}
}
impl GetField<CompositeFieldSet> for $type {
#[inline]
fn get_field(&self) -> CompositeFieldSet {
CompositeFieldSet::$variant(self.to_enum())
}
}
};
}
macro_rules! impl_marker_with_options {
(
$(#[$attr:meta])*
$type:ident,
$(sample_length: $sample_length:ident,)?
$(alignment: $alignment_yes:ident,)?
$(year_style: $yearstyle_yes:ident,)?
$(time_precision: $timeprecision_yes:ident,)?
$(enumerated: $enumerated_yes:ident,)?
) => {
$(#[$attr])*
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct $type {
$(
/// The desired length of the formatted string.
pub length: datetime_marker_helper!(@option/length, $sample_length),
)?
$(
pub alignment: datetime_marker_helper!(@option/alignment, $alignment_yes),
)?
$(
pub year_style: datetime_marker_helper!(@option/yearstyle, $yearstyle_yes),
)?
$(
pub time_precision: datetime_marker_helper!(@option/timeprecision, $timeprecision_yes),
)?
}
impl $type {
#[doc = concat!("Creates a ", stringify!($type), " skeleton with the given formatting length.")]
pub const fn with_length(length: Length) -> Self {
Self {
length,
$(
alignment: yes_to!(None, $alignment_yes),
)?
$(
year_style: yes_to!(None, $yearstyle_yes),
)?
$(
time_precision: yes_to!(None, $timeprecision_yes),
)?
}
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a long length.")]
pub const fn long() -> Self {
Self::with_length(Length::Long)
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a medium length.")]
pub const fn medium() -> Self {
Self::with_length(Length::Medium)
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a short length.")]
pub const fn short() -> Self {
Self::with_length(Length::Short)
}
}
#[allow(dead_code)]
impl $type {
$(
const _: () = yes_to!((), $enumerated_yes); #[warn(dead_code)]
)?
pub(crate) fn to_raw_options(self) -> RawOptions {
RawOptions {
length: self.length,
alignment: ternary!(self.alignment, None, $($alignment_yes)?),
year_style: ternary!(self.year_style, None, $($yearstyle_yes)?),
time_precision: ternary!(self.time_precision, None, $($timeprecision_yes)?),
}
}
$(
const _: () = yes_to!((), $enumerated_yes); #[warn(dead_code)]
)?
pub(crate) fn from_raw_options(options: RawOptions) -> Self {
Self {
length: options.length,
$(alignment: yes_to!(options.alignment, $alignment_yes),)?
$(year_style: yes_to!(options.year_style, $yearstyle_yes),)?
$(time_precision: yes_to!(options.time_precision, $timeprecision_yes),)?
}
}
}
$(
impl $type {
pub const fn with_alignment(mut self, alignment: Alignment) -> Self {
self.alignment = Some(yes_to!(alignment, $alignment_yes));
self
}
}
)?
$(
impl $type {
pub const fn with_year_style(mut self, year_style: YearStyle) -> Self {
self.year_style = Some(yes_to!(year_style, $yearstyle_yes));
self
}
}
)?
$(
impl $type {
pub const fn with_time_precision(mut self, time_precision: TimePrecision) -> Self {
self.time_precision = Some(yes_to!(time_precision, $timeprecision_yes));
self
}
pub fn hm(mut self) -> Self {
self.time_precision = Some(TimePrecision::MinuteExact);
self
}
}
)?
};
}
macro_rules! impl_combo_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(self.dt().to_enum(), ZoneStyle::$out)
}
}
};
}
macro_rules! impl_combo_generic_fns {
($type:ident) => {
impl<Z> Combo<$type, Z> {
#[doc = concat!("Creates a ", stringify!($type), " skeleton with the given formatting length and a time zone.")]
pub fn with_length(length: Length) -> Self {
Self::new($type::with_length(length))
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a long length and a time zone.")]
pub const fn long() -> Self {
Self::new($type::long())
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a medium length and a time zone.")]
pub const fn medium() -> Self {
Self::new($type::medium())
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a short length and a time zone.")]
pub const fn short() -> Self {
Self::new($type::short())
}
}
};
}
macro_rules! impl_zone_combo_helpers {
(
$type:ident,
$composite:ident,
$enum:ident,
$wrap:ident
) => {
impl $type {
#[inline]
pub fn zone_z(self) -> Combo<Self, Zs> {
Combo::new(self)
}
#[inline]
pub fn zone_o(self) -> Combo<Self, O> {
Combo::new(self)
}
#[inline]
pub fn zone_v(self) -> Combo<Self, Vs> {
Combo::new(self)
}
#[inline]
pub fn zone_l(self) -> Combo<Self, L> {
Combo::new(self)
}
}
impl_combo_get_field!($type, $composite, $enum, $wrap, Zs, Z);
impl_combo_get_field!($type, $composite, $enum, $wrap, O, O);
impl_combo_get_field!($type, $composite, $enum, $wrap, Vs, V);
impl_combo_get_field!($type, $composite, $enum, $wrap, L, L);
};
}
macro_rules! impl_date_or_calendar_period_marker {
(
$(#[$attr:meta])*
// The name of the type being created.
$type:ident,
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the sample string below.
sample_length = $sample_length:ident,
// A sample string. A docs test will be generated!
sample = $sample:literal,
// Whether years can occur.
$(years = $years_yes:ident,)?
// Whether months can occur.
$(months = $months_yes:ident,)?
// Whether weekdays can occur.
$(weekdays = $weekdays_yes:ident,)?
// Whether the input should contain years.
$(input_year = $year_yes:ident,)?
// Whether the input should contain months.
$(input_month = $month_yes:ident,)?
// Whether the input should contain the day of the month.
$(input_day_of_month = $day_of_month_yes:ident,)?
// Whether the input should contain the day of the week.
$(input_day_of_week = $day_of_week_yes:ident,)?
// Whether the input should contain the day of the year.
$(input_day_of_year = $day_of_year_yes:ident,)?
// Whether the input should declare its calendar kind.
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)?
// Whether the alignment option should be available.
// According to UTS 35, it should be available with years, months, and days.
$(option_alignment = $option_alignment_yes:ident,)?
) => {
impl_marker_with_options!(
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")]
#[doc = concat!("let fmt = DateTimeFormatter::<", stringify!($type), ">::try_new(")]
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
#[doc = concat!(" \"", $sample, "\"")]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")]
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type), ">::try_new(")]
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
#[doc = concat!(" \"", $sample, "\"")]
$(#[$attr])*
$type,
sample_length: $sample_length,
$(alignment: $option_alignment_yes,)?
$(year_style: $year_yes,)?
);
impl UnstableSealed for $type {}
impl DateTimeNamesMarker for $type {
type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?);
type MonthNames = datetime_marker_helper!(@names/month, $($months_yes)?);
type WeekdayNames = datetime_marker_helper!(@names/weekday, $($weekdays_yes)?);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod,);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,);
}
impl DateInputMarkers for $type {
type YearInput = datetime_marker_helper!(@input/year, $($year_yes)?);
type MonthInput = datetime_marker_helper!(@input/month, $($month_yes)?);
type DayOfMonthInput = datetime_marker_helper!(@input/day_of_month, $($day_of_month_yes)?);
type DayOfYearInput = datetime_marker_helper!(@input/day_of_year, $($day_of_year_yes)?);
type DayOfWeekInput = datetime_marker_helper!(@input/day_of_week, $($day_of_week_yes)?);
}
impl<C: CldrCalendar> TypedDateDataMarkers<C> for $type {
type DateSkeletonPatternsV1Marker = datetime_marker_helper!(@dates/typed, yes);
type YearNamesV1Marker = datetime_marker_helper!(@years/typed, $($years_yes)?);
type MonthNamesV1Marker = datetime_marker_helper!(@months/typed, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl DateDataMarkers for $type {
type Skel = datetime_marker_helper!(@calmarkers, yes);
type Year = datetime_marker_helper!(@calmarkers, $($years_yes)?);
type Month = datetime_marker_helper!(@calmarkers, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl DateTimeMarkers for $type {
type D = Self;
type T = ();
type Z = ();
type GluePatternV1Marker = datetime_marker_helper!(@glue,);
}
};
}
macro_rules! impl_date_marker {
(
$(#[$attr:meta])*
$type:ident,
$type_time:ident,
description = $description:literal,
sample_length = $sample_length:ident,
sample = $sample:literal,
sample_time = $sample_time:literal,
$(years = $years_yes:ident,)?
$(months = $months_yes:ident,)?
$(dates = $dates_yes:ident,)?
$(weekdays = $weekdays_yes:ident,)?
$(input_year = $year_yes:ident,)?
$(input_month = $month_yes:ident,)?
$(input_day_of_month = $day_of_month_yes:ident,)?
$(input_day_of_week = $day_of_week_yes:ident,)?
$(input_day_of_year = $day_of_year_yes:ident,)?
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)?
$(option_alignment = $option_alignment_yes:ident,)?
) => {
impl_date_or_calendar_period_marker!(
$(#[$attr])*
$type,
description = $description,
sample_length = $sample_length,
sample = $sample,
$(years = $years_yes,)?
$(months = $months_yes,)?
$(dates = $dates_yes,)?
$(weekdays = $weekdays_yes,)?
$(input_year = $year_yes,)?
$(input_month = $month_yes,)?
$(input_day_of_month = $day_of_month_yes,)?
$(input_day_of_week = $day_of_week_yes,)?
$(input_day_of_year = $day_of_year_yes,)?
$(input_any_calendar_kind = $any_calendar_kind_yes,)?
$(option_alignment = $option_alignment_yes,)?
);
impl_zone_combo_helpers!($type, DateZone, DateFieldSet, wrap);
impl_combo_generic_fns!($type);
impl_composite!($type, Date, DateFieldSet);
impl_marker_with_options!(
#[doc = concat!("**“", $sample_time, "**” ⇒ ", $description, " with time")]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type_time), ";")]
#[doc = concat!("let fmt = DateTimeFormatter::try_new(")]
#[doc = concat!(" ", length_option_helper!($type_time, $sample_length), ",")]
#[doc = concat!(" \"", $sample_time, "\"")]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type_time), ";")]
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::try_new(")]
#[doc = concat!(" ", length_option_helper!($type_time, $sample_length), ",")]
#[doc = concat!(" \"", $sample_time, "\"")]
$(#[$attr])*
$type_time,
sample_length: $sample_length,
alignment: yes,
$(year_style: $year_yes,)?
time_precision: yes,
);
impl_zone_combo_helpers!($type_time, DateTimeZone, DateAndTimeFieldSet, wrap);
impl_combo_generic_fns!($type_time);
impl UnstableSealed for $type_time {}
impl DateTimeNamesMarker for $type_time {
type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?);
type MonthNames = datetime_marker_helper!(@names/month, $($months_yes)?);
type WeekdayNames = datetime_marker_helper!(@names/weekday, $($weekdays_yes)?);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod, yes);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,);
}
impl DateInputMarkers for $type_time {
type YearInput = datetime_marker_helper!(@input/year, $($year_yes)?);
type MonthInput = datetime_marker_helper!(@input/month, $($month_yes)?);
type DayOfMonthInput = datetime_marker_helper!(@input/day_of_month, $($day_of_month_yes)?);
type DayOfYearInput = datetime_marker_helper!(@input/day_of_year, $($day_of_year_yes)?);
type DayOfWeekInput = datetime_marker_helper!(@input/day_of_week, $($day_of_week_yes)?);
}
impl<C: CldrCalendar> TypedDateDataMarkers<C> for $type_time {
type DateSkeletonPatternsV1Marker = datetime_marker_helper!(@dates/typed, yes);
type YearNamesV1Marker = datetime_marker_helper!(@years/typed, $($years_yes)?);
type MonthNamesV1Marker = datetime_marker_helper!(@months/typed, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl DateDataMarkers for $type_time {
type Skel = datetime_marker_helper!(@calmarkers, yes);
type Year = datetime_marker_helper!(@calmarkers, $($years_yes)?);
type Month = datetime_marker_helper!(@calmarkers, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl TimeMarkers for $type_time {
type DayPeriodNamesV1Marker = datetime_marker_helper!(@dayperiods, yes);
type TimeSkeletonPatternsV1Marker = datetime_marker_helper!(@times, yes);
type HourInput = datetime_marker_helper!(@input/hour, yes);
type MinuteInput = datetime_marker_helper!(@input/minute, yes);
type SecondInput = datetime_marker_helper!(@input/second, yes);
type NanoSecondInput = datetime_marker_helper!(@input/nanosecond, yes);
}
impl DateTimeMarkers for $type_time {
type D = Self;
type T = Self;
type Z = ();
type GluePatternV1Marker = datetime_marker_helper!(@glue, yes);
}
impl_composite!($type_time, DateTime, DateAndTimeFieldSet);
impl $type_time {
pub(crate) fn to_date_field_set(self) -> $type {
$type {
length: self.length,
$(alignment: yes_to!(self.alignment, $option_alignment_yes),)?
$(year_style: yes_to!(self.year_style, $years_yes),)?
}
}
}
};
}
macro_rules! impl_calendar_period_marker {
(
$(#[$attr:meta])*
$type:ident,
description = $description:literal,
sample_length = $sample_length:ident,
sample = $sample:literal,
$(years = $years_yes:ident,)?
$(months = $months_yes:ident,)?
$(dates = $dates_yes:ident,)?
$(input_year = $year_yes:ident,)?
$(input_month = $month_yes:ident,)?
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)?
$(option_alignment = $option_alignment_yes:ident,)?
) => {
impl_date_or_calendar_period_marker!(
$(#[$attr])*
$type,
description = $description,
sample_length = $sample_length,
sample = $sample,
$(years = $years_yes,)?
$(months = $months_yes,)?
$(dates = $dates_yes,)?
$(input_year = $year_yes,)?
$(input_month = $month_yes,)?
$(input_any_calendar_kind = $any_calendar_kind_yes,)?
$(option_alignment = $option_alignment_yes,)?
);
impl_composite!($type, CalendarPeriod, CalendarPeriodFieldSet);
};
}
macro_rules! impl_time_marker {
(
$(#[$attr:meta])*
// The name of the type being created.
$type:ident,
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the sample string below.
sample_length = $sample_length:ident,
// A sample string. A docs test will be generated!
sample = $sample:literal,
// Whether day periods can occur.
$(dayperiods = $dayperiods_yes:ident,)?
// Whether the input should include hours.
$(input_hour = $hour_yes:ident,)?
// Whether the input should contain minutes.
$(input_minute = $minute_yes:ident,)?
// Whether the input should contain seconds.
$(input_second = $second_yes:ident,)?
// Whether the input should contain fractional seconds.
$(input_nanosecond = $nanosecond_yes:ident,)?
) => {
impl_marker_with_options!(
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")]
#[doc = concat!("let fmt = TimeFormatter::try_new(")]
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
#[doc = concat!(" \"", $sample, "\"")]
$(#[$attr])*
$type,
sample_length: $sample_length,
alignment: yes,
time_precision: yes,
);
impl_zone_combo_helpers!($type, TimeZone, TimeFieldSet, wrap);
impl_combo_generic_fns!($type);
impl UnstableSealed for $type {}
impl DateTimeNamesMarker for $type {
type YearNames = datetime_marker_helper!(@names/year,);
type MonthNames = datetime_marker_helper!(@names/month,);
type WeekdayNames = datetime_marker_helper!(@names/weekday,);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod, $($dayperiods_yes)?);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,);
}
impl TimeMarkers for $type {
type DayPeriodNamesV1Marker = datetime_marker_helper!(@dayperiods, $($dayperiods_yes)?);
type TimeSkeletonPatternsV1Marker = datetime_marker_helper!(@times, yes);
type HourInput = datetime_marker_helper!(@input/hour, $($hour_yes)?);
type MinuteInput = datetime_marker_helper!(@input/minute, $($minute_yes)?);
type SecondInput = datetime_marker_helper!(@input/second, $($second_yes)?);
type NanoSecondInput = datetime_marker_helper!(@input/nanosecond, $($nanosecond_yes)?);
}
impl DateTimeMarkers for $type {
type D = ();
type T = Self;
type Z = ();
type GluePatternV1Marker = datetime_marker_helper!(@glue,);
}
impl_composite!($type, Time, TimeFieldSet);
};
}
macro_rules! impl_zone_marker {
(
$(#[$attr:meta])*
// The name of the type being created.
$type:ident,
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the sample string below.
sample_length = $sample_length:ident,
// A sample string. A docs test will be generated!
sample = $sample:literal,
// The field symbol and field length when the semantic length is short/medium.
field_short = $field_short:expr,
// The field symbol and field length when the semantic length is long.
field_long = $field_long:expr,
// The type in ZoneFieldSet for this field set
resolved_type = $resolved_type:ident,
// Whether to skip tests and render a message instead.
$(skip_tests = $skip_tests:literal,)?
// Whether zone-essentials should be loaded.
$(zone_essentials = $zone_essentials_yes:ident,)?
// Whether locations formats can occur.
$(zone_locations = $zone_locations_yes:ident,)?
// Whether generic long formats can occur.
$(zone_generic_long = $zone_generic_long_yes:ident,)?
// Whether generic short formats can occur.
$(zone_generic_short = $zone_generic_short_yes:ident,)?
// Whether specific long formats can occur.
$(zone_specific_long = $zone_specific_long_yes:ident,)?
// Whether specific short formats can occur.
$(zone_specific_short = $zone_specific_short_yes:ident,)?
// Whether metazone periods are needed
$(metazone_periods = $metazone_periods_yes:ident,)?
// Whether to require the TimeZoneBcp47Id
$(input_tzid = $tzid_input_yes:ident,)?
// Whether to require the ZoneVariant
$(input_variant = $variant_input_yes:ident,)?
// Whether to require the Local Time
$(input_localtime = $localtime_input_yes:ident,)?
// Whether this time zone style is enumerated in ZoneFieldSet
$(enumerated = $enumerated_yes:ident,)?
) => {
impl_marker_with_options!(
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
#[doc = yes_or!("", $($skip_tests)?)]
#[doc = concat!("```", ternary!("compile_fail", "", $($skip_tests)?))]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")]
#[doc = concat!("let fmt = TimeFormatter::try_new(")]
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
#[doc = concat!(" \"", $sample, "\"")]
$(#[$attr])*
$type,
sample_length: $sample_length,
);
impl UnstableSealed for $type {}
impl DateTimeNamesMarker for $type {
type YearNames = datetime_marker_helper!(@names/year,);
type MonthNames = datetime_marker_helper!(@names/month,);
type WeekdayNames = datetime_marker_helper!(@names/weekday,);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod,);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials, $($zone_essentials_yes)?);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations, $($zone_locations_yes)?);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long, $($zone_generic_long_yes)?);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short, $($zone_generic_short_yes)?);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long, $($zone_specific_long_yes)?);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short, $($zone_specific_short_yes)?);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods, $($metazone_periods_yes)?);
}
impl ZoneMarkers for $type {
type TimeZoneIdInput = datetime_marker_helper!(@input/timezone/id, $($tzid_input_yes)?);
type TimeZoneOffsetInput = datetime_marker_helper!(@input/timezone/offset, yes);
type TimeZoneVariantInput = datetime_marker_helper!(@input/timezone/variant, $($variant_input_yes)?);
type TimeZoneLocalTimeInput = datetime_marker_helper!(@input/timezone/local_time, $($localtime_input_yes)?);
type EssentialsV1Marker = datetime_marker_helper!(@data/zone/essentials, $($zone_essentials_yes)?);
type LocationsV1Marker = datetime_marker_helper!(@data/zone/locations, $($zone_locations_yes)?);
type GenericLongV1Marker = datetime_marker_helper!(@data/zone/generic_long, $($zone_generic_long_yes)?);
type GenericShortV1Marker = datetime_marker_helper!(@data/zone/generic_short, $($zone_generic_short_yes)?);
type SpecificLongV1Marker = datetime_marker_helper!(@data/zone/specific_long, $($zone_specific_long_yes)?);
type SpecificShortV1Marker = datetime_marker_helper!(@data/zone/specific_short, $($zone_specific_short_yes)?);
type MetazonePeriodV1Marker = datetime_marker_helper!(@data/zone/metazone_periods, $($metazone_periods_yes)?);
}
impl DateTimeMarkers for $type {
type D = ();
type T = ();
type Z = Self;
type GluePatternV1Marker = datetime_marker_helper!(@glue,);
}
$(
const _: () = yes_to!((), $enumerated_yes); impl_composite!($type, Zone, ZoneFieldSet);
impl $type {
pub(crate) fn to_field(self) -> (fields::TimeZone, fields::FieldLength) {
match self.length {
Length::Short | Length::Medium => $field_short,
Length::Long => $field_long,
}
}
}
)?
};
}
macro_rules! impl_zoneddatetime_marker {
(
$type:ident,
description = $description:literal,
sample_length = $sample_length:ident,
sample = $sample:literal,
datetime = $datetime:path,
zone = $zone:path,
) => {
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")]
#[doc = concat!("let fmt = DateTimeFormatter::try_new(")]
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
#[doc = concat!(" \"", $sample, "\"")]
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")]
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type), ">::try_new(")]
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
#[doc = concat!(" \"", $sample, "\"")]
pub type $type = Combo<$datetime, $zone>;
}
}
impl_date_marker!(
D,
DT,
description = "day of month (standalone)",
sample_length = short,
sample = "17",
sample_time = "17, 3:47:50 PM",
input_day_of_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
E,
ET,
description = "weekday (standalone)",
sample_length = long,
sample = "Friday",
sample_time = "Friday 3:47:50 PM",
weekdays = yes,
input_day_of_week = yes,
);
impl_date_marker!(
DE,
DET,
description = "day of month and weekday",
sample_length = long,
sample = "17 Friday",
sample_time = "17 Friday, 3:47:50 PM",
weekdays = yes,
input_day_of_month = yes,
input_day_of_week = yes,
option_alignment = yes,
);
impl_date_marker!(
MD,
MDT,
description = "month and day",
sample_length = medium,
sample = "May 17",
sample_time = "May 17, 3:47:50 PM",
months = yes,
input_month = yes,
input_day_of_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
MDE,
MDET,
description = "month, day, and weekday",
sample_length = medium,
sample = "Fri, May 17",
sample_time = "Fri, May 17, 3:47:50 PM",
months = yes,
weekdays = yes,
input_month = yes,
input_day_of_month = yes,
input_day_of_week = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
YMD,
YMDT,
description = "year, month, and day",
sample_length = short,
sample = "5/17/24",
sample_time = "5/17/24, 3:47:50 PM",
years = yes,
months = yes,
input_year = yes,
input_month = yes,
input_day_of_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
YMDE,
YMDET,
description = "year, month, day, and weekday",
sample_length = short,
sample = "Fri, 5/17/24",
sample_time = "Fri, 5/17/24, 3:47:50 PM",
years = yes,
months = yes,
weekdays = yes,
input_year = yes,
input_month = yes,
input_day_of_month = yes,
input_day_of_week = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_calendar_period_marker!(
Y,
description = "year (standalone)",
sample_length = medium,
sample = "2024",
years = yes,
input_year = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_calendar_period_marker!(
M,
description = "month (standalone)",
sample_length = long,
sample = "May",
months = yes,
input_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_calendar_period_marker!(
YM,
description = "year and month",
sample_length = medium,
sample = "May 2024",
years = yes,
months = yes,
input_year = yes,
input_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_time_marker!(
T,
description = "time (locale-dependent hour cycle)",
sample_length = medium,
sample = "3:47:50 PM",
dayperiods = yes,
input_hour = yes,
input_minute = yes,
input_second = yes,
input_nanosecond = yes,
);
impl_zone_marker!(
Z,
description = "time zone in specific non-location format",
sample_length = long,
sample = "Central Daylight Time",
field_short = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::Four),
resolved_type = Z,
zone_essentials = yes,
zone_locations = yes,
zone_specific_long = yes,
zone_specific_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_variant = yes,
input_localtime = yes,
enumerated = yes,
);
impl_zone_marker!(
Zs,
description = "time zone in specific non-location format (only short)",
sample_length = short,
sample = "CDT",
field_short = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::One),
resolved_type = Z,
skip_tests = "This field set can be used only in combination with others.",
zone_essentials = yes,
zone_specific_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_variant = yes,
input_localtime = yes,
);
impl_zone_marker!(
O,
description = "UTC offset",
sample_length = medium,
sample = "GMT-5",
field_short = (fields::TimeZone::LocalizedOffset, fields::FieldLength::One),
field_long = (fields::TimeZone::LocalizedOffset, fields::FieldLength::Four),
resolved_type = O,
zone_essentials = yes,
enumerated = yes,
);
impl_zone_marker!(
V,
description = "time zone in generic non-location format",
sample_length = long,
sample = "Central Time",
field_short = (fields::TimeZone::GenericNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::GenericNonLocation, fields::FieldLength::Four),
resolved_type = V,
zone_essentials = yes,
zone_locations = yes,
zone_generic_long = yes,
zone_generic_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_localtime = yes,
enumerated = yes,
);
impl_zone_marker!(
Vs,
description = "time zone in generic non-location format (only short)",
sample_length = short,
sample = "CT",
field_short = (fields::TimeZone::GenericNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::GenericNonLocation, fields::FieldLength::One),
resolved_type = V,
skip_tests = "This field set can be used only in combination with others.",
zone_essentials = yes,
zone_locations = yes,
zone_generic_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_localtime = yes,
);
impl_zone_marker!(
L,
description = "time zone in location format",
sample_length = long,
sample = "Chicago Time",
field_short = (fields::TimeZone::Location, fields::FieldLength::Four),
field_long = (fields::TimeZone::Location, fields::FieldLength::Four),
resolved_type = L,
zone_essentials = yes,
zone_locations = yes,
input_tzid = yes,
enumerated = yes,
);
impl_zoneddatetime_marker!(
YMDTV,
description = "locale-dependent date and time fields with a time zone",
sample_length = medium,
sample = "17 May 2024, 15:47:50 GMT",
datetime = YMDT,
zone = Vs,
);
impl_zoneddatetime_marker!(
YMDTZ,
description = "locale-dependent date and time fields with a time zone",
sample_length = medium,
sample = "17 May 2024, 15:47:50 BST",
datetime = YMDT,
zone = Zs,
);
impl_zoneddatetime_marker!(
YMDTO,
description = "locale-dependent date and time fields with a time zone",
sample_length = medium,
sample = "17 May 2024, 15:47:50 GMT+1",
datetime = YMDT,
zone = O,
);
impl_zone_combo_helpers!(DateFieldSet, DateZone, UNREACHABLE, no_wrap);
impl_zone_combo_helpers!(TimeFieldSet, TimeZone, UNREACHABLE, no_wrap);
impl_zone_combo_helpers!(DateAndTimeFieldSet, DateTimeZone, UNREACHABLE, no_wrap);