Enum icu::calendar::any_calendar::AnyCalendar
source · #[non_exhaustive]pub enum AnyCalendar {
Show 17 variants
Buddhist(Buddhist),
Chinese(Chinese),
Coptic(Coptic),
Dangi(Dangi),
Ethiopian(Ethiopian),
Gregorian(Gregorian),
Hebrew(Hebrew),
Indian(Indian),
IslamicCivil(IslamicCivil),
IslamicObservational(IslamicObservational),
IslamicTabular(IslamicTabular),
IslamicUmmAlQura(IslamicUmmAlQura),
Iso(Iso),
Japanese(Japanese),
JapaneseExtended(JapaneseExtended),
Persian(Persian),
Roc(Roc),
}
Expand description
This is a calendar that encompasses all formattable calendars supported by this crate
This allows for the construction of Date
objects that have their calendar known at runtime.
This can be constructed by calling .into()
on a concrete calendar type if the calendar type is known at
compile time. When the type is known at runtime, the AnyCalendar::new()
and sibling methods may be used.
Date
can also be converted to AnyCalendar
-compatible ones
via Date::to_any()
.
There are many ways of constructing an AnyCalendar’d date:
use icu::calendar::{AnyCalendar, DateTime, cal::Japanese, Time, types::{Era, MonthCode}};
use icu::locale::locale;
use tinystr::tinystr;
let locale = locale!("en-u-ca-japanese"); // English with the Japanese calendar
let calendar = AnyCalendar::new_for_locale(locale.into());
let calendar = Rc::new(calendar); // Avoid cloning it each time
// If everything is a local reference, you may use icu::calendar::Ref instead.
// manually construct a datetime in this calendar
let manual_time = Time::try_new(12, 33, 12, 0).expect("failed to construct Time");
// construct from era code, year, month code, day, time, and a calendar
// This is March 28, 15 Heisei
let manual_datetime = DateTime::try_new_from_codes(Some(Era(tinystr!(16, "heisei"))), 15, MonthCode(tinystr!(4, "M03")), 28,
manual_time, calendar.clone())
.expect("Failed to construct DateTime manually");
// construct another datetime by converting from ISO
let iso_datetime = DateTime::try_new_iso(2020, 9, 1, 12, 34, 28)
.expect("Failed to construct ISO DateTime.");
let iso_converted = iso_datetime.to_calendar(calendar);
// Construct a datetime in the appropriate typed calendar and convert
let japanese_calendar = Japanese::new();
let japanese_datetime = DateTime::try_new_japanese_with_calendar(Era(tinystr!(16, "heisei")), 15, 3, 28,
12, 33, 12, japanese_calendar).unwrap();
// This is a DateTime<AnyCalendar>
let any_japanese_datetime = japanese_datetime.to_any();
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Buddhist(Buddhist)
A Buddhist
calendar
Chinese(Chinese)
A Chinese
calendar
Coptic(Coptic)
A Coptic
calendar
Dangi(Dangi)
A Dangi
calendar
Ethiopian(Ethiopian)
An Ethiopian
calendar
Gregorian(Gregorian)
A Gregorian
calendar
Hebrew(Hebrew)
A Hebrew
calendar
Indian(Indian)
An Indian
calendar
IslamicCivil(IslamicCivil)
An IslamicCivil
calendar
IslamicObservational(IslamicObservational)
An IslamicObservational
calendar
IslamicTabular(IslamicTabular)
An IslamicTabular
calendar
IslamicUmmAlQura(IslamicUmmAlQura)
An IslamicUmmAlQura
calendar
Iso(Iso)
An Iso
calendar
Japanese(Japanese)
A Japanese
calendar
JapaneseExtended(JapaneseExtended)
A JapaneseExtended
calendar
Persian(Persian)
A Persian
calendar
Roc(Roc)
A Roc
calendar
Implementations§
source§impl AnyCalendar
impl AnyCalendar
sourcepub const fn new(kind: AnyCalendarKind) -> AnyCalendar
pub const fn new(kind: AnyCalendarKind) -> AnyCalendar
Constructs an AnyCalendar for a given calendar kind from compiled data.
As this requires a valid AnyCalendarKind
to work, it does not do any kind of locale-based
fallbacking. If this is desired, use Self::new_for_locale()
.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_any_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<AnyCalendar, DataError>where
P: AnyProvider + ?Sized,
pub fn try_new_with_any_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<AnyCalendar, DataError>where
P: AnyProvider + ?Sized,
A version of Self::new
that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<AnyCalendar, DataError>where
P: BufferProvider + ?Sized,
pub fn try_new_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<AnyCalendar, DataError>where
P: BufferProvider + ?Sized,
A version of Self::new
that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<AnyCalendar, DataError>
pub fn try_new_unstable<P>( provider: &P, kind: AnyCalendarKind, ) -> Result<AnyCalendar, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
sourcepub fn new_for_locale(prefs: AnyCalendarPreferences) -> AnyCalendar
pub fn new_for_locale(prefs: AnyCalendarPreferences) -> AnyCalendar
Constructs an AnyCalendar for a given calendar kind from compiled data.
In case the locale’s calendar is unknown or unspecified, it will attempt to load the default calendar for the locale, falling back to gregorian.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_for_locale_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
prefs: AnyCalendarPreferences,
) -> Result<AnyCalendar, DataError>
pub fn try_new_for_locale_with_any_provider( provider: &(impl AnyProvider + ?Sized), prefs: AnyCalendarPreferences, ) -> Result<AnyCalendar, DataError>
A version of [Self :: new_for_locale
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_for_locale_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
prefs: AnyCalendarPreferences,
) -> Result<AnyCalendar, DataError>
pub fn try_new_for_locale_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), prefs: AnyCalendarPreferences, ) -> Result<AnyCalendar, DataError>
A version of [Self :: new_for_locale
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_for_locale_unstable<P>(
provider: &P,
prefs: AnyCalendarPreferences,
) -> Result<AnyCalendar, DataError>
pub fn try_new_for_locale_unstable<P>( provider: &P, prefs: AnyCalendarPreferences, ) -> Result<AnyCalendar, DataError>
A version of Self::new_for_locale
that uses custom data provided by a DataProvider
.
sourcepub fn kind(&self) -> AnyCalendarKind
pub fn kind(&self) -> AnyCalendarKind
The AnyCalendarKind
corresponding to the calendar this contains
sourcepub fn convert_any_date<'a>(
&'a self,
date: &Date<impl AsCalendar<Calendar = AnyCalendar>>,
) -> Date<Ref<'a, AnyCalendar>>
pub fn convert_any_date<'a>( &'a self, date: &Date<impl AsCalendar<Calendar = AnyCalendar>>, ) -> Date<Ref<'a, AnyCalendar>>
Given an AnyCalendar date, convert that date to another AnyCalendar date in this calendar, if conversion is needed
sourcepub fn convert_any_datetime<'a>(
&'a self,
date: &DateTime<impl AsCalendar<Calendar = AnyCalendar>>,
) -> DateTime<Ref<'a, AnyCalendar>>
pub fn convert_any_datetime<'a>( &'a self, date: &DateTime<impl AsCalendar<Calendar = AnyCalendar>>, ) -> DateTime<Ref<'a, AnyCalendar>>
Given an AnyCalendar datetime, convert that date to another AnyCalendar datetime in this calendar, if conversion is needed
Trait Implementations§
source§impl Calendar for AnyCalendar
impl Calendar for AnyCalendar
source§fn is_in_leap_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> bool
fn is_in_leap_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> bool
The calendar-specific check if date
is in a leap year
source§fn month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> MonthInfo
fn month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> MonthInfo
The calendar-specific month represented by date
source§fn day_of_month(
&self,
date: &<AnyCalendar as Calendar>::DateInner,
) -> DayOfMonth
fn day_of_month( &self, date: &<AnyCalendar as Calendar>::DateInner, ) -> DayOfMonth
The calendar-specific day-of-month represented by date
source§fn day_of_year_info(
&self,
date: &<AnyCalendar as Calendar>::DateInner,
) -> DayOfYearInfo
fn day_of_year_info( &self, date: &<AnyCalendar as Calendar>::DateInner, ) -> DayOfYearInfo
Information of the day of the year
source§type DateInner = AnyDateInner
type DateInner = AnyDateInner
source§fn date_from_codes(
&self,
era: Option<Era>,
year: i32,
month_code: MonthCode,
day: u8,
) -> Result<<AnyCalendar as Calendar>::DateInner, DateError>
fn date_from_codes( &self, era: Option<Era>, year: i32, month_code: MonthCode, day: u8, ) -> Result<<AnyCalendar as Calendar>::DateInner, DateError>
source§fn date_from_iso(&self, iso: Date<Iso>) -> AnyDateInner
fn date_from_iso(&self, iso: Date<Iso>) -> AnyDateInner
source§fn date_to_iso(&self, date: &<AnyCalendar as Calendar>::DateInner) -> Date<Iso>
fn date_to_iso(&self, date: &<AnyCalendar as Calendar>::DateInner) -> Date<Iso>
source§fn months_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
fn months_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
source§fn days_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u16
fn days_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u16
source§fn days_in_month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
fn days_in_month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
source§fn year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> YearInfo
fn year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> YearInfo
source§fn debug_name(&self) -> &'static str
fn debug_name(&self) -> &'static str
source§fn any_calendar_kind(&self) -> Option<AnyCalendarKind>
fn any_calendar_kind(&self) -> Option<AnyCalendarKind>
AnyCalendarKind
corresponding to this calendar,
if one exists. Implementors outside of icu::calendar
should return None
source§fn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
fn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
source§impl Clone for AnyCalendar
impl Clone for AnyCalendar
source§fn clone(&self) -> AnyCalendar
fn clone(&self) -> AnyCalendar
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AnyCalendar
impl Debug for AnyCalendar
source§impl From<Buddhist> for AnyCalendar
impl From<Buddhist> for AnyCalendar
source§fn from(value: Buddhist) -> AnyCalendar
fn from(value: Buddhist) -> AnyCalendar
source§impl From<Chinese> for AnyCalendar
impl From<Chinese> for AnyCalendar
source§fn from(value: Chinese) -> AnyCalendar
fn from(value: Chinese) -> AnyCalendar
source§impl From<Coptic> for AnyCalendar
impl From<Coptic> for AnyCalendar
source§fn from(value: Coptic) -> AnyCalendar
fn from(value: Coptic) -> AnyCalendar
source§impl From<Dangi> for AnyCalendar
impl From<Dangi> for AnyCalendar
source§fn from(value: Dangi) -> AnyCalendar
fn from(value: Dangi) -> AnyCalendar
source§impl From<Ethiopian> for AnyCalendar
impl From<Ethiopian> for AnyCalendar
source§fn from(value: Ethiopian) -> AnyCalendar
fn from(value: Ethiopian) -> AnyCalendar
source§impl From<Gregorian> for AnyCalendar
impl From<Gregorian> for AnyCalendar
source§fn from(value: Gregorian) -> AnyCalendar
fn from(value: Gregorian) -> AnyCalendar
source§impl From<Hebrew> for AnyCalendar
impl From<Hebrew> for AnyCalendar
source§fn from(value: Hebrew) -> AnyCalendar
fn from(value: Hebrew) -> AnyCalendar
source§impl From<Indian> for AnyCalendar
impl From<Indian> for AnyCalendar
source§fn from(value: Indian) -> AnyCalendar
fn from(value: Indian) -> AnyCalendar
source§impl From<IslamicCivil> for AnyCalendar
impl From<IslamicCivil> for AnyCalendar
source§fn from(value: IslamicCivil) -> AnyCalendar
fn from(value: IslamicCivil) -> AnyCalendar
source§impl From<IslamicObservational> for AnyCalendar
impl From<IslamicObservational> for AnyCalendar
source§fn from(value: IslamicObservational) -> AnyCalendar
fn from(value: IslamicObservational) -> AnyCalendar
source§impl From<IslamicTabular> for AnyCalendar
impl From<IslamicTabular> for AnyCalendar
source§fn from(value: IslamicTabular) -> AnyCalendar
fn from(value: IslamicTabular) -> AnyCalendar
source§impl From<IslamicUmmAlQura> for AnyCalendar
impl From<IslamicUmmAlQura> for AnyCalendar
source§fn from(value: IslamicUmmAlQura) -> AnyCalendar
fn from(value: IslamicUmmAlQura) -> AnyCalendar
source§impl From<Iso> for AnyCalendar
impl From<Iso> for AnyCalendar
source§fn from(value: Iso) -> AnyCalendar
fn from(value: Iso) -> AnyCalendar
source§impl From<Japanese> for AnyCalendar
impl From<Japanese> for AnyCalendar
source§fn from(value: Japanese) -> AnyCalendar
fn from(value: Japanese) -> AnyCalendar
source§impl From<JapaneseExtended> for AnyCalendar
impl From<JapaneseExtended> for AnyCalendar
source§fn from(value: JapaneseExtended) -> AnyCalendar
fn from(value: JapaneseExtended) -> AnyCalendar
source§impl From<Persian> for AnyCalendar
impl From<Persian> for AnyCalendar
source§fn from(value: Persian) -> AnyCalendar
fn from(value: Persian) -> AnyCalendar
source§impl From<Roc> for AnyCalendar
impl From<Roc> for AnyCalendar
source§fn from(value: Roc) -> AnyCalendar
fn from(value: Roc) -> AnyCalendar
source§impl IntoAnyCalendar for AnyCalendar
impl IntoAnyCalendar for AnyCalendar
source§fn to_any(self) -> AnyCalendar
fn to_any(self) -> AnyCalendar
AnyCalendar
, moving it Read moresource§fn kind(&self) -> AnyCalendarKind
fn kind(&self) -> AnyCalendarKind
AnyCalendarKind
enum variant associated with this calendarsource§fn to_any_cloned(&self) -> AnyCalendar
fn to_any_cloned(&self) -> AnyCalendar
AnyCalendar
, cloning it Read moresource§fn from_any(any: AnyCalendar) -> Result<AnyCalendar, AnyCalendar>
fn from_any(any: AnyCalendar) -> Result<AnyCalendar, AnyCalendar>
source§fn from_any_ref(any: &AnyCalendar) -> Option<&AnyCalendar>
fn from_any_ref(any: &AnyCalendar) -> Option<&AnyCalendar>
source§fn date_to_any(&self, d: &<AnyCalendar as Calendar>::DateInner) -> AnyDateInner
fn date_to_any(&self, d: &<AnyCalendar as Calendar>::DateInner) -> AnyDateInner
AnyDateInner
Read moreAuto Trait Implementations§
impl Freeze for AnyCalendar
impl RefUnwindSafe for AnyCalendar
impl Send for AnyCalendar
impl Sync for AnyCalendar
impl Unpin for AnyCalendar
impl UnwindSafe for AnyCalendar
Blanket Implementations§
source§impl<C> AsCalendar for Cwhere
C: Calendar,
impl<C> AsCalendar for Cwhere
C: Calendar,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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