Struct icu::datetime::FixedCalendarDateTimeFormatter
source · pub struct FixedCalendarDateTimeFormatter<C, FSet>where
C: CldrCalendar,
FSet: DateTimeNamesMarker,{ /* private fields */ }
Expand description
FixedCalendarDateTimeFormatter
is a formatter capable of formatting dates and/or times from
a calendar selected at compile time.
For more details, please read the crate root docs.
📏 This item has a stack size of 344 bytes on the stable toolchain at release date.
Implementations§
source§impl<C, FSet> FixedCalendarDateTimeFormatter<C, FSet>where
C: CldrCalendar,
FSet: DateTimeMarkers + GetField<CompositeFieldSet>,
<FSet as DateTimeMarkers>::D: TypedDateDataMarkers<C>,
<FSet as DateTimeMarkers>::T: TimeMarkers,
<FSet as DateTimeMarkers>::Z: ZoneMarkers,
impl<C, FSet> FixedCalendarDateTimeFormatter<C, FSet>where
C: CldrCalendar,
FSet: DateTimeMarkers + GetField<CompositeFieldSet>,
<FSet as DateTimeMarkers>::D: TypedDateDataMarkers<C>,
<FSet as DateTimeMarkers>::T: TimeMarkers,
<FSet as DateTimeMarkers>::Z: ZoneMarkers,
sourcepub fn try_new(
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
Baked: AllFixedCalendarFormattingDataMarkers<C, FSet>,
pub fn try_new(
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
Baked: AllFixedCalendarFormattingDataMarkers<C, FSet>,
Creates a new FixedCalendarDateTimeFormatter
from compiled data with
datetime components specified at build time.
Use this constructor for optimal data size and memory use
if you know the required datetime components at build time.
If you do not know the datetime components until runtime,
use a with_components
constructor.
§Examples
Basic usage:
use icu::calendar::Date;
use icu::calendar::Gregorian;
use icu::datetime::fieldsets::YMD;
use icu::datetime::FixedCalendarDateTimeFormatter;
use icu::locale::locale;
use writeable::assert_writeable_eq;
let formatter = FixedCalendarDateTimeFormatter::try_new(
locale!("es-MX").into(),
YMD::long(),
)
.unwrap();
assert_writeable_eq!(
formatter.format(&Date::try_new_gregorian(2023, 12, 20).unwrap()),
"20 de diciembre de 2023"
);
sourcepub fn try_new_with_any_provider<P>(
provider: &P,
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
P: AnyProvider + ?Sized,
pub fn try_new_with_any_provider<P>(
provider: &P,
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
P: AnyProvider + ?Sized,
A version of [Self :: try_new
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider<P>(
provider: &P,
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
P: BufferProvider + ?Sized,
pub fn try_new_with_buffer_provider<P>(
provider: &P,
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
P: BufferProvider + ?Sized,
A version of [Self :: try_new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable<P>(
provider: &P,
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
P: AllFixedCalendarFormattingDataMarkers<C, FSet> + AllFixedCalendarExternalDataMarkers + ?Sized,
pub fn try_new_unstable<P>(
provider: &P,
prefs: DateTimeFormatterPreferences,
field_set: FSet,
) -> Result<FixedCalendarDateTimeFormatter<C, FSet>, DateTimeFormatterLoadError>where
P: AllFixedCalendarFormattingDataMarkers<C, FSet> + AllFixedCalendarExternalDataMarkers + ?Sized,
A version of Self::try_new
that uses custom data provided by a DataProvider
.
source§impl<C, FSet> FixedCalendarDateTimeFormatter<C, FSet>where
C: CldrCalendar,
FSet: DateTimeMarkers,
<FSet as DateTimeMarkers>::D: DateInputMarkers,
<FSet as DateTimeMarkers>::T: TimeMarkers,
<FSet as DateTimeMarkers>::Z: ZoneMarkers,
impl<C, FSet> FixedCalendarDateTimeFormatter<C, FSet>where
C: CldrCalendar,
FSet: DateTimeMarkers,
<FSet as DateTimeMarkers>::D: DateInputMarkers,
<FSet as DateTimeMarkers>::T: TimeMarkers,
<FSet as DateTimeMarkers>::Z: ZoneMarkers,
sourcepub fn format<I>(&self, input: &I) -> FormattedDateTime<'_>
pub fn format<I>(&self, input: &I) -> FormattedDateTime<'_>
Formats a datetime. Calendars and fields must match at compile time.
§Examples
Mismatched calendars will not compile:
use icu::calendar::Date;
use icu::calendar::cal::Buddhist;
use icu::datetime::FixedCalendarDateTimeFormatter;
use icu::datetime::fieldsets::YMD;
use icu::locale::locale;
let formatter =
FixedCalendarDateTimeFormatter::<Buddhist, _>::try_new(
locale!("es-MX").into(),
YMD::long(),
)
.unwrap();
// type mismatch resolving `<Gregorian as AsCalendar>::Calendar == Buddhist`
formatter.format(&Date::try_new_gregorian(2023, 12, 20).unwrap());
A time cannot be passed into the formatter when a date is expected:
use icu::calendar::Time;
use icu::calendar::Gregorian;
use icu::datetime::FixedCalendarDateTimeFormatter;
use icu::datetime::fieldsets::YMD;
use icu::locale::locale;
let formatter =
FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new(
locale!("es-MX").into(),
YMD::long(),
)
.unwrap();
// the trait `GetField<AnyCalendarKind>`
// is not implemented for `icu::icu_calendar::Time`
formatter.format(&Time::try_new(0, 0, 0, 0).unwrap());
source§impl<C, FSet> FixedCalendarDateTimeFormatter<C, FSet>where
C: CldrCalendar,
FSet: DateTimeMarkers,
impl<C, FSet> FixedCalendarDateTimeFormatter<C, FSet>where
C: CldrCalendar,
FSet: DateTimeMarkers,
sourcepub fn into_formatter(self, calendar: C) -> DateTimeFormatter<FSet>where
C: IntoAnyCalendar,
pub fn into_formatter(self, calendar: C) -> DateTimeFormatter<FSet>where
C: IntoAnyCalendar,
Make this FixedCalendarDateTimeFormatter
adopt a calendar so it can format any date.
This is useful if you need a DateTimeFormatter
but know the calendar system ahead of time,
so that you do not need to link extra data you aren’t using.
§Examples
use icu::calendar::cal::Hebrew;
use icu::calendar::Date;
use icu::datetime::fieldsets::YMD;
use icu::datetime::FixedCalendarDateTimeFormatter;
use icu::locale::locale;
use writeable::assert_writeable_eq;
let formatter = FixedCalendarDateTimeFormatter::try_new(
locale!("en").into(),
YMD::long(),
)
.unwrap()
.into_formatter(Hebrew::new());
let date = Date::try_new_iso(2024, 10, 14).unwrap();
assert_writeable_eq!(
formatter.format_any_calendar(&date),
"12 Tishri 5785"
);
sourcepub fn with_fset<FSet2>(self) -> FixedCalendarDateTimeFormatter<C, FSet2>where
FSet2: DateTimeNamesFrom<FSet>,
pub fn with_fset<FSet2>(self) -> FixedCalendarDateTimeFormatter<C, FSet2>where
FSet2: DateTimeNamesFrom<FSet>,
Maps a FixedCalendarDateTimeFormatter
of a specific FSet
to a more general FSet
.
For example, this can transform a formatter for YMD
to one for DateFieldSet
.
§Examples
use icu::calendar::Gregorian;
use icu::calendar::DateTime;
use icu::datetime::FixedCalendarDateTimeFormatter;
use icu::datetime::fieldsets::{YMD, enums::DateFieldSet};
use icu::locale::locale;
use writeable::assert_writeable_eq;
let specific_formatter = FixedCalendarDateTimeFormatter::try_new(
locale!("fr").into(),
YMD::medium(),
)
.unwrap();
// Test that the specific formatter works:
let datetime = DateTime::try_new_gregorian(2024, 12, 20, 14, 30, 0).unwrap();
assert_writeable_eq!(
specific_formatter.format(&datetime),
"20 déc. 2024"
);
// Make a more general formatter:
let general_formatter = specific_formatter.with_fset::<DateFieldSet>();
// Test that it still works:
assert_writeable_eq!(
general_formatter.format(&datetime),
"20 déc. 2024"
);
Trait Implementations§
Auto Trait Implementations§
impl<C, FSet> Freeze for FixedCalendarDateTimeFormatter<C, FSet>where
<<FSet as DateTimeNamesMarker>::YearNames as NamesContainer<YearNamesV1Marker, FieldLength>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::MonthNames as NamesContainer<MonthNamesV1Marker, (Month, FieldLength)>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::WeekdayNames as NamesContainer<WeekdayNamesV1Marker, (Weekday, FieldLength)>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::DayPeriodNames as NamesContainer<DayPeriodNamesV1Marker, FieldLength>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::ZoneEssentials as NamesContainer<TimeZoneEssentialsV1Marker, ()>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::ZoneLocations as NamesContainer<LocationsV1Marker, ()>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::ZoneGenericLong as NamesContainer<MetazoneGenericNamesLongV1Marker, ()>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::ZoneGenericShort as NamesContainer<MetazoneGenericNamesShortV1Marker, ()>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::ZoneSpecificLong as NamesContainer<MetazoneSpecificNamesLongV1Marker, ()>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::ZoneSpecificShort as NamesContainer<MetazoneSpecificNamesShortV1Marker, ()>>::Container: Freeze,
<<FSet as DateTimeNamesMarker>::MetazoneLookup as NamesContainer<MetazonePeriodV1Marker, ()>>::Container: Freeze,
impl<C, FSet> RefUnwindSafe for FixedCalendarDateTimeFormatter<C, FSet>where
<<FSet as DateTimeNamesMarker>::YearNames as NamesContainer<YearNamesV1Marker, FieldLength>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::MonthNames as NamesContainer<MonthNamesV1Marker, (Month, FieldLength)>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::WeekdayNames as NamesContainer<WeekdayNamesV1Marker, (Weekday, FieldLength)>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::DayPeriodNames as NamesContainer<DayPeriodNamesV1Marker, FieldLength>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneEssentials as NamesContainer<TimeZoneEssentialsV1Marker, ()>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneLocations as NamesContainer<LocationsV1Marker, ()>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneGenericLong as NamesContainer<MetazoneGenericNamesLongV1Marker, ()>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneGenericShort as NamesContainer<MetazoneGenericNamesShortV1Marker, ()>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneSpecificLong as NamesContainer<MetazoneSpecificNamesLongV1Marker, ()>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneSpecificShort as NamesContainer<MetazoneSpecificNamesShortV1Marker, ()>>::Container: RefUnwindSafe,
<<FSet as DateTimeNamesMarker>::MetazoneLookup as NamesContainer<MetazonePeriodV1Marker, ()>>::Container: RefUnwindSafe,
C: RefUnwindSafe,
FSet: RefUnwindSafe,
impl<C, FSet> Send for FixedCalendarDateTimeFormatter<C, FSet>where
<<FSet as DateTimeNamesMarker>::YearNames as NamesContainer<YearNamesV1Marker, FieldLength>>::Container: Send,
<<FSet as DateTimeNamesMarker>::MonthNames as NamesContainer<MonthNamesV1Marker, (Month, FieldLength)>>::Container: Send,
<<FSet as DateTimeNamesMarker>::WeekdayNames as NamesContainer<WeekdayNamesV1Marker, (Weekday, FieldLength)>>::Container: Send,
<<FSet as DateTimeNamesMarker>::DayPeriodNames as NamesContainer<DayPeriodNamesV1Marker, FieldLength>>::Container: Send,
<<FSet as DateTimeNamesMarker>::ZoneEssentials as NamesContainer<TimeZoneEssentialsV1Marker, ()>>::Container: Send,
<<FSet as DateTimeNamesMarker>::ZoneLocations as NamesContainer<LocationsV1Marker, ()>>::Container: Send,
<<FSet as DateTimeNamesMarker>::ZoneGenericLong as NamesContainer<MetazoneGenericNamesLongV1Marker, ()>>::Container: Send,
<<FSet as DateTimeNamesMarker>::ZoneGenericShort as NamesContainer<MetazoneGenericNamesShortV1Marker, ()>>::Container: Send,
<<FSet as DateTimeNamesMarker>::ZoneSpecificLong as NamesContainer<MetazoneSpecificNamesLongV1Marker, ()>>::Container: Send,
<<FSet as DateTimeNamesMarker>::ZoneSpecificShort as NamesContainer<MetazoneSpecificNamesShortV1Marker, ()>>::Container: Send,
<<FSet as DateTimeNamesMarker>::MetazoneLookup as NamesContainer<MetazonePeriodV1Marker, ()>>::Container: Send,
C: Send,
FSet: Send,
impl<C, FSet> Sync for FixedCalendarDateTimeFormatter<C, FSet>where
<<FSet as DateTimeNamesMarker>::YearNames as NamesContainer<YearNamesV1Marker, FieldLength>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::MonthNames as NamesContainer<MonthNamesV1Marker, (Month, FieldLength)>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::WeekdayNames as NamesContainer<WeekdayNamesV1Marker, (Weekday, FieldLength)>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::DayPeriodNames as NamesContainer<DayPeriodNamesV1Marker, FieldLength>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::ZoneEssentials as NamesContainer<TimeZoneEssentialsV1Marker, ()>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::ZoneLocations as NamesContainer<LocationsV1Marker, ()>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::ZoneGenericLong as NamesContainer<MetazoneGenericNamesLongV1Marker, ()>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::ZoneGenericShort as NamesContainer<MetazoneGenericNamesShortV1Marker, ()>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::ZoneSpecificLong as NamesContainer<MetazoneSpecificNamesLongV1Marker, ()>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::ZoneSpecificShort as NamesContainer<MetazoneSpecificNamesShortV1Marker, ()>>::Container: Sync,
<<FSet as DateTimeNamesMarker>::MetazoneLookup as NamesContainer<MetazonePeriodV1Marker, ()>>::Container: Sync,
C: Sync,
FSet: Sync,
impl<C, FSet> Unpin for FixedCalendarDateTimeFormatter<C, FSet>where
<<FSet as DateTimeNamesMarker>::YearNames as NamesContainer<YearNamesV1Marker, FieldLength>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::MonthNames as NamesContainer<MonthNamesV1Marker, (Month, FieldLength)>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::WeekdayNames as NamesContainer<WeekdayNamesV1Marker, (Weekday, FieldLength)>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::DayPeriodNames as NamesContainer<DayPeriodNamesV1Marker, FieldLength>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::ZoneEssentials as NamesContainer<TimeZoneEssentialsV1Marker, ()>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::ZoneLocations as NamesContainer<LocationsV1Marker, ()>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::ZoneGenericLong as NamesContainer<MetazoneGenericNamesLongV1Marker, ()>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::ZoneGenericShort as NamesContainer<MetazoneGenericNamesShortV1Marker, ()>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::ZoneSpecificLong as NamesContainer<MetazoneSpecificNamesLongV1Marker, ()>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::ZoneSpecificShort as NamesContainer<MetazoneSpecificNamesShortV1Marker, ()>>::Container: Unpin,
<<FSet as DateTimeNamesMarker>::MetazoneLookup as NamesContainer<MetazonePeriodV1Marker, ()>>::Container: Unpin,
C: Unpin,
FSet: Unpin,
impl<C, FSet> UnwindSafe for FixedCalendarDateTimeFormatter<C, FSet>where
<<FSet as DateTimeNamesMarker>::YearNames as NamesContainer<YearNamesV1Marker, FieldLength>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::MonthNames as NamesContainer<MonthNamesV1Marker, (Month, FieldLength)>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::WeekdayNames as NamesContainer<WeekdayNamesV1Marker, (Weekday, FieldLength)>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::DayPeriodNames as NamesContainer<DayPeriodNamesV1Marker, FieldLength>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneEssentials as NamesContainer<TimeZoneEssentialsV1Marker, ()>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneLocations as NamesContainer<LocationsV1Marker, ()>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneGenericLong as NamesContainer<MetazoneGenericNamesLongV1Marker, ()>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneGenericShort as NamesContainer<MetazoneGenericNamesShortV1Marker, ()>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneSpecificLong as NamesContainer<MetazoneSpecificNamesLongV1Marker, ()>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::ZoneSpecificShort as NamesContainer<MetazoneSpecificNamesShortV1Marker, ()>>::Container: UnwindSafe,
<<FSet as DateTimeNamesMarker>::MetazoneLookup as NamesContainer<MetazonePeriodV1Marker, ()>>::Container: UnwindSafe,
C: UnwindSafe,
FSet: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more