use super::{
DateTimePattern, DateTimePatternFormatter, GetNameForCyclicYearError, GetNameForDayPeriodError,
GetNameForEraError, GetNameForMonthError, GetNameForWeekdayError, MonthPlaceholderValue,
PatternLoadError, UnsupportedCalendarError,
};
use crate::error::ErrorField;
use crate::fieldsets::enums::{CompositeDateTimeFieldSet, CompositeFieldSet};
use crate::provider::fields::{self, FieldLength, FieldSymbol};
use crate::provider::names::*;
use crate::provider::pattern::PatternItem;
use crate::provider::semantic_skeletons::marker_attrs;
use crate::provider::time_zones::tz;
use crate::size_test_macro::size_test;
use crate::FixedCalendarDateTimeFormatter;
use crate::{external_loaders::*, DateTimeFormatterPreferences};
use crate::{scaffold::*, DateTimeFormatter, DateTimeFormatterLoadError};
use core::fmt;
use core::marker::PhantomData;
use icu_calendar::types::{EraYear, LeapStatus, MonthInfo};
use icu_calendar::AnyCalendar;
use icu_decimal::options::DecimalFormatterOptions;
use icu_decimal::options::GroupingStrategy;
use icu_decimal::provider::{DecimalDigitsV1, DecimalSymbolsV1};
use icu_decimal::DecimalFormatter;
use icu_pattern::SinglePlaceholderPattern;
use icu_provider::prelude::*;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum YearNameLength {
Abbreviated,
Wide,
Narrow,
}
impl YearNameLength {
pub(crate) fn to_attributes(self) -> &'static DataMarkerAttributes {
use marker_attrs::Length;
let length = match self {
YearNameLength::Abbreviated => Length::Abbr,
YearNameLength::Wide => Length::Wide,
YearNameLength::Narrow => Length::Narrow,
};
marker_attrs::name_attr_for(marker_attrs::Context::Format, length)
}
pub(crate) fn from_field_length(field_length: FieldLength) -> Option<Self> {
let field_length = field_length.numeric_to_abbr();
match field_length {
FieldLength::Three => Some(YearNameLength::Abbreviated),
FieldLength::Four => Some(YearNameLength::Wide),
FieldLength::Five => Some(YearNameLength::Narrow),
_ => None,
}
}
pub(crate) fn to_approximate_error_field(self) -> ErrorField {
let field_length = match self {
YearNameLength::Abbreviated => FieldLength::Three,
YearNameLength::Wide => FieldLength::Four,
YearNameLength::Narrow => FieldLength::Five,
};
ErrorField(fields::Field {
symbol: FieldSymbol::Era,
length: field_length,
})
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum MonthNameLength {
Abbreviated,
Wide,
Narrow,
StandaloneAbbreviated,
StandaloneWide,
StandaloneNarrow,
}
impl MonthNameLength {
pub(crate) fn to_attributes(self) -> &'static DataMarkerAttributes {
use marker_attrs::{Context, Length};
let (context, length) = match self {
MonthNameLength::Abbreviated => (Context::Format, Length::Abbr),
MonthNameLength::Wide => (Context::Format, Length::Wide),
MonthNameLength::Narrow => (Context::Format, Length::Narrow),
MonthNameLength::StandaloneAbbreviated => (Context::Standalone, Length::Abbr),
MonthNameLength::StandaloneWide => (Context::Standalone, Length::Wide),
MonthNameLength::StandaloneNarrow => (Context::Standalone, Length::Narrow),
};
marker_attrs::name_attr_for(context, length)
}
pub(crate) fn from_field(
field_symbol: fields::Month,
field_length: FieldLength,
) -> Option<Self> {
use fields::Month;
match (field_symbol, field_length) {
(Month::Format, FieldLength::Three) => Some(MonthNameLength::Abbreviated),
(Month::Format, FieldLength::Four) => Some(MonthNameLength::Wide),
(Month::Format, FieldLength::Five) => Some(MonthNameLength::Narrow),
(Month::StandAlone, FieldLength::Three) => Some(MonthNameLength::StandaloneAbbreviated),
(Month::StandAlone, FieldLength::Four) => Some(MonthNameLength::StandaloneWide),
(Month::StandAlone, FieldLength::Five) => Some(MonthNameLength::StandaloneNarrow),
_ => None,
}
}
pub(crate) fn to_approximate_error_field(self) -> ErrorField {
use fields::Month;
let (field_symbol, field_length) = match self {
MonthNameLength::Abbreviated => (Month::Format, FieldLength::Three),
MonthNameLength::Wide => (Month::Format, FieldLength::Four),
MonthNameLength::Narrow => (Month::Format, FieldLength::Five),
MonthNameLength::StandaloneAbbreviated => (Month::StandAlone, FieldLength::Three),
MonthNameLength::StandaloneWide => (Month::StandAlone, FieldLength::Four),
MonthNameLength::StandaloneNarrow => (Month::StandAlone, FieldLength::Five),
};
ErrorField(fields::Field {
symbol: FieldSymbol::Month(field_symbol),
length: field_length,
})
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum WeekdayNameLength {
Abbreviated,
Wide,
Narrow,
Short,
StandaloneAbbreviated,
StandaloneWide,
StandaloneNarrow,
StandaloneShort,
}
impl WeekdayNameLength {
pub(crate) fn to_attributes(self) -> &'static DataMarkerAttributes {
use marker_attrs::{Context, Length};
let (context, length) = match self {
WeekdayNameLength::Abbreviated => (Context::Format, Length::Abbr),
WeekdayNameLength::Wide => (Context::Format, Length::Wide),
WeekdayNameLength::Narrow => (Context::Format, Length::Narrow),
WeekdayNameLength::Short => (Context::Format, Length::Short),
WeekdayNameLength::StandaloneAbbreviated => (Context::Standalone, Length::Abbr),
WeekdayNameLength::StandaloneWide => (Context::Standalone, Length::Wide),
WeekdayNameLength::StandaloneNarrow => (Context::Standalone, Length::Narrow),
WeekdayNameLength::StandaloneShort => (Context::Standalone, Length::Short),
};
marker_attrs::name_attr_for(context, length)
}
pub(crate) fn from_field(
field_symbol: fields::Weekday,
field_length: FieldLength,
) -> Option<Self> {
use fields::Weekday;
let field_symbol = field_symbol.to_format_symbol();
let field_length = if matches!(field_symbol, Weekday::Format) {
field_length.numeric_to_abbr()
} else {
field_length
};
match (field_symbol, field_length) {
(Weekday::Format, FieldLength::Three) => Some(WeekdayNameLength::Abbreviated),
(Weekday::Format, FieldLength::Four) => Some(WeekdayNameLength::Wide),
(Weekday::Format, FieldLength::Five) => Some(WeekdayNameLength::Narrow),
(Weekday::Format, FieldLength::Six) => Some(WeekdayNameLength::Short),
(Weekday::StandAlone, FieldLength::Three) => {
Some(WeekdayNameLength::StandaloneAbbreviated)
}
(Weekday::StandAlone, FieldLength::Four) => Some(WeekdayNameLength::StandaloneWide),
(Weekday::StandAlone, FieldLength::Five) => Some(WeekdayNameLength::StandaloneNarrow),
(Weekday::StandAlone, FieldLength::Six) => Some(WeekdayNameLength::StandaloneShort),
_ => None,
}
}
pub(crate) fn to_approximate_error_field(self) -> ErrorField {
use fields::Weekday;
let (field_symbol, field_length) = match self {
WeekdayNameLength::Abbreviated => (Weekday::Format, FieldLength::Three),
WeekdayNameLength::Wide => (Weekday::Format, FieldLength::Four),
WeekdayNameLength::Narrow => (Weekday::Format, FieldLength::Five),
WeekdayNameLength::Short => (Weekday::Format, FieldLength::Six),
WeekdayNameLength::StandaloneAbbreviated => (Weekday::StandAlone, FieldLength::Three),
WeekdayNameLength::StandaloneWide => (Weekday::StandAlone, FieldLength::Four),
WeekdayNameLength::StandaloneNarrow => (Weekday::StandAlone, FieldLength::Five),
WeekdayNameLength::StandaloneShort => (Weekday::StandAlone, FieldLength::Six),
};
ErrorField(fields::Field {
symbol: FieldSymbol::Weekday(field_symbol),
length: field_length,
})
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DayPeriodNameLength {
Abbreviated,
Wide,
Narrow,
}
impl DayPeriodNameLength {
pub(crate) fn to_attributes(self) -> &'static DataMarkerAttributes {
use marker_attrs::Length;
let length = match self {
DayPeriodNameLength::Abbreviated => Length::Abbr,
DayPeriodNameLength::Wide => Length::Wide,
DayPeriodNameLength::Narrow => Length::Narrow,
};
marker_attrs::name_attr_for(marker_attrs::Context::Format, length)
}
pub(crate) fn from_field(
field_symbol: fields::DayPeriod,
field_length: FieldLength,
) -> Option<Self> {
use fields::DayPeriod;
let field_symbol = match field_symbol {
DayPeriod::NoonMidnight => DayPeriod::AmPm,
other => other,
};
let field_length = field_length.numeric_to_abbr();
match (field_symbol, field_length) {
(DayPeriod::AmPm, FieldLength::Three) => Some(DayPeriodNameLength::Abbreviated),
(DayPeriod::AmPm, FieldLength::Four) => Some(DayPeriodNameLength::Wide),
(DayPeriod::AmPm, FieldLength::Five) => Some(DayPeriodNameLength::Narrow),
_ => None,
}
}
pub(crate) fn to_approximate_error_field(self) -> ErrorField {
let field_symbol = fields::DayPeriod::AmPm;
let field_length = match self {
DayPeriodNameLength::Abbreviated => FieldLength::Three,
DayPeriodNameLength::Wide => FieldLength::Four,
DayPeriodNameLength::Narrow => FieldLength::Five,
};
ErrorField(fields::Field {
symbol: FieldSymbol::DayPeriod(field_symbol),
length: field_length,
})
}
}
pub(crate) struct EmptyDataProvider;
impl<M> DataProvider<M> for EmptyDataProvider
where
M: DataMarker,
{
fn load(&self, base_req: DataRequest) -> Result<DataResponse<M>, DataError> {
Err(DataErrorKind::MarkerNotFound.with_req(M::INFO, base_req))
}
}
size_test!(
FixedCalendarDateTimeNames<icu_calendar::Gregorian>,
typed_date_time_names_size,
328
);
#[doc = typed_date_time_names_size!()]
#[derive(Debug, Clone)]
pub struct FixedCalendarDateTimeNames<C, FSet: DateTimeNamesMarker = CompositeDateTimeFieldSet> {
prefs: DateTimeFormatterPreferences,
inner: RawDateTimeNames<FSet>,
metadata: DateTimeNamesMetadata,
_calendar: PhantomData<C>,
}
#[derive(Debug, Clone)]
pub(crate) struct DateTimeNamesMetadata {
zone_checksum: Option<u64>,
}
impl DateTimeNamesMetadata {
#[inline]
pub(crate) fn new_empty() -> Self {
Self {
zone_checksum: None,
}
}
#[inline]
pub(crate) fn new_from_previous<M: DateTimeNamesMarker>(names: &RawDateTimeNames<M>) -> Self {
if names.mz_periods.get().inner.get_option().is_some() {
Self {
zone_checksum: Some(0),
}
} else {
Self::new_empty()
}
}
}
#[derive(Debug, Clone)]
pub struct DateTimeNames<FSet: DateTimeNamesMarker> {
inner: FixedCalendarDateTimeNames<(), FSet>,
calendar: FormattableAnyCalendar,
}
pub(crate) struct RawDateTimeNames<FSet: DateTimeNamesMarker> {
year_names: <FSet::YearNames as NamesContainer<YearNamesV1, YearNameLength>>::Container,
month_names: <FSet::MonthNames as NamesContainer<MonthNamesV1, MonthNameLength>>::Container,
weekday_names:
<FSet::WeekdayNames as NamesContainer<WeekdayNamesV1, WeekdayNameLength>>::Container,
dayperiod_names:
<FSet::DayPeriodNames as NamesContainer<DayPeriodNamesV1, DayPeriodNameLength>>::Container,
zone_essentials: <FSet::ZoneEssentials as NamesContainer<tz::EssentialsV1, ()>>::Container,
locations_root: <FSet::ZoneLocationsRoot as NamesContainer<tz::LocationsRootV1, ()>>::Container,
locations: <FSet::ZoneLocations as NamesContainer<tz::LocationsOverrideV1, ()>>::Container,
exemplars_root: <FSet::ZoneExemplarsRoot as NamesContainer<tz::CitiesRootV1, ()>>::Container,
exemplars: <FSet::ZoneExemplars as NamesContainer<tz::CitiesOverrideV1, ()>>::Container,
mz_generic_long: <FSet::ZoneGenericLong as NamesContainer<tz::MzGenericLongV1, ()>>::Container,
mz_generic_short:
<FSet::ZoneGenericShort as NamesContainer<tz::MzGenericShortV1, ()>>::Container,
mz_standard_long:
<FSet::ZoneStandardLong as NamesContainer<tz::MzStandardLongV1, ()>>::Container,
mz_specific_long:
<FSet::ZoneSpecificLong as NamesContainer<tz::MzSpecificLongV1, ()>>::Container,
mz_specific_short:
<FSet::ZoneSpecificShort as NamesContainer<tz::MzSpecificShortV1, ()>>::Container,
mz_periods: <FSet::MetazoneLookup as NamesContainer<tz::MzPeriodV1, ()>>::Container,
decimal_formatter: Option<DecimalFormatter>,
_marker: PhantomData<FSet>,
}
impl<FSet: DateTimeNamesMarker> fmt::Debug for RawDateTimeNames<FSet> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RawDateTimeNames")
.field("year_names", &self.year_names)
.field("month_names", &self.month_names)
.field("weekday_names", &self.weekday_names)
.field("dayperiod_names", &self.dayperiod_names)
.field("zone_essentials", &self.zone_essentials)
.field("locations_root", &self.locations_root)
.field("locations", &self.locations)
.field("exemplars_root", &self.exemplars_root)
.field("exemplars", &self.exemplars)
.field("mz_generic_long", &self.mz_generic_long)
.field("mz_generic_short", &self.mz_generic_short)
.field("mz_standard_long", &self.mz_standard_long)
.field("mz_specific_long", &self.mz_specific_long)
.field("mz_specific_short", &self.mz_specific_short)
.field("mz_periods", &self.mz_periods)
.field("decimal_formatter", &self.decimal_formatter)
.finish()
}
}
impl<FSet: DateTimeNamesMarker> Clone for RawDateTimeNames<FSet> {
fn clone(&self) -> Self {
Self {
year_names: self.year_names.clone(),
month_names: self.month_names.clone(),
weekday_names: self.weekday_names.clone(),
dayperiod_names: self.dayperiod_names.clone(),
zone_essentials: self.zone_essentials.clone(),
locations_root: self.locations_root.clone(),
locations: self.locations.clone(),
exemplars_root: self.exemplars_root.clone(),
exemplars: self.exemplars.clone(),
mz_generic_long: self.mz_generic_long.clone(),
mz_generic_short: self.mz_generic_short.clone(),
mz_standard_long: self.mz_standard_long.clone(),
mz_specific_long: self.mz_specific_long.clone(),
mz_specific_short: self.mz_specific_short.clone(),
mz_periods: self.mz_periods.clone(),
decimal_formatter: self.decimal_formatter.clone(),
_marker: PhantomData,
}
}
}
impl<FSet: DateTimeNamesMarker> RawDateTimeNames<FSet> {
pub(crate) fn cast_into_fset<FSet2: DateTimeNamesFrom<FSet>>(self) -> RawDateTimeNames<FSet2> {
RawDateTimeNames {
year_names: FSet2::map_year_names(self.year_names),
month_names: FSet2::map_month_names(self.month_names),
weekday_names: FSet2::map_weekday_names(self.weekday_names),
dayperiod_names: FSet2::map_day_period_names(self.dayperiod_names),
zone_essentials: FSet2::map_zone_essentials(self.zone_essentials),
locations_root: FSet2::map_zone_locations_root(self.locations_root),
locations: FSet2::map_zone_locations(self.locations),
exemplars_root: FSet2::map_zone_exemplars_root(self.exemplars_root),
exemplars: FSet2::map_zone_exemplars(self.exemplars),
mz_generic_long: FSet2::map_zone_generic_long(self.mz_generic_long),
mz_generic_short: FSet2::map_zone_generic_short(self.mz_generic_short),
mz_standard_long: FSet2::map_zone_standard_long(self.mz_standard_long),
mz_specific_long: FSet2::map_zone_specific_long(self.mz_specific_long),
mz_specific_short: FSet2::map_zone_specific_short(self.mz_specific_short),
mz_periods: FSet2::map_metazone_lookup(self.mz_periods),
decimal_formatter: self.decimal_formatter,
_marker: PhantomData,
}
}
}
#[derive(Debug, Copy, Clone)]
pub(crate) struct RawDateTimeNamesBorrowed<'l> {
year_names: OptionalNames<YearNameLength, &'l YearNames<'l>>,
month_names: OptionalNames<MonthNameLength, &'l MonthNames<'l>>,
weekday_names: OptionalNames<WeekdayNameLength, &'l LinearNames<'l>>,
dayperiod_names: OptionalNames<DayPeriodNameLength, &'l LinearNames<'l>>,
zone_essentials: OptionalNames<(), &'l tz::Essentials<'l>>,
locations_root: OptionalNames<(), &'l tz::Locations<'l>>,
locations: OptionalNames<(), &'l tz::Locations<'l>>,
exemplars_root: OptionalNames<(), &'l tz::ExemplarCities<'l>>,
exemplars: OptionalNames<(), &'l tz::ExemplarCities<'l>>,
mz_generic_long: OptionalNames<(), &'l tz::MzGeneric<'l>>,
mz_standard_long: OptionalNames<(), &'l tz::MzGeneric<'l>>,
mz_generic_short: OptionalNames<(), &'l tz::MzGeneric<'l>>,
mz_specific_long: OptionalNames<(), &'l tz::MzSpecific<'l>>,
mz_specific_short: OptionalNames<(), &'l tz::MzSpecific<'l>>,
mz_periods: OptionalNames<(), &'l tz::MzPeriod<'l>>,
pub(crate) decimal_formatter: Option<&'l DecimalFormatter>,
}
impl<C, FSet: DateTimeNamesMarker> FixedCalendarDateTimeNames<C, FSet> {
#[cfg(feature = "compiled_data")]
pub fn try_new(prefs: DateTimeFormatterPreferences) -> Result<Self, DataError> {
let mut names = Self {
prefs,
inner: RawDateTimeNames::new_without_number_formatting(),
metadata: DateTimeNamesMetadata::new_empty(), _calendar: PhantomData,
};
names.include_decimal_formatter()?;
Ok(names)
}
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
pub fn try_new_unstable<P>(
provider: &P,
prefs: DateTimeFormatterPreferences,
) -> Result<Self, DataError>
where
P: DataProvider<DecimalSymbolsV1> + DataProvider<DecimalDigitsV1> + ?Sized,
{
let mut names = Self {
prefs,
inner: RawDateTimeNames::new_without_number_formatting(),
metadata: DateTimeNamesMetadata::new_empty(), _calendar: PhantomData,
};
names.load_decimal_formatter(provider)?;
Ok(names)
}
icu_provider::gen_buffer_data_constructors!(
(prefs: DateTimeFormatterPreferences) -> error: DataError,
functions: [
try_new: skip,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]
);
pub fn new_without_number_formatting(prefs: DateTimeFormatterPreferences) -> Self {
Self {
prefs,
inner: RawDateTimeNames::new_without_number_formatting(),
metadata: DateTimeNamesMetadata::new_empty(), _calendar: PhantomData,
}
}
}
impl<C: CldrCalendar, FSet: DateTimeNamesMarker> FixedCalendarDateTimeNames<C, FSet> {
pub fn from_formatter(
prefs: DateTimeFormatterPreferences,
formatter: FixedCalendarDateTimeFormatter<C, FSet>,
) -> Self {
let metadata = DateTimeNamesMetadata::new_from_previous(&formatter.names);
Self {
prefs,
inner: formatter.names,
metadata,
_calendar: PhantomData,
}
}
fn from_parts(
prefs: DateTimeFormatterPreferences,
parts: (RawDateTimeNames<FSet>, DateTimeNamesMetadata),
) -> Self {
Self {
prefs,
inner: parts.0,
metadata: parts.1,
_calendar: PhantomData,
}
}
}
impl<C: CldrCalendar, FSet: DateTimeMarkers> FixedCalendarDateTimeNames<C, FSet>
where
FSet::D: TypedDateDataMarkers<C>,
FSet::T: TimeMarkers,
FSet::Z: ZoneMarkers,
FSet: GetField<CompositeFieldSet>,
{
#[expect(clippy::result_large_err)] #[cfg(feature = "compiled_data")]
pub fn try_into_formatter(
self,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, (DateTimeFormatterLoadError, Self)>
where
crate::provider::Baked: AllFixedCalendarPatternDataMarkers<C, FSet>,
{
FixedCalendarDateTimeFormatter::try_new_internal_with_names(
&crate::provider::Baked,
&EmptyDataProvider,
&ExternalLoaderUnstable(&EmptyDataProvider), self.prefs,
field_set.get_field(),
self.inner,
self.metadata,
)
.map_err(|e| (e.0, Self::from_parts(self.prefs, e.1)))
}
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::try_into_formatter)]
#[expect(clippy::result_large_err)] pub fn try_into_formatter_unstable<P>(
self,
provider: &P,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, (DateTimeFormatterLoadError, Self)>
where
P: AllFixedCalendarPatternDataMarkers<C, FSet> + ?Sized,
{
FixedCalendarDateTimeFormatter::try_new_internal_with_names(
provider,
&EmptyDataProvider,
&ExternalLoaderUnstable(&EmptyDataProvider), self.prefs,
field_set.get_field(),
self.inner,
self.metadata,
)
.map_err(|e| (e.0, Self::from_parts(self.prefs, e.1)))
}
#[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER, Self::try_into_formatter)]
#[expect(clippy::result_large_err)] #[cfg(feature = "serde")]
pub fn try_into_formatter_with_buffer_provider<P>(
self,
provider: &P,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, (DateTimeFormatterLoadError, Self)>
where
P: BufferProvider + ?Sized,
{
FixedCalendarDateTimeFormatter::try_new_internal_with_names(
&provider.as_deserializing(),
&EmptyDataProvider,
&ExternalLoaderUnstable(&EmptyDataProvider), self.prefs,
field_set.get_field(),
self.inner,
self.metadata,
)
.map_err(|e| (e.0, Self::from_parts(self.prefs, e.1)))
}
}
impl<FSet: DateTimeNamesMarker> DateTimeNames<FSet> {
pub fn try_new_with_calendar_without_number_formatting(
prefs: DateTimeFormatterPreferences,
calendar: AnyCalendar,
) -> Result<Self, UnsupportedCalendarError> {
let calendar = FormattableAnyCalendar::try_from_any_calendar(calendar)
.map_err(|c| UnsupportedCalendarError { kind: c.kind() })?;
Ok(Self {
inner: FixedCalendarDateTimeNames::new_without_number_formatting(prefs),
calendar,
})
}
pub fn from_formatter(
prefs: DateTimeFormatterPreferences,
formatter: DateTimeFormatter<FSet>,
) -> Self {
let metadata = DateTimeNamesMetadata::new_from_previous(&formatter.names);
Self::from_parts(prefs, (formatter.calendar, formatter.names, metadata))
}
fn from_parts(
prefs: DateTimeFormatterPreferences,
parts: (
FormattableAnyCalendar,
RawDateTimeNames<FSet>,
DateTimeNamesMetadata,
),
) -> Self {
Self {
inner: FixedCalendarDateTimeNames {
prefs,
inner: parts.1,
metadata: parts.2,
_calendar: PhantomData,
},
calendar: parts.0,
}
}
}
impl<FSet: DateTimeMarkers> DateTimeNames<FSet>
where
FSet::D: DateDataMarkers,
FSet::T: TimeMarkers,
FSet::Z: ZoneMarkers,
FSet: GetField<CompositeFieldSet>,
{
#[expect(clippy::result_large_err)] #[cfg(feature = "compiled_data")]
pub fn try_into_formatter(
self,
field_set: FSet,
) -> Result<DateTimeFormatter<FSet>, (DateTimeFormatterLoadError, Self)>
where
crate::provider::Baked: AllAnyCalendarPatternDataMarkers<FSet>,
{
DateTimeFormatter::try_new_internal_with_calendar_and_names(
&crate::provider::Baked,
&EmptyDataProvider,
&ExternalLoaderUnstable(&EmptyDataProvider), self.inner.prefs,
field_set.get_field(),
self.calendar,
self.inner.inner,
self.inner.metadata,
)
.map_err(|e| (e.0, Self::from_parts(self.inner.prefs, e.1)))
}
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::try_into_formatter)]
#[expect(clippy::result_large_err)] pub fn try_into_formatter_unstable<P>(
self,
provider: &P,
field_set: FSet,
) -> Result<DateTimeFormatter<FSet>, (DateTimeFormatterLoadError, Self)>
where
P: AllAnyCalendarPatternDataMarkers<FSet> + ?Sized,
{
DateTimeFormatter::try_new_internal_with_calendar_and_names(
provider,
&EmptyDataProvider,
&ExternalLoaderUnstable(&EmptyDataProvider), self.inner.prefs,
field_set.get_field(),
self.calendar,
self.inner.inner,
self.inner.metadata,
)
.map_err(|e| (e.0, Self::from_parts(self.inner.prefs, e.1)))
}
#[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER, Self::try_into_formatter)]
#[expect(clippy::result_large_err)] #[cfg(feature = "serde")]
pub fn try_into_formatter_with_buffer_provider<P>(
self,
provider: &P,
field_set: FSet,
) -> Result<DateTimeFormatter<FSet>, (DateTimeFormatterLoadError, Self)>
where
P: BufferProvider + ?Sized,
{
DateTimeFormatter::try_new_internal_with_calendar_and_names(
&provider.as_deserializing(),
&EmptyDataProvider,
&ExternalLoaderUnstable(&EmptyDataProvider), self.inner.prefs,
field_set.get_field(),
self.calendar,
self.inner.inner,
self.inner.metadata,
)
.map_err(|e| (e.0, Self::from_parts(self.inner.prefs, e.1)))
}
}
impl<FSet: DateTimeNamesMarker> AsRef<FixedCalendarDateTimeNames<(), FSet>>
for DateTimeNames<FSet>
{
fn as_ref(&self) -> &FixedCalendarDateTimeNames<(), FSet> {
&self.inner
}
}
impl<FSet: DateTimeNamesMarker> AsMut<FixedCalendarDateTimeNames<(), FSet>>
for DateTimeNames<FSet>
{
fn as_mut(&mut self) -> &mut FixedCalendarDateTimeNames<(), FSet> {
&mut self.inner
}
}
impl<C: CldrCalendar, FSet: DateTimeNamesMarker> FixedCalendarDateTimeNames<C, FSet> {
pub fn load_year_names<P>(
&mut self,
provider: &P,
length: YearNameLength,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<C::YearNamesV1> + ?Sized,
{
self.inner.load_year_names(
&C::YearNamesV1::bind(provider),
self.prefs,
length,
length.to_approximate_error_field(),
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_year_names(
&mut self,
length: YearNameLength,
) -> Result<&mut Self, PatternLoadError>
where
crate::provider::Baked: DataProvider<<C as CldrCalendar>::YearNamesV1>,
{
self.load_year_names(&crate::provider::Baked, length)
}
pub fn load_month_names<P>(
&mut self,
provider: &P,
length: MonthNameLength,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<C::MonthNamesV1> + ?Sized,
{
self.inner.load_month_names(
&C::MonthNamesV1::bind(provider),
self.prefs,
length,
length.to_approximate_error_field(),
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_month_names(
&mut self,
length: MonthNameLength,
) -> Result<&mut Self, PatternLoadError>
where
crate::provider::Baked: DataProvider<<C as CldrCalendar>::MonthNamesV1>,
{
self.load_month_names(&crate::provider::Baked, length)
}
}
impl<C, FSet: DateTimeNamesMarker> FixedCalendarDateTimeNames<C, FSet> {
pub fn load_day_period_names<P>(
&mut self,
provider: &P,
length: DayPeriodNameLength,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<DayPeriodNamesV1> + ?Sized,
{
let provider = DayPeriodNamesV1::bind(provider);
self.inner.load_day_period_names(
&provider,
self.prefs,
length,
length.to_approximate_error_field(),
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_day_period_names(
&mut self,
length: DayPeriodNameLength,
) -> Result<&mut Self, PatternLoadError> {
self.load_day_period_names(&crate::provider::Baked, length)
}
pub fn load_weekday_names<P>(
&mut self,
provider: &P,
length: WeekdayNameLength,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<WeekdayNamesV1> + ?Sized,
{
self.inner.load_weekday_names(
&WeekdayNamesV1::bind(provider),
self.prefs,
length,
length.to_approximate_error_field(),
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_weekday_names(
&mut self,
length: WeekdayNameLength,
) -> Result<&mut Self, PatternLoadError> {
self.load_weekday_names(&crate::provider::Baked, length)
}
pub fn load_time_zone_essentials<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<tz::EssentialsV1> + ?Sized,
{
self.inner
.load_time_zone_essentials(&tz::EssentialsV1::bind(provider), self.prefs)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_essentials(&mut self) -> Result<&mut Self, PatternLoadError> {
self.load_time_zone_essentials(&crate::provider::Baked)
}
pub fn load_time_zone_location_names<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<tz::LocationsOverrideV1> + DataProvider<tz::LocationsRootV1> + ?Sized,
{
self.inner.load_time_zone_location_names(
&tz::LocationsOverrideV1::bind(provider),
&tz::LocationsRootV1::bind(provider),
self.prefs,
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_location_names(&mut self) -> Result<&mut Self, PatternLoadError> {
self.load_time_zone_location_names(&crate::provider::Baked)
}
pub fn load_time_zone_exemplar_city_names<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<tz::CitiesOverrideV1> + DataProvider<tz::CitiesRootV1> + ?Sized,
{
self.inner.load_time_zone_exemplar_city_names(
&tz::CitiesOverrideV1::bind(provider),
&tz::CitiesRootV1::bind(provider),
self.prefs,
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_exemplar_city_names(&mut self) -> Result<&mut Self, PatternLoadError> {
self.load_time_zone_exemplar_city_names(&crate::provider::Baked)
}
pub fn load_time_zone_generic_long_names<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<tz::MzGenericLongV1>
+ DataProvider<tz::MzStandardLongV1>
+ DataProvider<tz::MzPeriodV1>
+ ?Sized,
{
self.inner.load_time_zone_generic_long_names(
&tz::MzGenericLongV1::bind(provider),
&tz::MzStandardLongV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_generic_long_names(&mut self) -> Result<&mut Self, PatternLoadError> {
self.load_time_zone_generic_long_names(&crate::provider::Baked)
}
pub fn load_time_zone_generic_short_names<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<tz::MzGenericShortV1> + DataProvider<tz::MzPeriodV1> + ?Sized,
{
self.inner.load_time_zone_generic_short_names(
&tz::MzGenericShortV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_generic_short_names(&mut self) -> Result<&mut Self, PatternLoadError> {
self.load_time_zone_generic_short_names(&crate::provider::Baked)
}
pub fn load_time_zone_specific_long_names<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<tz::MzSpecificLongV1>
+ DataProvider<tz::MzStandardLongV1>
+ DataProvider<tz::MzPeriodV1>
+ ?Sized,
{
self.inner.load_time_zone_specific_long_names(
&tz::MzSpecificLongV1::bind(provider),
&tz::MzStandardLongV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_specific_long_names(&mut self) -> Result<&mut Self, PatternLoadError> {
self.load_time_zone_specific_long_names(&crate::provider::Baked)
}
pub fn load_time_zone_specific_short_names<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<tz::MzSpecificShortV1> + DataProvider<tz::MzPeriodV1> + ?Sized,
{
self.inner.load_time_zone_specific_short_names(
&tz::MzSpecificShortV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_specific_short_names(
&mut self,
) -> Result<&mut Self, PatternLoadError> {
self.load_time_zone_specific_short_names(&crate::provider::Baked)
}
pub fn load_time_zone_generic_short_names_with_fallback<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<DecimalSymbolsV1>
+ DataProvider<DecimalDigitsV1>
+ DataProvider<tz::EssentialsV1>
+ DataProvider<tz::LocationsOverrideV1>
+ DataProvider<tz::LocationsRootV1>
+ DataProvider<tz::MzGenericShortV1>
+ DataProvider<tz::MzPeriodV1>
+ ?Sized,
{
let error_field = self.inner.load_time_zone_field_v_except_decimals(
&tz::EssentialsV1::bind(provider),
&tz::LocationsOverrideV1::bind(provider),
&tz::LocationsRootV1::bind(provider),
&tz::MzGenericShortV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
self.load_decimal_formatter(provider)
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_generic_short_names_with_fallback(
&mut self,
) -> Result<&mut Self, PatternLoadError> {
let error_field = self.inner.load_time_zone_field_v_except_decimals(
&tz::EssentialsV1::bind(&crate::provider::Baked),
&tz::LocationsOverrideV1::bind(&crate::provider::Baked),
&tz::LocationsRootV1::bind(&crate::provider::Baked),
&tz::MzGenericShortV1::bind(&crate::provider::Baked),
&tz::MzPeriodV1::bind(&crate::provider::Baked),
self.prefs,
&mut self.metadata,
)?;
self.include_decimal_formatter()
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
pub fn load_time_zone_generic_long_names_with_fallback<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<DecimalSymbolsV1>
+ DataProvider<DecimalDigitsV1>
+ DataProvider<tz::EssentialsV1>
+ DataProvider<tz::LocationsOverrideV1>
+ DataProvider<tz::LocationsRootV1>
+ DataProvider<tz::MzGenericLongV1>
+ DataProvider<tz::MzStandardLongV1>
+ DataProvider<tz::MzPeriodV1>
+ ?Sized,
{
let error_field = self.inner.load_time_zone_field_vvvv_except_decimals(
&tz::EssentialsV1::bind(provider),
&tz::LocationsOverrideV1::bind(provider),
&tz::LocationsRootV1::bind(provider),
&tz::MzGenericLongV1::bind(provider),
&tz::MzStandardLongV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
self.load_decimal_formatter(provider)
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_generic_long_names_with_fallback(
&mut self,
) -> Result<&mut Self, PatternLoadError> {
let error_field = self.inner.load_time_zone_field_vvvv_except_decimals(
&tz::EssentialsV1::bind(&crate::provider::Baked),
&tz::LocationsOverrideV1::bind(&crate::provider::Baked),
&tz::LocationsRootV1::bind(&crate::provider::Baked),
&tz::MzGenericLongV1::bind(&crate::provider::Baked),
&tz::MzStandardLongV1::bind(&crate::provider::Baked),
&tz::MzPeriodV1::bind(&crate::provider::Baked),
self.prefs,
&mut self.metadata,
)?;
self.include_decimal_formatter()
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
pub fn load_time_zone_specific_short_names_with_fallback<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<DecimalSymbolsV1>
+ DataProvider<DecimalDigitsV1>
+ DataProvider<tz::EssentialsV1>
+ DataProvider<tz::LocationsOverrideV1>
+ DataProvider<tz::LocationsRootV1>
+ DataProvider<tz::MzSpecificShortV1>
+ DataProvider<tz::MzPeriodV1>
+ ?Sized,
{
let error_field = self.inner.load_time_zone_field_z_except_decimals(
&tz::EssentialsV1::bind(provider),
&tz::MzSpecificShortV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
self.load_decimal_formatter(provider)
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_specific_short_names_with_fallback(
&mut self,
) -> Result<&mut Self, PatternLoadError> {
let error_field = self.inner.load_time_zone_field_z_except_decimals(
&tz::EssentialsV1::bind(&crate::provider::Baked),
&tz::MzSpecificShortV1::bind(&crate::provider::Baked),
&tz::MzPeriodV1::bind(&crate::provider::Baked),
self.prefs,
&mut self.metadata,
)?;
self.include_decimal_formatter()
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
pub fn load_time_zone_specific_long_names_with_fallback<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<DecimalSymbolsV1>
+ DataProvider<DecimalDigitsV1>
+ DataProvider<tz::EssentialsV1>
+ DataProvider<tz::LocationsOverrideV1>
+ DataProvider<tz::LocationsRootV1>
+ DataProvider<tz::MzSpecificLongV1>
+ DataProvider<tz::MzStandardLongV1>
+ DataProvider<tz::MzPeriodV1>
+ ?Sized,
{
let error_field = self.inner.load_time_zone_field_zzzz_except_decimals(
&tz::EssentialsV1::bind(provider),
&tz::LocationsOverrideV1::bind(provider),
&tz::LocationsRootV1::bind(provider),
&tz::MzStandardLongV1::bind(provider),
&tz::MzSpecificLongV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
self.prefs,
&mut self.metadata,
)?;
self.load_decimal_formatter(provider)
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_specific_long_names_with_fallback(
&mut self,
) -> Result<&mut Self, PatternLoadError> {
let error_field = self.inner.load_time_zone_field_zzzz_except_decimals(
&tz::EssentialsV1::bind(&crate::provider::Baked),
&tz::LocationsOverrideV1::bind(&crate::provider::Baked),
&tz::LocationsRootV1::bind(&crate::provider::Baked),
&tz::MzStandardLongV1::bind(&crate::provider::Baked),
&tz::MzSpecificLongV1::bind(&crate::provider::Baked),
&tz::MzPeriodV1::bind(&crate::provider::Baked),
self.prefs,
&mut self.metadata,
)?;
self.include_decimal_formatter()
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
pub fn load_time_zone_localized_offset_names_with_fallback<P>(
&mut self,
provider: &P,
) -> Result<&mut Self, PatternLoadError>
where
P: DataProvider<DecimalSymbolsV1>
+ DataProvider<DecimalDigitsV1>
+ DataProvider<tz::EssentialsV1>
+ ?Sized,
{
let error_field = self.inner.load_time_zone_field_O_except_decimals(
&tz::EssentialsV1::bind(provider),
self.prefs,
)?;
self.load_decimal_formatter(provider)
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
pub fn include_time_zone_localized_offset_names_with_fallback(
&mut self,
) -> Result<&mut Self, PatternLoadError> {
let error_field = self.inner.load_time_zone_field_O_except_decimals(
&tz::EssentialsV1::bind(&crate::provider::Baked),
self.prefs,
)?;
self.include_decimal_formatter()
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(self)
}
#[inline]
pub fn load_decimal_formatter<P>(&mut self, provider: &P) -> Result<&mut Self, DataError>
where
P: DataProvider<DecimalSymbolsV1> + DataProvider<DecimalDigitsV1> + ?Sized,
{
self.inner
.load_decimal_formatter(&ExternalLoaderUnstable(provider), self.prefs)?;
Ok(self)
}
#[cfg(feature = "compiled_data")]
#[inline]
pub fn include_decimal_formatter(&mut self) -> Result<&mut Self, DataError> {
self.inner
.load_decimal_formatter(&ExternalLoaderCompiledData, self.prefs)?;
Ok(self)
}
}
impl<C: CldrCalendar, FSet: DateTimeNamesMarker> FixedCalendarDateTimeNames<C, FSet> {
#[inline]
pub fn with_pattern_unchecked<'l>(
&'l self,
pattern: &'l DateTimePattern,
) -> DateTimePatternFormatter<'l, C, FSet> {
DateTimePatternFormatter::new(pattern.as_borrowed(), self.inner.as_borrowed())
}
pub fn load_for_pattern<'l, P>(
&'l mut self,
provider: &P,
pattern: &'l DateTimePattern,
) -> Result<DateTimePatternFormatter<'l, C, FSet>, PatternLoadError>
where
P: DataProvider<C::YearNamesV1>
+ DataProvider<C::MonthNamesV1>
+ DataProvider<WeekdayNamesV1>
+ DataProvider<DayPeriodNamesV1>
+ DataProvider<tz::EssentialsV1>
+ DataProvider<tz::LocationsOverrideV1>
+ DataProvider<tz::LocationsRootV1>
+ DataProvider<tz::CitiesOverrideV1>
+ DataProvider<tz::CitiesRootV1>
+ DataProvider<tz::MzGenericLongV1>
+ DataProvider<tz::MzGenericShortV1>
+ DataProvider<tz::MzStandardLongV1>
+ DataProvider<tz::MzSpecificLongV1>
+ DataProvider<tz::MzSpecificShortV1>
+ DataProvider<tz::MzPeriodV1>
+ DataProvider<DecimalSymbolsV1>
+ DataProvider<DecimalDigitsV1>
+ ?Sized,
{
let locale = self.prefs;
self.inner.load_for_pattern(
&C::YearNamesV1::bind(provider),
&C::MonthNamesV1::bind(provider),
&WeekdayNamesV1::bind(provider),
&DayPeriodNamesV1::bind(provider),
&tz::EssentialsV1::bind(provider),
&tz::LocationsRootV1::bind(provider),
&tz::LocationsOverrideV1::bind(provider),
&tz::CitiesRootV1::bind(provider),
&tz::CitiesOverrideV1::bind(provider),
&tz::MzGenericLongV1::bind(provider),
&tz::MzGenericShortV1::bind(provider),
&tz::MzStandardLongV1::bind(provider),
&tz::MzSpecificLongV1::bind(provider),
&tz::MzSpecificShortV1::bind(provider),
&tz::MzPeriodV1::bind(provider),
&ExternalLoaderUnstable(provider),
locale,
pattern.iter_items(),
&mut self.metadata,
)?;
Ok(DateTimePatternFormatter::new(
pattern.as_borrowed(),
self.inner.as_borrowed(),
))
}
#[cfg(feature = "compiled_data")]
pub fn include_for_pattern<'l>(
&'l mut self,
pattern: &'l DateTimePattern,
) -> Result<DateTimePatternFormatter<'l, C, FSet>, PatternLoadError>
where
crate::provider::Baked: DataProvider<C::YearNamesV1> + DataProvider<C::MonthNamesV1>,
crate::provider::Baked: DataProvider<C::YearNamesV1> + DataProvider<C::MonthNamesV1>,
{
let locale = self.prefs;
self.inner.load_for_pattern(
&C::YearNamesV1::bind(&crate::provider::Baked),
&C::MonthNamesV1::bind(&crate::provider::Baked),
&WeekdayNamesV1::bind(&crate::provider::Baked),
&DayPeriodNamesV1::bind(&crate::provider::Baked),
&tz::EssentialsV1::bind(&crate::provider::Baked),
&tz::LocationsOverrideV1::bind(&crate::provider::Baked),
&tz::LocationsRootV1::bind(&crate::provider::Baked),
&tz::CitiesOverrideV1::bind(&crate::provider::Baked),
&tz::CitiesRootV1::bind(&crate::provider::Baked),
&tz::MzGenericLongV1::bind(&crate::provider::Baked),
&tz::MzGenericShortV1::bind(&crate::provider::Baked),
&tz::MzStandardLongV1::bind(&crate::provider::Baked),
&tz::MzSpecificLongV1::bind(&crate::provider::Baked),
&tz::MzSpecificShortV1::bind(&crate::provider::Baked),
&tz::MzPeriodV1::bind(&crate::provider::Baked),
&ExternalLoaderCompiledData,
locale,
pattern.iter_items(),
&mut self.metadata,
)?;
Ok(DateTimePatternFormatter::new(
pattern.as_borrowed(),
self.inner.as_borrowed(),
))
}
}
impl<C, FSet: DateTimeNamesMarker> FixedCalendarDateTimeNames<C, FSet> {
pub fn cast_into_fset<FSet2: DateTimeNamesFrom<FSet>>(
self,
) -> FixedCalendarDateTimeNames<C, FSet2> {
FixedCalendarDateTimeNames {
prefs: self.prefs,
inner: self.inner.cast_into_fset(),
metadata: self.metadata,
_calendar: PhantomData,
}
}
}
#[cfg(feature = "unstable")]
impl<C, FSet: DateTimeNamesMarker> FixedCalendarDateTimeNames<C, FSet>
where
FSet::DayPeriodNames: NamesContainer<
DayPeriodNamesV1,
DayPeriodNameLength,
Container = DataPayloadWithVariables<DayPeriodNamesV1, DayPeriodNameLength>,
>,
{
pub fn get_am(&self, length: DayPeriodNameLength) -> Option<&str> {
let borrowed = self.inner.as_borrowed();
borrowed
.dayperiod_names
.get_with_variables(length)
.and_then(|names| names.am())
}
pub fn get_pm(&self, length: DayPeriodNameLength) -> Option<&str> {
let borrowed = self.inner.as_borrowed();
borrowed
.dayperiod_names
.get_with_variables(length)
.and_then(|names| names.pm())
}
}
impl<FSet: DateTimeNamesMarker> DateTimeNames<FSet> {
pub fn cast_into_fset<FSet2: DateTimeNamesFrom<FSet>>(self) -> DateTimeNames<FSet2> {
DateTimeNames {
inner: self.inner.cast_into_fset(),
calendar: self.calendar,
}
}
}
impl<FSet: DateTimeNamesMarker> RawDateTimeNames<FSet> {
pub(crate) fn new_without_number_formatting() -> Self {
Self {
year_names: <FSet::YearNames as NamesContainer<
YearNamesV1,
YearNameLength,
>>::Container::new_empty(),
month_names: <FSet::MonthNames as NamesContainer<
MonthNamesV1,
MonthNameLength,
>>::Container::new_empty(),
weekday_names: <FSet::WeekdayNames as NamesContainer<
WeekdayNamesV1,
WeekdayNameLength,
>>::Container::new_empty(),
dayperiod_names: <FSet::DayPeriodNames as NamesContainer<
DayPeriodNamesV1,
DayPeriodNameLength,
>>::Container::new_empty(),
zone_essentials: <FSet::ZoneEssentials as NamesContainer<
tz::EssentialsV1,
(),
>>::Container::new_empty(),
locations_root: <FSet::ZoneLocationsRoot as NamesContainer<
tz::LocationsRootV1,
(),
>>::Container::new_empty(),
locations: <FSet::ZoneLocations as NamesContainer<
tz::LocationsOverrideV1,
(),
>>::Container::new_empty(),
exemplars: <FSet::ZoneExemplars as NamesContainer<
tz::CitiesOverrideV1,
(),
>>::Container::new_empty(),
exemplars_root: <FSet::ZoneExemplarsRoot as NamesContainer<
tz::CitiesRootV1,
(),
>>::Container::new_empty(),
mz_generic_long: <FSet::ZoneGenericLong as NamesContainer<
tz::MzGenericLongV1,
(),
>>::Container::new_empty(),
mz_generic_short: <FSet::ZoneGenericShort as NamesContainer<
tz::MzGenericShortV1,
(),
>>::Container::new_empty(),
mz_standard_long: <FSet::ZoneStandardLong as NamesContainer<
tz::MzStandardLongV1,
(),
>>::Container::new_empty(),
mz_specific_long: <FSet::ZoneSpecificLong as NamesContainer<
tz::MzSpecificLongV1,
(),
>>::Container::new_empty(),
mz_specific_short: <FSet::ZoneSpecificShort as NamesContainer<
tz::MzSpecificShortV1,
(),
>>::Container::new_empty(),
mz_periods: <FSet::MetazoneLookup as NamesContainer<
tz::MzPeriodV1,
(),
>>::Container::new_empty(),
decimal_formatter: None,
_marker: PhantomData,
}
}
pub(crate) fn as_borrowed(&self) -> RawDateTimeNamesBorrowed<'_> {
RawDateTimeNamesBorrowed {
year_names: self.year_names.get().inner,
month_names: self.month_names.get().inner,
weekday_names: self.weekday_names.get().inner,
dayperiod_names: self.dayperiod_names.get().inner,
zone_essentials: self.zone_essentials.get().inner,
locations_root: self.locations_root.get().inner,
locations: self.locations.get().inner,
exemplars_root: self.exemplars_root.get().inner,
exemplars: self.exemplars.get().inner,
mz_generic_long: self.mz_generic_long.get().inner,
mz_generic_short: self.mz_generic_short.get().inner,
mz_standard_long: self.mz_standard_long.get().inner,
mz_specific_long: self.mz_specific_long.get().inner,
mz_specific_short: self.mz_specific_short.get().inner,
mz_periods: self.mz_periods.get().inner,
decimal_formatter: self.decimal_formatter.as_ref(),
}
}
pub(crate) fn load_year_names<P>(
&mut self,
provider: &P,
prefs: DateTimeFormatterPreferences,
length: YearNameLength,
error_field: ErrorField,
) -> Result<(), PatternLoadError>
where
P: BoundDataProvider<YearNamesV1> + ?Sized,
{
let attributes = length.to_attributes();
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let req = DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(attributes, &locale),
..Default::default()
};
self.year_names
.load_put(provider, req, length)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(())
}
pub(crate) fn load_month_names<P>(
&mut self,
provider: &P,
prefs: DateTimeFormatterPreferences,
length: MonthNameLength,
error_field: ErrorField,
) -> Result<(), PatternLoadError>
where
P: BoundDataProvider<MonthNamesV1> + ?Sized,
{
let attributes = length.to_attributes();
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let req = DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(attributes, &locale),
..Default::default()
};
self.month_names
.load_put(provider, req, length)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(())
}
pub(crate) fn load_day_period_names<P>(
&mut self,
provider: &P,
prefs: DateTimeFormatterPreferences,
length: DayPeriodNameLength,
error_field: ErrorField,
) -> Result<(), PatternLoadError>
where
P: BoundDataProvider<DayPeriodNamesV1> + ?Sized,
{
let attributes = length.to_attributes();
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let req = DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(attributes, &locale),
..Default::default()
};
self.dayperiod_names
.load_put(provider, req, length)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(())
}
pub(crate) fn load_weekday_names<P>(
&mut self,
provider: &P,
prefs: DateTimeFormatterPreferences,
length: WeekdayNameLength,
error_field: ErrorField,
) -> Result<(), PatternLoadError>
where
P: BoundDataProvider<WeekdayNamesV1> + ?Sized,
{
let attributes = length.to_attributes();
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let req = DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(attributes, &locale),
..Default::default()
};
self.weekday_names
.load_put(provider, req, length)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(())
}
pub(crate) fn load_time_zone_essentials<P>(
&mut self,
provider: &P,
prefs: DateTimeFormatterPreferences,
) -> Result<ErrorField, PatternLoadError>
where
P: BoundDataProvider<tz::EssentialsV1> + ?Sized,
{
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let error_field = ErrorField(fields::Field {
symbol: FieldSymbol::TimeZone(fields::TimeZone::LocalizedOffset),
length: FieldLength::Four,
});
let variables = ();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
self.zone_essentials
.load_put(provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(error_field)
}
pub(crate) fn load_time_zone_location_names<P, P2>(
&mut self,
provider: &P,
root_provider: &P2,
prefs: DateTimeFormatterPreferences,
) -> Result<ErrorField, PatternLoadError>
where
P: BoundDataProvider<tz::LocationsOverrideV1> + ?Sized,
P2: BoundDataProvider<tz::LocationsRootV1> + ?Sized,
{
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let error_field = ErrorField(fields::Field {
symbol: FieldSymbol::TimeZone(fields::TimeZone::Location),
length: FieldLength::Four,
});
let variables = ();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
self.locations_root
.load_put(root_provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
self.locations
.load_put(provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(error_field)
}
pub(crate) fn load_time_zone_exemplar_city_names<P, P2>(
&mut self,
provider: &P,
root_provider: &P2,
prefs: DateTimeFormatterPreferences,
) -> Result<ErrorField, PatternLoadError>
where
P: BoundDataProvider<tz::CitiesOverrideV1> + ?Sized,
P2: BoundDataProvider<tz::CitiesRootV1> + ?Sized,
{
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let error_field = ErrorField(fields::Field {
symbol: FieldSymbol::TimeZone(fields::TimeZone::Location),
length: FieldLength::Three,
});
let variables = ();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
self.exemplars_root
.load_put(root_provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
self.exemplars
.load_put(provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?;
Ok(error_field)
}
pub(crate) fn load_time_zone_generic_long_names(
&mut self,
mz_generic_provider: &(impl BoundDataProvider<tz::MzGenericLongV1> + ?Sized),
mz_standard_provider: &(impl BoundDataProvider<tz::MzStandardLongV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
let locale = mz_generic_provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let error_field = ErrorField(fields::Field {
symbol: FieldSymbol::TimeZone(fields::TimeZone::GenericNonLocation),
length: FieldLength::Four,
});
let variables = ();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
let mut save_checksum = |cs: &u64| {
names_metadata.zone_checksum.get_or_insert(*cs);
};
let cs1 = self
.mz_generic_long
.load_put(mz_generic_provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs2 = self
.mz_standard_long
.load_put(mz_standard_provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs3 = self
.mz_periods
.load_put(mz_period_provider, Default::default(), ())
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs = names_metadata.zone_checksum;
if cs1.or(cs) != cs || cs2.or(cs) != cs || cs3.or(cs) != cs {
return Err(PatternLoadError::Data(
DataErrorKind::InconsistentData(tz::MzPeriodV1::INFO)
.with_req(tz::MzGenericLongV1::INFO, req),
error_field,
));
}
Ok(error_field)
}
pub(crate) fn load_time_zone_generic_short_names(
&mut self,
provider: &(impl BoundDataProvider<tz::MzGenericShortV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let error_field = ErrorField(fields::Field {
symbol: FieldSymbol::TimeZone(fields::TimeZone::GenericNonLocation),
length: FieldLength::One,
});
let variables = ();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
let mut save_checksum = |cs: &u64| {
names_metadata.zone_checksum.get_or_insert(*cs);
};
let cs1 = self
.mz_generic_short
.load_put(provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs2 = self
.mz_periods
.load_put(mz_period_provider, Default::default(), ())
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs = names_metadata.zone_checksum;
if cs1.or(cs) != cs || cs2.or(cs) != cs {
return Err(PatternLoadError::Data(
DataErrorKind::InconsistentData(tz::MzPeriodV1::INFO)
.with_req(tz::MzGenericLongV1::INFO, req),
error_field,
));
}
Ok(error_field)
}
pub(crate) fn load_time_zone_specific_long_names(
&mut self,
mz_specific_provider: &(impl BoundDataProvider<tz::MzSpecificLongV1> + ?Sized),
mz_standard_provider: &(impl BoundDataProvider<tz::MzStandardLongV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
let locale = mz_specific_provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let error_field = ErrorField(fields::Field {
symbol: FieldSymbol::TimeZone(fields::TimeZone::SpecificNonLocation),
length: FieldLength::Four,
});
let variables = ();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
let mut save_checksum = |cs: &u64| {
names_metadata.zone_checksum.get_or_insert(*cs);
};
let cs1 = self
.mz_specific_long
.load_put(mz_specific_provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs2 = self
.mz_standard_long
.load_put(mz_standard_provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs3 = self
.mz_periods
.load_put(mz_period_provider, Default::default(), ())
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs = names_metadata.zone_checksum;
if cs1.or(cs) != cs || cs2.or(cs) != cs || cs3.or(cs) != cs {
return Err(PatternLoadError::Data(
DataErrorKind::InconsistentData(tz::MzPeriodV1::INFO)
.with_req(tz::MzSpecificLongV1::INFO, req),
error_field,
));
}
Ok(error_field)
}
pub(crate) fn load_time_zone_specific_short_names(
&mut self,
provider: &(impl BoundDataProvider<tz::MzSpecificShortV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
let locale = provider
.bound_marker()
.make_locale(prefs.locale_preferences);
let error_field = ErrorField(fields::Field {
symbol: FieldSymbol::TimeZone(fields::TimeZone::SpecificNonLocation),
length: FieldLength::One,
});
let variables = ();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
let mut save_checksum = |cs: &u64| {
names_metadata.zone_checksum.get_or_insert(*cs);
};
let cs1 = self
.mz_specific_short
.load_put(provider, req, variables)
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs2 = self
.mz_periods
.load_put(mz_period_provider, Default::default(), ())
.map_err(|e| MaybePayloadError::into_load_error(e, error_field))?
.map_err(|e| PatternLoadError::Data(e, error_field))?
.checksum
.inspect(&mut save_checksum);
let cs = names_metadata.zone_checksum;
if cs1.or(cs) != cs || cs2.or(cs) != cs {
return Err(PatternLoadError::Data(
DataErrorKind::InconsistentData(tz::MzPeriodV1::INFO)
.with_req(tz::MzSpecificShortV1::INFO, req),
error_field,
));
}
Ok(error_field)
}
pub(crate) fn load_time_zone_field_z_except_decimals(
&mut self,
zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1> + ?Sized),
mz_specific_short_provider: &(impl BoundDataProvider<tz::MzSpecificShortV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
self.load_time_zone_specific_short_names(
mz_specific_short_provider,
mz_period_provider,
prefs,
names_metadata,
)
}
#[expect(clippy::too_many_arguments)]
pub(crate) fn load_time_zone_field_zzzz_except_decimals(
&mut self,
zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1> + ?Sized),
locations_provider: &(impl BoundDataProvider<tz::LocationsOverrideV1> + ?Sized),
locations_root_provider: &(impl BoundDataProvider<tz::LocationsRootV1> + ?Sized),
mz_standard_long_provider: &(impl BoundDataProvider<tz::MzStandardLongV1> + ?Sized),
mz_specific_long_provider: &(impl BoundDataProvider<tz::MzSpecificLongV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
self.load_time_zone_location_names(locations_provider, locations_root_provider, prefs)?;
self.load_time_zone_specific_long_names(
mz_specific_long_provider,
mz_standard_long_provider,
mz_period_provider,
prefs,
names_metadata,
)
}
#[expect(clippy::too_many_arguments)] pub(crate) fn load_time_zone_field_v_except_decimals(
&mut self,
zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1> + ?Sized),
locations_provider: &(impl BoundDataProvider<tz::LocationsOverrideV1> + ?Sized),
locations_root_provider: &(impl BoundDataProvider<tz::LocationsRootV1> + ?Sized),
mz_generic_short_provider: &(impl BoundDataProvider<tz::MzGenericShortV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
self.load_time_zone_location_names(locations_provider, locations_root_provider, prefs)?;
self.load_time_zone_generic_short_names(
mz_generic_short_provider,
mz_period_provider,
prefs,
names_metadata,
)
}
#[expect(clippy::too_many_arguments)]
pub(crate) fn load_time_zone_field_vvvv_except_decimals(
&mut self,
zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1> + ?Sized),
locations_provider: &(impl BoundDataProvider<tz::LocationsOverrideV1> + ?Sized),
locations_root_provider: &(impl BoundDataProvider<tz::LocationsRootV1> + ?Sized),
mz_generic_long_provider: &(impl BoundDataProvider<tz::MzGenericLongV1> + ?Sized),
mz_standard_long_provider: &(impl BoundDataProvider<tz::MzStandardLongV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<ErrorField, PatternLoadError> {
self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
self.load_time_zone_location_names(locations_provider, locations_root_provider, prefs)?;
self.load_time_zone_generic_long_names(
mz_generic_long_provider,
mz_standard_long_provider,
mz_period_provider,
prefs,
names_metadata,
)
}
#[allow(non_snake_case)] #[allow(clippy::unnecessary_wraps)] pub(crate) fn load_time_zone_field_V(
&mut self,
_prefs: DateTimeFormatterPreferences,
) -> Result<(), PatternLoadError> {
Ok(())
}
#[allow(non_snake_case)] pub(crate) fn load_time_zone_field_VVV(
&mut self,
locations_provider: &(impl BoundDataProvider<tz::LocationsOverrideV1> + ?Sized),
locations_root_provider: &(impl BoundDataProvider<tz::LocationsRootV1> + ?Sized),
exemplar_cities_provider: &(impl BoundDataProvider<tz::CitiesOverrideV1> + ?Sized),
exemplar_cities_root_provider: &(impl BoundDataProvider<tz::CitiesRootV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
) -> Result<ErrorField, PatternLoadError> {
self.load_time_zone_location_names(locations_provider, locations_root_provider, prefs)?;
self.load_time_zone_exemplar_city_names(
exemplar_cities_provider,
exemplar_cities_root_provider,
prefs,
)
}
#[allow(non_snake_case)] pub(crate) fn load_time_zone_field_VVVV_except_decimals(
&mut self,
zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1> + ?Sized),
locations_provider: &(impl BoundDataProvider<tz::LocationsOverrideV1> + ?Sized),
locations_root_provider: &(impl BoundDataProvider<tz::LocationsRootV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
) -> Result<ErrorField, PatternLoadError> {
self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
self.load_time_zone_location_names(locations_provider, locations_root_provider, prefs)
}
#[allow(non_snake_case)] pub(crate) fn load_time_zone_field_O_except_decimals(
&mut self,
zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1> + ?Sized),
prefs: DateTimeFormatterPreferences,
) -> Result<ErrorField, PatternLoadError> {
self.load_time_zone_essentials(zone_essentials_provider, prefs)
}
#[allow(non_snake_case)] #[allow(clippy::unnecessary_wraps)] pub(crate) fn load_time_zone_field_X(
&mut self,
_prefs: DateTimeFormatterPreferences,
) -> Result<(), PatternLoadError> {
Ok(())
}
pub(crate) fn load_decimal_formatter(
&mut self,
loader: &impl DecimalFormatterLoader,
prefs: DateTimeFormatterPreferences,
) -> Result<(), DataError> {
if self.decimal_formatter.is_some() {
return Ok(());
}
let mut options = DecimalFormatterOptions::default();
options.grouping_strategy = Some(GroupingStrategy::Never);
self.decimal_formatter = Some(DecimalFormatterLoader::load(
loader,
(&prefs).into(),
options,
)?);
Ok(())
}
#[expect(clippy::too_many_arguments)]
pub(crate) fn load_for_pattern(
&mut self,
year_provider: &(impl BoundDataProvider<YearNamesV1> + ?Sized),
month_provider: &(impl BoundDataProvider<MonthNamesV1> + ?Sized),
weekday_provider: &(impl BoundDataProvider<WeekdayNamesV1> + ?Sized),
dayperiod_provider: &(impl BoundDataProvider<DayPeriodNamesV1> + ?Sized),
zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1> + ?Sized),
locations_provider: &(impl BoundDataProvider<tz::LocationsOverrideV1> + ?Sized),
locations_root_provider: &(impl BoundDataProvider<tz::LocationsRootV1> + ?Sized),
exemplar_cities_provider: &(impl BoundDataProvider<tz::CitiesOverrideV1> + ?Sized),
exemplar_cities_root_provider: &(impl BoundDataProvider<tz::CitiesRootV1> + ?Sized),
mz_generic_long_provider: &(impl BoundDataProvider<tz::MzGenericLongV1> + ?Sized),
mz_generic_short_provider: &(impl BoundDataProvider<tz::MzGenericShortV1> + ?Sized),
mz_standard_long_provider: &(impl BoundDataProvider<tz::MzStandardLongV1> + ?Sized),
mz_specific_long_provider: &(impl BoundDataProvider<tz::MzSpecificLongV1> + ?Sized),
mz_specific_short_provider: &(impl BoundDataProvider<tz::MzSpecificShortV1> + ?Sized),
mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1> + ?Sized),
decimal_formatter_loader: &impl DecimalFormatterLoader,
prefs: DateTimeFormatterPreferences,
pattern_items: impl Iterator<Item = PatternItem>,
names_metadata: &mut DateTimeNamesMetadata,
) -> Result<(), PatternLoadError> {
let mut numeric_field = None;
for item in pattern_items {
let PatternItem::Field(field) = item else {
continue;
};
let error_field = ErrorField(field);
use crate::provider::fields::*;
use FieldLength::*;
use FieldSymbol as FS;
match (field.symbol, field.length) {
(FS::Era, One | Two | Three | Four | Five) => {
self.load_year_names(
year_provider,
prefs,
YearNameLength::from_field_length(field.length)
.ok_or(PatternLoadError::UnsupportedLength(error_field))?,
error_field,
)?;
}
(FS::Year(Year::Cyclic), One | Two | Three | Four | Five) => {
numeric_field = Some(field);
self.load_year_names(
year_provider,
prefs,
YearNameLength::from_field_length(field.length)
.ok_or(PatternLoadError::UnsupportedLength(error_field))?,
error_field,
)?;
}
(
FS::Month(field_symbol @ Month::Format | field_symbol @ Month::StandAlone),
Three | Four | Five,
) => {
self.load_month_names(
month_provider,
prefs,
MonthNameLength::from_field(field_symbol, field.length)
.ok_or(PatternLoadError::UnsupportedLength(error_field))?,
error_field,
)?;
}
(FS::Weekday(Weekday::Local | Weekday::StandAlone), One | Two) => {
return Err(PatternLoadError::UnsupportedLength(ErrorField(field)));
}
(FS::Weekday(field_symbol), One | Two | Three | Four | Five | Six) => {
self.load_weekday_names(
weekday_provider,
prefs,
WeekdayNameLength::from_field(field_symbol, field.length)
.ok_or(PatternLoadError::UnsupportedLength(error_field))?,
error_field,
)?;
}
(FS::DayPeriod(field_symbol), One | Two | Three | Four | Five) => {
self.load_day_period_names(
dayperiod_provider,
prefs,
DayPeriodNameLength::from_field(field_symbol, field.length)
.ok_or(PatternLoadError::UnsupportedLength(error_field))?,
error_field,
)?;
}
(FS::TimeZone(TimeZone::SpecificNonLocation), One | Two | Three) => {
self.load_time_zone_field_z_except_decimals(
zone_essentials_provider,
mz_specific_short_provider,
mz_period_provider,
prefs,
names_metadata,
)?;
numeric_field = Some(field);
}
(FS::TimeZone(TimeZone::SpecificNonLocation), Four) => {
self.load_time_zone_field_zzzz_except_decimals(
zone_essentials_provider,
locations_provider,
locations_root_provider,
mz_standard_long_provider,
mz_specific_long_provider,
mz_period_provider,
prefs,
names_metadata,
)?;
numeric_field = Some(field);
}
(FS::TimeZone(TimeZone::GenericNonLocation), One) => {
self.load_time_zone_field_v_except_decimals(
zone_essentials_provider,
locations_provider,
locations_root_provider,
mz_generic_short_provider,
mz_period_provider,
prefs,
names_metadata,
)?;
numeric_field = Some(field);
}
(FS::TimeZone(TimeZone::GenericNonLocation), Four) => {
self.load_time_zone_field_vvvv_except_decimals(
zone_essentials_provider,
locations_provider,
locations_root_provider,
mz_generic_long_provider,
mz_standard_long_provider,
mz_period_provider,
prefs,
names_metadata,
)?;
numeric_field = Some(field);
}
(FS::TimeZone(TimeZone::Location), One) => {
self.load_time_zone_field_V(prefs)?;
}
(FS::TimeZone(TimeZone::Location), Three) => {
self.load_time_zone_field_VVV(
locations_provider,
locations_root_provider,
exemplar_cities_provider,
exemplar_cities_root_provider,
prefs,
)?;
}
(FS::TimeZone(TimeZone::Location), Four) => {
self.load_time_zone_field_VVVV_except_decimals(
zone_essentials_provider,
locations_provider,
locations_root_provider,
prefs,
)?;
numeric_field = Some(field);
}
(FS::TimeZone(TimeZone::LocalizedOffset), One | Four) => {
self.load_time_zone_field_O_except_decimals(zone_essentials_provider, prefs)?;
numeric_field = Some(field);
}
(
FS::TimeZone(TimeZone::IsoWithZ | TimeZone::Iso),
One | Two | Three | Four | Five,
) => {
self.load_time_zone_field_X(prefs)?;
}
(FS::Year(Year::Calendar), _) => numeric_field = Some(field),
(FS::Year(Year::Extended), _) => numeric_field = Some(field),
(FS::Year(Year::RelatedIso), _) => {
}
(FS::Month(_), One | Two) => numeric_field = Some(field),
(FS::Day(Day::DayOfMonth), One | Two) => numeric_field = Some(field),
(FS::Day(Day::DayOfYear), One | Two | Three) => numeric_field = Some(field),
(FS::Day(Day::DayOfWeekInMonth), One) => numeric_field = Some(field),
(FS::Day(Day::ModifiedJulianDay), One) => numeric_field = Some(field),
(FS::Hour(_), One | Two) => numeric_field = Some(field),
(FS::Minute, One | Two) => numeric_field = Some(field),
(FS::Second(Second::Second), One | Two) => numeric_field = Some(field),
(FS::Second(Second::MillisInDay), _) => numeric_field = Some(field),
(FS::DecimalSecond(_), One | Two) => numeric_field = Some(field),
_ => {
return Err(PatternLoadError::UnsupportedLength(ErrorField(field)));
}
}
}
if let Some(field) = numeric_field {
self.load_decimal_formatter(decimal_formatter_loader, prefs)
.map_err(|e| PatternLoadError::Data(e, ErrorField(field)))?;
}
Ok(())
}
}
impl RawDateTimeNamesBorrowed<'_> {
pub(crate) fn get_name_for_month(
&self,
field_symbol: fields::Month,
field_length: FieldLength,
month: MonthInfo,
) -> Result<MonthPlaceholderValue<'_>, GetNameForMonthError> {
let month_name_length = MonthNameLength::from_field(field_symbol, field_length)
.ok_or(GetNameForMonthError::InvalidFieldLength)?;
let month_names = self
.month_names
.get_with_variables(month_name_length)
.ok_or(GetNameForMonthError::NotLoaded)?;
let month_index = usize::from(month.number() - 1);
match month_names {
MonthNames::Linear(linear) => {
if month.leap_status() != LeapStatus::Normal {
None
} else {
linear
.get(month_index)
.map(MonthPlaceholderValue::PlainString)
}
}
#[cfg(feature = "serde")]
MonthNames::LeapLinear(leap_linear) => {
let num_months = leap_linear.len() / 2;
if month.leap_status() == LeapStatus::Leap {
leap_linear.get(month_index + num_months)
} else if month.leap_status() == LeapStatus::Base && month.number() < month.ordinal
{
leap_linear.get(month_index + num_months)
} else if month_index < num_months {
leap_linear.get(month_index)
} else {
None
}
.map(MonthPlaceholderValue::PlainString)
}
MonthNames::LeapNumeric(leap_numeric) => {
if month.leap_status() != LeapStatus::Normal {
Some(MonthPlaceholderValue::NumericPattern(leap_numeric))
} else {
Some(MonthPlaceholderValue::Numeric)
}
}
MonthNames::LeapPattern(data) => if month_index < data.len() - 2 {
data.get(month_index)
} else {
None
}
.and_then(|normal_name| {
Some(match month.leap_status() {
LeapStatus::Normal => MonthPlaceholderValue::PlainString(normal_name),
LeapStatus::Leap => MonthPlaceholderValue::StringPattern(
normal_name,
SinglePlaceholderPattern::from_ref_store(&data[data.len() - 2]).ok()?,
),
LeapStatus::Base => MonthPlaceholderValue::StringPattern(
normal_name,
SinglePlaceholderPattern::from_ref_store(&data[data.len() - 1]).ok()?,
),
_ => {
debug_assert!(false, "unhandled LeapStatus");
MonthPlaceholderValue::PlainString(normal_name)
}
})
}),
}
.ok_or(GetNameForMonthError::InvalidMonthCode)
}
pub(crate) fn get_name_for_weekday(
&self,
field_symbol: fields::Weekday,
field_length: FieldLength,
day: icu_calendar::types::Weekday,
) -> Result<&str, GetNameForWeekdayError> {
let weekday_name_length = WeekdayNameLength::from_field(field_symbol, field_length)
.ok_or(GetNameForWeekdayError::InvalidFieldLength)?;
let weekday_names = self
.weekday_names
.get_with_variables(weekday_name_length)
.ok_or(GetNameForWeekdayError::NotLoaded)?;
weekday_names
.names
.get((day as usize) % 7)
.ok_or(GetNameForWeekdayError::NotLoaded)
}
pub(crate) fn get_name_for_era(
&self,
field_length: FieldLength,
era_year: EraYear,
) -> Result<&str, GetNameForEraError> {
let year_name_length = YearNameLength::from_field_length(field_length)
.ok_or(GetNameForEraError::InvalidFieldLength)?;
let year_names = self
.year_names
.get_with_variables(year_name_length)
.ok_or(GetNameForEraError::NotLoaded)?;
match year_names {
#[cfg(feature = "serde")]
YearNames::VariableEras(era_names) => {
get_year_name_from_map(era_names, era_year.era.as_str().into())
.ok_or(GetNameForEraError::InvalidEraCode)
}
YearNames::FixedEras(era_names) => era_names
.get(if let Some(i) = era_year.era_index {
i as usize
} else {
debug_assert!(false, "missing era index");
usize::MAX
})
.ok_or(GetNameForEraError::InvalidEraCode),
YearNames::Cyclic(_) => Err(GetNameForEraError::InvalidEraCode),
}
}
pub(crate) fn get_name_for_cyclic(
&self,
field_length: FieldLength,
cyclic: u8,
) -> Result<&str, GetNameForCyclicYearError> {
let year_name_length = YearNameLength::from_field_length(field_length)
.ok_or(GetNameForCyclicYearError::InvalidFieldLength)?;
let year_names = self
.year_names
.get_with_variables(year_name_length)
.ok_or(GetNameForCyclicYearError::NotLoaded)?;
let YearNames::Cyclic(cyclics) = year_names else {
return Err(GetNameForCyclicYearError::InvalidYearNumber { max: 0 });
};
cyclics
.get(cyclic as usize - 1)
.ok_or(GetNameForCyclicYearError::InvalidYearNumber {
max: cyclics.len() as u8 + 1,
})
}
pub(crate) fn get_name_for_day_period(
&self,
field_symbol: fields::DayPeriod,
field_length: FieldLength,
hour: icu_time::Hour,
is_top_of_hour: bool,
) -> Result<&str, GetNameForDayPeriodError> {
use fields::DayPeriod::NoonMidnight;
let day_period_name_length = DayPeriodNameLength::from_field(field_symbol, field_length)
.ok_or(GetNameForDayPeriodError::InvalidFieldLength)?;
let dayperiod_names = self
.dayperiod_names
.get_with_variables(day_period_name_length)
.ok_or(GetNameForDayPeriodError::NotLoaded)?;
let option_value: Option<&str> = match (field_symbol, u8::from(hour), is_top_of_hour) {
(NoonMidnight, 00, true) => dayperiod_names.midnight().or_else(|| dayperiod_names.am()),
(NoonMidnight, 12, true) => dayperiod_names.noon().or_else(|| dayperiod_names.pm()),
(_, hour, _) if hour < 12 => dayperiod_names.am(),
_ => dayperiod_names.pm(),
};
option_value.ok_or(GetNameForDayPeriodError::NotLoaded)
}
}
#[derive(Debug, Copy, Clone, Default)]
pub(crate) struct TimeZoneDataPayloadsBorrowed<'a> {
pub(crate) essentials: Option<&'a tz::Essentials<'a>>,
pub(crate) locations_root: Option<&'a tz::Locations<'a>>,
pub(crate) locations: Option<&'a tz::Locations<'a>>,
pub(crate) exemplars_root: Option<&'a tz::ExemplarCities<'a>>,
pub(crate) exemplars: Option<&'a tz::ExemplarCities<'a>>,
pub(crate) mz_generic_long: Option<&'a tz::MzGeneric<'a>>,
pub(crate) mz_standard_long: Option<&'a tz::MzGeneric<'a>>,
pub(crate) mz_generic_short: Option<&'a tz::MzGeneric<'a>>,
pub(crate) mz_specific_long: Option<&'a tz::MzSpecific<'a>>,
pub(crate) mz_specific_short: Option<&'a tz::MzSpecific<'a>>,
pub(crate) mz_periods: Option<&'a tz::MzPeriod<'a>>,
}
impl<'data> RawDateTimeNamesBorrowed<'data> {
pub(crate) fn get_payloads(&self) -> TimeZoneDataPayloadsBorrowed<'data> {
TimeZoneDataPayloadsBorrowed {
essentials: self.zone_essentials.get_option(),
locations_root: self.locations_root.get_option(),
locations: self.locations.get_option(),
exemplars: self.exemplars.get_option(),
exemplars_root: self.exemplars_root.get_option(),
mz_generic_long: self.mz_generic_long.get_option(),
mz_standard_long: self.mz_standard_long.get_option(),
mz_generic_short: self.mz_generic_short.get_option(),
mz_specific_long: self.mz_specific_long.get_option(),
mz_specific_short: self.mz_specific_short.get_option(),
mz_periods: self.mz_periods.get_option(),
}
}
}