Struct icu_datetime::neo::NeoDateFormatter
source ยท pub struct NeoDateFormatter { /* private fields */ }
Expand description
NeoDateFormatter
is a formatter capable of formatting dates from any calendar, selected
at runtime. For the difference between this and TypedNeoDateFormatter
, please read the
crate root docs.
๐ This item has a stack size of 512 bytes on the stable toolchain at release date.
Implementationsยง
sourceยงimpl NeoDateFormatter
impl NeoDateFormatter
sourcepub fn try_new_with_length(
locale: &DataLocale,
length: Date,
) -> Result<Self, LoadError>
pub fn try_new_with_length( locale: &DataLocale, length: Date, ) -> Result<Self, LoadError>
Construct a new NeoDateFormatter
from compiled data.
This method will pick the calendar off of the locale; and if unspecified or unknown will fall back to the default
calendar for the locale. See AnyCalendarKind
for a list of supported calendars.
โจ Enabled with the compiled_data
Cargo feature.
๐ Help choosing a constructor
ยงExamples
use icu::calendar::{any_calendar::AnyCalendar, Date};
use icu::datetime::{neo::NeoDateFormatter, options::length};
use icu::locid::locale;
use icu_provider::any::DynamicDataProviderAnyMarkerWrap;
use std::str::FromStr;
use writeable::assert_try_writeable_eq;
let length = length::Date::Medium;
let locale = locale!("en-u-ca-gregory");
let df = NeoDateFormatter::try_new_with_length(&locale.into(), length)
.expect("Failed to create TypedDateFormatter instance.");
let datetime =
Date::try_new_iso_date(2020, 9, 1).expect("Failed to construct Date.");
let any_datetime = datetime.to_any();
assert_try_writeable_eq!(
df.format(&any_datetime).expect("Calendars should match"),
"Sep 1, 2020"
);
sourcepub fn try_new_with_length_with_any_provider<P>(
provider: &P,
locale: &DataLocale,
length: Date,
) -> Result<Self, LoadError>where
P: AnyProvider + ?Sized,
pub fn try_new_with_length_with_any_provider<P>(
provider: &P,
locale: &DataLocale,
length: Date,
) -> Result<Self, LoadError>where
P: AnyProvider + ?Sized,
A version of Self::try_new_with_length
that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_length_with_buffer_provider<P>(
provider: &P,
locale: &DataLocale,
length: Date,
) -> Result<Self, LoadError>where
P: BufferProvider + ?Sized,
pub fn try_new_with_length_with_buffer_provider<P>(
provider: &P,
locale: &DataLocale,
length: Date,
) -> Result<Self, LoadError>where
P: BufferProvider + ?Sized,
A version of Self::try_new_with_length
that uses custom data provided by a BufferProvider
.
โจ Enabled with the serde
feature.
sourcepub fn try_new_with_length_unstable<P>(
provider: &P,
locale: &DataLocale,
length: Date,
) -> Result<Self, LoadError>where
P: ?Sized + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Buddhist> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Chinese> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Coptic> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Dangi> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Ethiopian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::EthiopianAmeteAlem> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Gregorian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Hebrew> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Indian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicCivil> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicObservational> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicTabular> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicUmmAlQura> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Japanese> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::JapaneseExtended> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Persian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Roc> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Buddhist> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Chinese> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Coptic> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Dangi> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Ethiopian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::EthiopianAmeteAlem> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Gregorian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Hebrew> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Indian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicCivil> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicObservational> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicTabular> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicUmmAlQura> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Japanese> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::JapaneseExtended> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Persian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Roc> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Buddhist> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Chinese> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Coptic> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Dangi> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Ethiopian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::EthiopianAmeteAlem> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Gregorian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Hebrew> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Indian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicCivil> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicObservational> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicTabular> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicUmmAlQura> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Japanese> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::JapaneseExtended> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Persian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Roc> + DataProvider<WeekdayNamesV1Marker> + DataProvider<ChineseCacheV1Marker> + DataProvider<DangiCacheV1Marker> + DataProvider<IslamicObservationalCacheV1Marker> + DataProvider<IslamicUmmAlQuraCacheV1Marker> + DataProvider<JapaneseErasV1Marker> + DataProvider<JapaneseExtendedErasV1Marker> + DataProvider<DecimalSymbolsV1Marker> + DataProvider<WeekDataV2Marker>,
pub fn try_new_with_length_unstable<P>(
provider: &P,
locale: &DataLocale,
length: Date,
) -> Result<Self, LoadError>where
P: ?Sized + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Buddhist> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Chinese> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Coptic> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Dangi> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Ethiopian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::EthiopianAmeteAlem> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Gregorian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Hebrew> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Indian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicCivil> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicObservational> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicTabular> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::IslamicUmmAlQura> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Japanese> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::JapaneseExtended> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Persian> + DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Roc> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Buddhist> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Chinese> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Coptic> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Dangi> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Ethiopian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::EthiopianAmeteAlem> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Gregorian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Hebrew> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Indian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicCivil> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicObservational> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicTabular> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::IslamicUmmAlQura> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Japanese> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::JapaneseExtended> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Persian> + DataProvider<<FullData as CalMarkers<MonthNamesV1Marker>>::Roc> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Buddhist> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Chinese> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Coptic> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Dangi> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Ethiopian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::EthiopianAmeteAlem> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Gregorian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Hebrew> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Indian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicCivil> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicObservational> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicTabular> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::IslamicUmmAlQura> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Japanese> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::JapaneseExtended> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Persian> + DataProvider<<FullData as CalMarkers<DatePatternV1Marker>>::Roc> + DataProvider<WeekdayNamesV1Marker> + DataProvider<ChineseCacheV1Marker> + DataProvider<DangiCacheV1Marker> + DataProvider<IslamicObservationalCacheV1Marker> + DataProvider<IslamicUmmAlQuraCacheV1Marker> + DataProvider<JapaneseErasV1Marker> + DataProvider<JapaneseExtendedErasV1Marker> + DataProvider<DecimalSymbolsV1Marker> + DataProvider<WeekDataV2Marker>,
A version of Self::try_new_with_length
that uses custom data provided by a DataProvider
.
๐ Help choosing a constructor
sourcepub fn format<T>(
&self,
date: &T,
) -> Result<FormattedNeoDate<'_>, MismatchedCalendarError>where
T: DateInput<Calendar = AnyCalendar>,
pub fn format<T>(
&self,
date: &T,
) -> Result<FormattedNeoDate<'_>, MismatchedCalendarError>where
T: DateInput<Calendar = AnyCalendar>,
Formats a date.
If the date is in neither ISO-8601 nor the same calendar system as the formatter, an error is returned.
For an example, see NeoDateFormatter
.