Enum icu::calendar::any_calendar::AnyCalendar
source · [−]#[non_exhaustive]
pub enum AnyCalendar {
Gregorian(Gregorian),
Buddhist(Buddhist),
Japanese(Japanese),
JapaneseExtended(JapaneseExtended),
Ethiopian(Ethiopian),
Indian(Indian),
Coptic(Coptic),
Iso(Iso),
}
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::try_new_with_any_provider()
,
AnyCalendar::try_new_with_buffer_provider()
, and AnyCalendar::try_new_unstable()
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, DateTime, japanese::Japanese, types::Time};
use icu::locid::locale;
let locale = locale!("en-u-ca-japanese"); // English with the Japanese calendar
let calendar = AnyCalendar::try_new_for_locale_unstable(&icu_testdata::unstable(), &locale.into())
.expect("constructing AnyCalendar failed");
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("heisei".parse().unwrap(), 15, "M03".parse().unwrap(), 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_datetime(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::try_new_unstable(&icu_testdata::unstable()).unwrap();
let japanese_datetime = DateTime::try_new_japanese_datetime("heisei".parse().unwrap(), 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
Gregorian(Gregorian)
A Gregorian
calendar
Buddhist(Buddhist)
A Buddhist
calendar
Japanese(Japanese)
A Japanese
calendar
JapaneseExtended(JapaneseExtended)
A JapaneseExtended
calendar
Ethiopian(Ethiopian)
An Ethiopian
calendar
Indian(Indian)
An Indian
calendar
Coptic(Coptic)
A Coptic
calendar
Iso(Iso)
An Iso
calendar
Implementations
sourceimpl AnyCalendar
impl AnyCalendar
sourcepub fn try_new_with_any_provider<P>(
provider: &P,
kind: AnyCalendarKind
) -> Result<AnyCalendar, CalendarError> where
P: AnyProvider + ?Sized,
pub fn try_new_with_any_provider<P>(
provider: &P,
kind: AnyCalendarKind
) -> Result<AnyCalendar, CalendarError> where
P: AnyProvider + ?Sized,
Constructs an AnyCalendar for a given calendar kind and AnyProvider
data source
As this requires a valid AnyCalendarKind
to work, it does not do any kind of locale-based
fallbacking. If this is desired, use Self::try_new_for_locale_with_any_provider()
.
For calendars that need data, will attempt to load the appropriate data from the source.
This API needs the calendar/japanese@1
or calendar/japanext@1
data key if working with Japanese calendars.
sourcepub fn try_new_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind
) -> Result<AnyCalendar, CalendarError> where
P: BufferProvider + ?Sized,
pub fn try_new_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind
) -> Result<AnyCalendar, CalendarError> where
P: BufferProvider + ?Sized,
Constructs an AnyCalendar for a given calendar kind and BufferProvider
data source
As this requires a valid AnyCalendarKind
to work, it does not do any kind of locale-based
fallbacking. If this is desired, use Self::try_new_for_locale_with_buffer_provider()
.
For calendars that need data, will attempt to load the appropriate data from the source.
This API needs the calendar/japanese@1
or calendar/japanext@1
data key if working with Japanese calendars.
This needs the "serde"
Cargo feature to be enabled to be used
sourcepub fn try_new_unstable<P>(
provider: &P,
kind: AnyCalendarKind
) -> Result<AnyCalendar, CalendarError> where
P: DataProvider<JapaneseErasV1Marker> + DataProvider<JapaneseExtendedErasV1Marker> + ?Sized,
pub fn try_new_unstable<P>(
provider: &P,
kind: AnyCalendarKind
) -> Result<AnyCalendar, CalendarError> where
P: DataProvider<JapaneseErasV1Marker> + DataProvider<JapaneseExtendedErasV1Marker> + ?Sized,
Constructs an AnyCalendar for a given calendar kind and data source.
This method is unstable; the bounds on P
might expand over time as more calendars are added
As this requires a valid AnyCalendarKind
to work, it does not do any kind of locale-based
fallbacking. If this is desired, use Self::try_new_for_locale_unstable()
.
For calendars that need data, will attempt to load the appropriate data from the source
sourcepub fn try_new_for_locale_with_any_provider(
provider: &impl AnyProvider,
locale: &DataLocale
) -> Result<AnyCalendar, CalendarError>
pub fn try_new_for_locale_with_any_provider(
provider: &impl AnyProvider,
locale: &DataLocale
) -> Result<AnyCalendar, CalendarError>
Creates a new instance using an AnyProvider
.
For details on the behavior of this function, see: Self::try_new_for_locale_unstable
sourcepub fn try_new_for_locale_with_buffer_provider(
provider: &impl BufferProvider,
locale: &DataLocale
) -> Result<AnyCalendar, CalendarError>
pub fn try_new_for_locale_with_buffer_provider(
provider: &impl BufferProvider,
locale: &DataLocale
) -> Result<AnyCalendar, CalendarError>
✨ Enabled with the "serde"
feature.
Creates a new instance using a BufferProvider
.
For details on the behavior of this function, see: Self::try_new_for_locale_unstable
sourcepub fn try_new_for_locale_unstable<P>(
provider: &P,
locale: &DataLocale
) -> Result<AnyCalendar, CalendarError> where
P: DataProvider<JapaneseErasV1Marker> + DataProvider<JapaneseExtendedErasV1Marker> + ?Sized,
pub fn try_new_for_locale_unstable<P>(
provider: &P,
locale: &DataLocale
) -> Result<AnyCalendar, CalendarError> where
P: DataProvider<JapaneseErasV1Marker> + DataProvider<JapaneseExtendedErasV1Marker> + ?Sized,
Constructs an AnyCalendar for a given calendar kind and data source.
This method is unstable; the bounds on P
might expand over time as more calendars are added
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.
For calendars that need data, will attempt to load the appropriate data from the source
sourcepub fn kind(&self) -> AnyCalendarKind
pub fn kind(&self) -> AnyCalendarKind
The AnyCalendarKind
corresponding to the calendar this contains
sourcepub fn convert_any_date(
&'a self,
date: &Date<impl AsCalendar<Calendar = AnyCalendar>>
) -> Date<Ref<'a, AnyCalendar>>
pub fn convert_any_date(
&'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 self,
date: &DateTime<impl AsCalendar<Calendar = AnyCalendar>>
) -> DateTime<Ref<'a, AnyCalendar>>
pub fn convert_any_datetime(
&'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
sourceimpl Calendar for AnyCalendar
impl Calendar for AnyCalendar
sourcefn year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> FormattableYear
fn year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> FormattableYear
The calendar-specific year represented by date
sourcefn month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> FormattableMonth
fn month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> FormattableMonth
The calendar-specific month represented by date
sourcefn 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
sourcefn 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
type DateInner = AnyDateInner
type DateInner = AnyDateInner
The internal type used to represent dates
sourcefn date_from_codes(
&self,
era: Era,
year: i32,
month_code: MonthCode,
day: u8
) -> Result<<AnyCalendar as Calendar>::DateInner, CalendarError>
fn date_from_codes(
&self,
era: Era,
year: i32,
month_code: MonthCode,
day: u8
) -> Result<<AnyCalendar as Calendar>::DateInner, CalendarError>
Construct a date from era/month codes and fields
sourcefn date_from_iso(&self, iso: Date<Iso>) -> AnyDateInner
fn date_from_iso(&self, iso: Date<Iso>) -> AnyDateInner
Construct the date from an ISO date
sourcefn date_to_iso(&self, date: &<AnyCalendar as Calendar>::DateInner) -> Date<Iso>
fn date_to_iso(&self, date: &<AnyCalendar as Calendar>::DateInner) -> Date<Iso>
Obtain an ISO date from this date
sourcefn months_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
fn months_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
Count the number of months in a given year, specified by providing a date from that year Read more
sourcefn days_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u32
fn days_in_year(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u32
Count the number of days in a given year, specified by providing a date from that year Read more
sourcefn days_in_month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
fn days_in_month(&self, date: &<AnyCalendar as Calendar>::DateInner) -> u8
Count the number of days in a given month, specified by providing a date from that year/month Read more
fn offset_date(
&self,
date: &mut <AnyCalendar as Calendar>::DateInner,
offset: DateDuration<AnyCalendar>
)
fn until(
&self,
date1: &<AnyCalendar as Calendar>::DateInner,
date2: &<AnyCalendar as Calendar>::DateInner,
calendar2: &AnyCalendar,
largest_unit: DateDurationUnit,
smallest_unit: DateDurationUnit
) -> DateDuration<AnyCalendar>
sourcefn debug_name(&self) -> &'static str
fn debug_name(&self) -> &'static str
Obtain a name for the calendar for debug printing
sourcefn any_calendar_kind(&self) -> Option<AnyCalendarKind>
fn any_calendar_kind(&self) -> Option<AnyCalendarKind>
The AnyCalendarKind
corresponding to this calendar,
if one exists. Implementors outside of icu_calendar should return None Read more
sourcefn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
fn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
Calculate the day of the week and return it
sourceimpl<C> From<C> for AnyCalendar where
C: IntoAnyCalendar,
impl<C> From<C> for AnyCalendar where
C: IntoAnyCalendar,
sourcefn from(c: C) -> AnyCalendar
fn from(c: C) -> AnyCalendar
Converts to this type from the input type.
Auto Trait Implementations
impl RefUnwindSafe for AnyCalendar
impl Send for AnyCalendar
impl Sync for AnyCalendar
impl Unpin for AnyCalendar
impl UnwindSafe for AnyCalendar
Blanket Implementations
sourceimpl<C> AsCalendar for C where
C: Calendar,
impl<C> AsCalendar for C where
C: Calendar,
type Calendar = C
type Calendar = C
The calendar being wrapped
sourcefn as_calendar(&self) -> &C
fn as_calendar(&self) -> &C
Obtain the inner calendar
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more