Enum AnyCalendar

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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.

📚 Help choosing a constructor

Source

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.

📚 Help choosing a constructor

Source

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.

📚 Help choosing a constructor

⚠️ The bounds on provider may change over time, including in SemVer minor releases.
Source

pub fn kind(&self) -> AnyCalendarKind

The AnyCalendarKind corresponding to the calendar this contains

Trait Implementations§

Source§

impl Calendar for AnyCalendar

Source§

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

The calendar-specific month represented by date

Source§

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

Information of the day of the year

Source§

type DateInner = AnyDateInner

The internal type used to represent dates
Source§

type Year = YearInfo

The type of YearInfo returned by the date
Source§

fn from_codes( &self, era: Option<&str>, year: i32, month_code: MonthCode, day: u8, ) -> Result<Self::DateInner, DateError>

Construct a date from era/month codes and fields Read more
Source§

fn from_iso(&self, iso: IsoDateInner) -> AnyDateInner

Construct the date from an ISO date
Source§

fn from_rata_die(&self, rd: RataDie) -> Self::DateInner

Construct the date from a RataDie
Source§

fn to_rata_die(&self, date: &Self::DateInner) -> RataDie

Obtain a RataDie from this date
Source§

fn to_iso(&self, date: &Self::DateInner) -> IsoDateInner

Obtain an ISO date from this date
Source§

fn months_in_year(&self, date: &Self::DateInner) -> u8

Count the number of months in a given year, specified by providing a date from that year
Source§

fn days_in_year(&self, date: &Self::DateInner) -> u16

Count the number of days in a given year, specified by providing a date from that year
Source§

fn days_in_month(&self, date: &Self::DateInner) -> u8

Count the number of days in a given month, specified by providing a date from that year/month
Source§

fn year_info(&self, date: &Self::DateInner) -> YearInfo

Information about the year
Source§

fn extended_year(&self, date: &Self::DateInner) -> i32

The extended year value
Source§

fn debug_name(&self) -> &'static str

Obtain a name for the calendar for debug printing
Source§

fn calendar_algorithm(&self) -> Option<CalendarAlgorithm>

Returns the CalendarAlgorithm that is required to match when parsing into this calendar. Read more
Source§

impl Clone for AnyCalendar

Source§

fn clone(&self) -> AnyCalendar

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnyCalendar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Buddhist> for AnyCalendar

Source§

fn from(value: Buddhist) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Chinese> for AnyCalendar

Source§

fn from(value: Chinese) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Coptic> for AnyCalendar

Source§

fn from(value: Coptic) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Dangi> for AnyCalendar

Source§

fn from(value: Dangi) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Ethiopian> for AnyCalendar

Source§

fn from(value: Ethiopian) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Gregorian> for AnyCalendar

Source§

fn from(value: Gregorian) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Hebrew> for AnyCalendar

Source§

fn from(value: Hebrew) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<HijriSimulated> for AnyCalendar

Source§

fn from(value: HijriSimulated) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<HijriTabular> for AnyCalendar

Source§

fn from(value: HijriTabular) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<HijriUmmAlQura> for AnyCalendar

Source§

fn from(value: HijriUmmAlQura) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Indian> for AnyCalendar

Source§

fn from(value: Indian) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Iso> for AnyCalendar

Source§

fn from(value: Iso) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Japanese> for AnyCalendar

Source§

fn from(value: Japanese) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<JapaneseExtended> for AnyCalendar

Source§

fn from(value: JapaneseExtended) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Persian> for AnyCalendar

Source§

fn from(value: Persian) -> AnyCalendar

Converts to this type from the input type.
Source§

impl From<Roc> for AnyCalendar

Source§

fn from(value: Roc) -> AnyCalendar

Converts to this type from the input type.
Source§

impl IntoAnyCalendar for AnyCalendar

Source§

fn to_any(self) -> AnyCalendar

Convert this calendar into an AnyCalendar, moving it Read more
Source§

fn kind(&self) -> AnyCalendarKind

The AnyCalendarKind enum variant associated with this calendar
Source§

fn from_any(any: AnyCalendar) -> Result<Self, AnyCalendar>

Move an AnyCalendar into a Self, or returning it as an error if the types do not match. Read more
Source§

fn from_any_ref(any: &AnyCalendar) -> Option<&Self>

Convert an AnyCalendar reference into a Self reference. Read more
Source§

fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner

Convert a date for this calendar into an AnyDateInner Read more
Source§

impl UnstableSealed for AnyCalendar

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<C> AsCalendar for C
where C: Calendar,

Source§

type Calendar = C

The calendar being wrapped
Source§

fn as_calendar(&self) -> &C

Obtain the inner calendar
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,