#[non_exhaustive]pub enum AnyCalendar {
Show 16 variants
Buddhist(Buddhist),
Chinese(Chinese),
Coptic(Coptic),
Dangi(Dangi),
Ethiopian(Ethiopian),
Gregorian(Gregorian),
Hebrew(Hebrew),
Indian(Indian),
HijriTabular(HijriTabular),
HijriSimulated(HijriSimulated),
HijriUmmAlQura(HijriUmmAlQura),
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, AnyCalendarKind, Date, cal::Japanese, types::MonthCode};
use icu::locale::locale;
use tinystr::tinystr;
let locale = locale!("en-u-ca-japanese"); // English with the Japanese calendar
let calendar = AnyCalendar::new(AnyCalendarKind::new(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.
// construct from era code, year, month code, day, and a calendar
// This is March 28, 15 Heisei
let manual_date = Date::try_new_from_codes(Some("heisei"), 15, MonthCode(tinystr!(4, "M03")), 28, calendar.clone())
.expect("Failed to construct Date manually");
// construct another date by converting from ISO
let iso_date = Date::try_new_iso(2020, 9, 1)
.expect("Failed to construct ISO Date.");
let iso_converted = iso_date.to_calendar(calendar);
// Construct a date in the appropriate typed calendar and convert
let japanese_calendar = Japanese::new();
let japanese_date = Date::try_new_japanese_with_calendar("heisei", 15, 3, 28,
japanese_calendar).unwrap();
// This is a Date<AnyCalendar>
let any_japanese_date = japanese_date.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
HijriTabular(HijriTabular)
A HijriTabular calendar
HijriSimulated(HijriSimulated)
A HijriSimulated calendar
HijriUmmAlQura(HijriUmmAlQura)
A HijriUmmAlQura 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) -> Self
pub const fn new(kind: AnyCalendarKind) -> Self
Constructs an AnyCalendar for a given calendar kind from compiled data.
✨ Enabled with the compiled_data Cargo feature.
Sourcepub fn try_new_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<Self, DataError>where
P: BufferProvider + ?Sized,
pub fn try_new_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<Self, 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<Self, DataError>
pub fn try_new_unstable<P>( provider: &P, kind: AnyCalendarKind, ) -> Result<Self, DataError>
A version of Self::new 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
Trait Implementations§
Source§impl Calendar for AnyCalendar
impl Calendar for AnyCalendar
Source§fn is_in_leap_year(&self, date: &Self::DateInner) -> bool
fn is_in_leap_year(&self, date: &Self::DateInner) -> bool
The calendar-specific check if date is in a leap year
Source§fn month(&self, date: &Self::DateInner) -> MonthInfo
fn month(&self, date: &Self::DateInner) -> MonthInfo
The calendar-specific month represented by date
Source§fn day_of_month(&self, date: &Self::DateInner) -> DayOfMonth
fn day_of_month(&self, date: &Self::DateInner) -> DayOfMonth
The calendar-specific day-of-month represented by date
Source§fn day_of_year(&self, date: &Self::DateInner) -> DayOfYear
fn day_of_year(&self, date: &Self::DateInner) -> DayOfYear
Information of the day of the year
Source§fn from_codes(
&self,
era: Option<&str>,
year: i32,
month_code: MonthCode,
day: u8,
) -> Result<Self::DateInner, DateError>
fn from_codes( &self, era: Option<&str>, year: i32, month_code: MonthCode, day: u8, ) -> Result<Self::DateInner, DateError>
Source§fn months_in_year(&self, date: &Self::DateInner) -> u8
fn months_in_year(&self, date: &Self::DateInner) -> u8
Source§fn days_in_year(&self, date: &Self::DateInner) -> u16
fn days_in_year(&self, date: &Self::DateInner) -> u16
Source§fn days_in_month(&self, date: &Self::DateInner) -> u8
fn days_in_month(&self, date: &Self::DateInner) -> u8
Source§fn extended_year(&self, date: &Self::DateInner) -> i32
fn extended_year(&self, date: &Self::DateInner) -> i32
Source§fn debug_name(&self) -> &'static str
fn debug_name(&self) -> &'static str
Source§fn calendar_algorithm(&self) -> Option<CalendarAlgorithm>
fn calendar_algorithm(&self) -> Option<CalendarAlgorithm>
CalendarAlgorithm that is required to match
when parsing into this calendar. Read moreSource§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<HijriSimulated> for AnyCalendar
impl From<HijriSimulated> for AnyCalendar
Source§fn from(value: HijriSimulated) -> AnyCalendar
fn from(value: HijriSimulated) -> AnyCalendar
Source§impl From<HijriTabular> for AnyCalendar
impl From<HijriTabular> for AnyCalendar
Source§fn from(value: HijriTabular) -> AnyCalendar
fn from(value: HijriTabular) -> AnyCalendar
Source§impl From<HijriUmmAlQura> for AnyCalendar
impl From<HijriUmmAlQura> for AnyCalendar
Source§fn from(value: HijriUmmAlQura) -> AnyCalendar
fn from(value: HijriUmmAlQura) -> 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<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 from_any(any: AnyCalendar) -> Result<Self, AnyCalendar>
fn from_any(any: AnyCalendar) -> Result<Self, AnyCalendar>
Source§fn from_any_ref(any: &AnyCalendar) -> Option<&Self>
fn from_any_ref(any: &AnyCalendar) -> Option<&Self>
Source§fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner
fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner
AnyDateInner Read moreimpl UnstableSealed for AnyCalendar
Auto 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§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