pub struct Date<A>where
A: AsCalendar,{ /* private fields */ }
Expand description
A date for a given calendar.
The primary definition of this type is in the icu_calendar
crate. Other ICU4X crates re-export it for convenience.
This can work with wrappers around Calendar
types,
e.g. Rc<C>
, via the AsCalendar
trait.
This can be constructed constructed
from its fields via Self::try_new_from_codes()
, or can be constructed with one of the
new_<calendar>_date()
per-calendar methods (and then freely converted between calendars).
use icu::calendar::Date;
// Example: creation of ISO date from integers.
let date_iso = Date::try_new_iso(1970, 1, 2)
.expect("Failed to initialize ISO Date instance.");
assert_eq!(date_iso.era_year().year, 1970);
assert_eq!(date_iso.month().ordinal, 1);
assert_eq!(date_iso.day_of_month().0, 2);
Implementations§
Source§impl<A> Date<A>where
A: AsCalendar,
impl<A> Date<A>where
A: AsCalendar,
Sourcepub fn try_new_from_codes(
era: Option<&str>,
year: i32,
month_code: MonthCode,
day: u8,
calendar: A,
) -> Result<Date<A>, DateError>
pub fn try_new_from_codes( era: Option<&str>, year: i32, month_code: MonthCode, day: u8, calendar: A, ) -> Result<Date<A>, DateError>
Construct a date from from era/month codes and fields, and some calendar representation
The year is extended_year
if no era is provided
Sourcepub fn from_rata_die(rd: RataDie, calendar: A) -> Date<A>
pub fn from_rata_die(rd: RataDie, calendar: A) -> Date<A>
Construct a date from a RataDie
and some calendar representation
Sourcepub fn to_rata_die(&self) -> RataDie
pub fn to_rata_die(&self) -> RataDie
Convert the date to a RataDie
Sourcepub fn new_from_iso(iso: Date<Iso>, calendar: A) -> Date<A>
pub fn new_from_iso(iso: Date<Iso>, calendar: A) -> Date<A>
Construct a date from an ISO date and some calendar representation
Sourcepub fn to_calendar<A2>(&self, calendar: A2) -> Date<A2>where
A2: AsCalendar,
pub fn to_calendar<A2>(&self, calendar: A2) -> Date<A2>where
A2: AsCalendar,
Convert the Date to a date in a different calendar
Sourcepub fn months_in_year(&self) -> u8
pub fn months_in_year(&self) -> u8
The number of months in the year of this date
Sourcepub fn days_in_year(&self) -> u16
pub fn days_in_year(&self) -> u16
The number of days in the year of this date
Sourcepub fn days_in_month(&self) -> u8
pub fn days_in_month(&self) -> u8
The number of days in the month of this date
Sourcepub fn day_of_week(&self) -> Weekday
pub fn day_of_week(&self) -> Weekday
The day of the week for this date
Sourcepub fn year(&self) -> YearInfo
pub fn year(&self) -> YearInfo
The calendar-specific year-info.
This returns an enum, see Date::era_year()
and Date::cyclic_year()
which are available
for concrete calendar types and return concrete types.
Sourcepub fn extended_year(&self) -> i32
pub fn extended_year(&self) -> i32
The “extended year”, typically anchored with year 1 as the year 1 of either the most modern or otherwise some “major” era for the calendar
See Self::year()
for more information about the year.
Sourcepub fn is_in_leap_year(&self) -> bool
pub fn is_in_leap_year(&self) -> bool
Returns whether self
is in a calendar-specific leap year
Sourcepub fn day_of_month(&self) -> DayOfMonth
pub fn day_of_month(&self) -> DayOfMonth
The calendar-specific day-of-month represented by self
Sourcepub fn day_of_year(&self) -> DayOfYear
pub fn day_of_year(&self) -> DayOfYear
The calendar-specific day-of-month represented by self
Sourcepub fn from_raw(
inner: <<A as AsCalendar>::Calendar as Calendar>::DateInner,
calendar: A,
) -> Date<A>
pub fn from_raw( inner: <<A as AsCalendar>::Calendar as Calendar>::DateInner, calendar: A, ) -> Date<A>
Construct a date from raw values for a given calendar. This does not check any invariants for the date and calendar, and should only be called by calendar implementations.
Calling this outside of calendar implementations is sound, but calendar implementations are not expected to do anything sensible with such invalid dates.
AnyCalendar will panic if AnyCalendar Date
objects with mismatching
date and calendar types are constructed
Sourcepub fn inner(&self) -> &<<A as AsCalendar>::Calendar as Calendar>::DateInner
pub fn inner(&self) -> &<<A as AsCalendar>::Calendar as Calendar>::DateInner
Get the inner date implementation. Should not be called outside of calendar implementations
Sourcepub fn calendar(&self) -> &<A as AsCalendar>::Calendar
pub fn calendar(&self) -> &<A as AsCalendar>::Calendar
Get a reference to the contained calendar
Sourcepub fn calendar_wrapper(&self) -> &A
pub fn calendar_wrapper(&self) -> &A
Get a reference to the contained calendar wrapper
(Useful in case the user wishes to e.g. clone an Rc)
Source§impl<A, C> Date<A>
impl<A, C> Date<A>
Sourcepub fn cyclic_year(&self) -> CyclicYear
pub fn cyclic_year(&self) -> CyclicYear
Returns information about the year cycle, for cyclic calendars.
Source§impl Date<Iso>
impl Date<Iso>
Sourcepub fn week_of_year(&self) -> IsoWeekOfYear
pub fn week_of_year(&self) -> IsoWeekOfYear
The ISO week of the year containing this date.
§Examples
use icu::calendar::types::IsoWeekOfYear;
use icu::calendar::Date;
let date = Date::try_new_iso(2022, 8, 26).unwrap();
assert_eq!(
date.week_of_year(),
IsoWeekOfYear {
week_number: 34,
iso_year: 2022,
}
);
Source§impl<C> Date<C>where
C: IntoAnyCalendar,
impl<C> Date<C>where
C: IntoAnyCalendar,
Sourcepub fn to_any(self) -> Date<AnyCalendar>
pub fn to_any(self) -> Date<AnyCalendar>
Type-erase the date, converting it to a date for AnyCalendar
Source§impl<A> Date<A>where
A: AsCalendar,
impl<A> Date<A>where
A: AsCalendar,
Sourcepub fn into_ref_counted(self) -> Date<Rc<A>>
pub fn into_ref_counted(self) -> Date<Rc<A>>
Wrap the contained calendar type in Rc<T>
, making it cheaper to clone.
Useful when paired with Self::to_any()
to obtain a Date<Rc<AnyCalendar>>
Sourcepub fn into_atomic_ref_counted(self) -> Date<Arc<A>>
pub fn into_atomic_ref_counted(self) -> Date<Arc<A>>
Wrap the contained calendar type in Arc<T>
, making it cheaper to clone in a thread-safe manner.
Useful when paired with Self::to_any()
to obtain a Date<Arc<AnyCalendar>>
Sourcepub fn as_borrowed(&self) -> Date<Ref<'_, A>>
pub fn as_borrowed(&self) -> Date<Ref<'_, A>>
Wrap the calendar type in Ref<T>
, making it cheaper to clone (by introducing a borrow)
Useful for converting a &Date<C>
into an equivalent Date<D>
without cloning
the calendar.
Source§impl<C> Date<C>where
C: AsCalendar<Calendar = AnyCalendar>,
impl<C> Date<C>where
C: AsCalendar<Calendar = AnyCalendar>,
Sourcepub fn convert_any<'a>(
&self,
calendar: &'a AnyCalendar,
) -> Date<Ref<'a, AnyCalendar>>
pub fn convert_any<'a>( &self, calendar: &'a AnyCalendar, ) -> Date<Ref<'a, AnyCalendar>>
Convert this Date<AnyCalendar>
to another AnyCalendar
, if conversion is needed
Source§impl Date<Buddhist>
impl Date<Buddhist>
Sourcepub fn try_new_buddhist(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Buddhist>, RangeError>
pub fn try_new_buddhist( year: i32, month: u8, day: u8, ) -> Result<Date<Buddhist>, RangeError>
Construct a new Buddhist Date.
Years are specified as BE years.
use icu::calendar::Date;
let date_buddhist = Date::try_new_buddhist(1970, 1, 2)
.expect("Failed to initialize Buddhist Date instance.");
assert_eq!(date_buddhist.era_year().year, 1970);
assert_eq!(date_buddhist.month().ordinal, 1);
assert_eq!(date_buddhist.day_of_month().0, 2);
Source§impl<A> Date<A>where
A: AsCalendar<Calendar = Chinese>,
impl<A> Date<A>where
A: AsCalendar<Calendar = Chinese>,
Sourcepub fn try_new_chinese_with_calendar(
related_iso_year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, DateError>
pub fn try_new_chinese_with_calendar( related_iso_year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, DateError>
Construct a new Chinese date from a year
, month
, and day
.
year
represents the ISO year that roughly matches the Chinese year;
month
represents the month of the year ordinally (ex. if it is a leap year, the last month will be 13, not 12);
day
indicates the day of month
This date will not use any precomputed calendrical calculations, one that loads such data from a provider will be added in the future (#3933)
use icu::calendar::{cal::Chinese, Date};
let chinese = Chinese::new_always_calculating();
let date_chinese =
Date::try_new_chinese_with_calendar(2023, 6, 11, chinese)
.expect("Failed to initialize Chinese Date instance.");
assert_eq!(date_chinese.cyclic_year().related_iso, 2023);
assert_eq!(date_chinese.cyclic_year().year, 40);
assert_eq!(date_chinese.month().ordinal, 6);
assert_eq!(date_chinese.day_of_month().0, 11);
Source§impl Date<Coptic>
impl Date<Coptic>
Sourcepub fn try_new_coptic(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Coptic>, RangeError>
pub fn try_new_coptic( year: i32, month: u8, day: u8, ) -> Result<Date<Coptic>, RangeError>
Construct new Coptic Date.
use icu::calendar::Date;
let date_coptic = Date::try_new_coptic(1686, 5, 6)
.expect("Failed to initialize Coptic Date instance.");
assert_eq!(date_coptic.era_year().year, 1686);
assert_eq!(date_coptic.month().ordinal, 5);
assert_eq!(date_coptic.day_of_month().0, 6);
Source§impl<A> Date<A>where
A: AsCalendar<Calendar = Dangi>,
impl<A> Date<A>where
A: AsCalendar<Calendar = Dangi>,
Sourcepub fn try_new_dangi_with_calendar(
related_iso_year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, DateError>
pub fn try_new_dangi_with_calendar( related_iso_year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, DateError>
Construct a new Dangi date from a year
, month
, and day
.
year
represents the ISO year that roughly matches the Dangi year;
month
represents the month of the year ordinally (ex. if it is a leap year, the last month will be 13, not 12);
day
indicates day of month.
This date will not use any precomputed calendrical calculations, one that loads such data from a provider will be added in the future (#3933)
use icu::calendar::cal::Dangi;
use icu::calendar::Date;
let dangi = Dangi::new();
let date_dangi = Date::try_new_dangi_with_calendar(2023, 6, 18, dangi)
.expect("Failed to initialize Dangi Date instance.");
assert_eq!(date_dangi.cyclic_year().related_iso, 2023);
assert_eq!(date_dangi.cyclic_year().year, 40);
assert_eq!(date_dangi.month().ordinal, 6);
assert_eq!(date_dangi.day_of_month().0, 18);
Source§impl Date<Ethiopian>
impl Date<Ethiopian>
Sourcepub fn try_new_ethiopian(
era_style: EthiopianEraStyle,
year: i32,
month: u8,
day: u8,
) -> Result<Date<Ethiopian>, RangeError>
pub fn try_new_ethiopian( era_style: EthiopianEraStyle, year: i32, month: u8, day: u8, ) -> Result<Date<Ethiopian>, RangeError>
Construct new Ethiopian Date.
use icu::calendar::cal::EthiopianEraStyle;
use icu::calendar::Date;
let date_ethiopian =
Date::try_new_ethiopian(EthiopianEraStyle::AmeteMihret, 2014, 8, 25)
.expect("Failed to initialize Ethopic Date instance.");
assert_eq!(date_ethiopian.era_year().year, 2014);
assert_eq!(date_ethiopian.month().ordinal, 8);
assert_eq!(date_ethiopian.day_of_month().0, 25);
Source§impl Date<Gregorian>
impl Date<Gregorian>
Sourcepub fn try_new_gregorian(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Gregorian>, RangeError>
pub fn try_new_gregorian( year: i32, month: u8, day: u8, ) -> Result<Date<Gregorian>, RangeError>
Construct a new Gregorian Date.
Years are specified as ISO years.
use icu::calendar::Date;
// Conversion from ISO to Gregorian
let date_gregorian = Date::try_new_gregorian(1970, 1, 2)
.expect("Failed to initialize Gregorian Date instance.");
assert_eq!(date_gregorian.era_year().year, 1970);
assert_eq!(date_gregorian.month().ordinal, 1);
assert_eq!(date_gregorian.day_of_month().0, 2);
Source§impl Date<Hebrew>
impl Date<Hebrew>
Sourcepub fn try_new_hebrew(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Hebrew>, RangeError>
pub fn try_new_hebrew( year: i32, month: u8, day: u8, ) -> Result<Date<Hebrew>, RangeError>
Construct new Hebrew Date.
This date will not use any precomputed calendrical calculations, one that loads such data from a provider will be added in the future (#3933)
use icu::calendar::Date;
let date_hebrew = Date::try_new_hebrew(3425, 4, 25)
.expect("Failed to initialize Hebrew Date instance.");
assert_eq!(date_hebrew.era_year().year, 3425);
assert_eq!(date_hebrew.month().ordinal, 4);
assert_eq!(date_hebrew.day_of_month().0, 25);
Source§impl<A> Date<A>where
A: AsCalendar<Calendar = HijriSimulated>,
impl<A> Date<A>where
A: AsCalendar<Calendar = HijriSimulated>,
Sourcepub fn try_new_simulated_hijri_with_calendar(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, RangeError>
pub fn try_new_simulated_hijri_with_calendar( year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, RangeError>
Construct new simulated Hijri Date.
use icu::calendar::cal::HijriSimulated;
use icu::calendar::Date;
let hijri = HijriSimulated::new_mecca_always_calculating();
let date_hijri =
Date::try_new_simulated_hijri_with_calendar(1392, 4, 25, hijri)
.expect("Failed to initialize Hijri Date instance.");
assert_eq!(date_hijri.era_year().year, 1392);
assert_eq!(date_hijri.month().ordinal, 4);
assert_eq!(date_hijri.day_of_month().0, 25);
Source§impl Date<HijriUmmAlQura>
impl Date<HijriUmmAlQura>
Sourcepub fn try_new_ummalqura(
year: i32,
month: u8,
day: u8,
) -> Result<Date<HijriUmmAlQura>, RangeError>
pub fn try_new_ummalqura( year: i32, month: u8, day: u8, ) -> Result<Date<HijriUmmAlQura>, RangeError>
Construct new Hijri Umm al-Qura Date.
use icu::calendar::cal::HijriUmmAlQura;
use icu::calendar::Date;
let date_hijri = Date::try_new_ummalqura(1392, 4, 25)
.expect("Failed to initialize Hijri Date instance.");
assert_eq!(date_hijri.era_year().year, 1392);
assert_eq!(date_hijri.month().ordinal, 4);
assert_eq!(date_hijri.day_of_month().0, 25);
Source§impl<A> Date<A>where
A: AsCalendar<Calendar = HijriTabular>,
impl<A> Date<A>where
A: AsCalendar<Calendar = HijriTabular>,
Sourcepub fn try_new_hijri_tabular_with_calendar(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, RangeError>
pub fn try_new_hijri_tabular_with_calendar( year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, RangeError>
Construct new Tabular Hijri Date.
use icu::calendar::cal::{
HijriTabular, HijriTabularEpoch, HijriTabularLeapYears,
};
use icu::calendar::Date;
let hijri = HijriTabular::new(
HijriTabularLeapYears::TypeII,
HijriTabularEpoch::Thursday,
);
let date_hijri =
Date::try_new_hijri_tabular_with_calendar(1392, 4, 25, hijri)
.expect("Failed to initialize Hijri Date instance.");
assert_eq!(date_hijri.era_year().year, 1392);
assert_eq!(date_hijri.month().ordinal, 4);
assert_eq!(date_hijri.day_of_month().0, 25);
Source§impl Date<Indian>
impl Date<Indian>
Sourcepub fn try_new_indian(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Indian>, RangeError>
pub fn try_new_indian( year: i32, month: u8, day: u8, ) -> Result<Date<Indian>, RangeError>
Construct new Indian Date, with year provided in the Śaka era.
use icu::calendar::Date;
let date_indian = Date::try_new_indian(1891, 10, 12)
.expect("Failed to initialize Indian Date instance.");
assert_eq!(date_indian.era_year().year, 1891);
assert_eq!(date_indian.month().ordinal, 10);
assert_eq!(date_indian.day_of_month().0, 12);
Source§impl Date<Iso>
impl Date<Iso>
Sourcepub fn try_new_iso(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Iso>, RangeError>
pub fn try_new_iso( year: i32, month: u8, day: u8, ) -> Result<Date<Iso>, RangeError>
Construct a new ISO date from integers.
use icu::calendar::Date;
let date_iso = Date::try_new_iso(1970, 1, 2)
.expect("Failed to initialize ISO Date instance.");
assert_eq!(date_iso.era_year().year, 1970);
assert_eq!(date_iso.month().ordinal, 1);
assert_eq!(date_iso.day_of_month().0, 2);
Source§impl Date<Japanese>
impl Date<Japanese>
Sourcepub fn try_new_japanese_with_calendar<A>(
era: &str,
year: i32,
month: u8,
day: u8,
japanese_calendar: A,
) -> Result<Date<A>, DateError>where
A: AsCalendar<Calendar = Japanese>,
pub fn try_new_japanese_with_calendar<A>(
era: &str,
year: i32,
month: u8,
day: u8,
japanese_calendar: A,
) -> Result<Date<A>, DateError>where
A: AsCalendar<Calendar = Japanese>,
Construct a new Japanese Date.
Years are specified in the era provided, and must be in range for Japanese eras (e.g. dates past April 30 Heisei 31 must be in Reiwa; “Jun 5 Heisei 31” and “Jan 1 Heisei 32” will not be adjusted to being in Reiwa 1 and 2 respectively)
However, dates may always be specified in “bce” or “ce” and they will be adjusted as necessary.
use icu::calendar::cal::Japanese;
use icu::calendar::{Date, Ref};
use tinystr::tinystr;
let japanese_calendar = Japanese::new();
// for easy sharing
let japanese_calendar = Ref(&japanese_calendar);
let era = "heisei";
let date =
Date::try_new_japanese_with_calendar(era, 14, 1, 2, japanese_calendar)
.expect("Constructing a date should succeed");
assert_eq!(date.era_year().era, era);
assert_eq!(date.era_year().year, 14);
assert_eq!(date.month().ordinal, 1);
assert_eq!(date.day_of_month().0, 2);
// This function will error for eras that are out of bounds:
// (Heisei was 32 years long, Heisei 33 is in Reiwa)
let oob_date =
Date::try_new_japanese_with_calendar(era, 33, 1, 2, japanese_calendar);
assert!(oob_date.is_err());
// and for unknown eras
let fake_era = "neko"; // 🐱
let fake_date = Date::try_new_japanese_with_calendar(
fake_era,
10,
1,
2,
japanese_calendar,
);
assert!(fake_date.is_err());
Source§impl Date<JapaneseExtended>
impl Date<JapaneseExtended>
Sourcepub fn try_new_japanese_extended_with_calendar<A>(
era: &str,
year: i32,
month: u8,
day: u8,
japanext_calendar: A,
) -> Result<Date<A>, DateError>where
A: AsCalendar<Calendar = JapaneseExtended>,
pub fn try_new_japanese_extended_with_calendar<A>(
era: &str,
year: i32,
month: u8,
day: u8,
japanext_calendar: A,
) -> Result<Date<A>, DateError>where
A: AsCalendar<Calendar = JapaneseExtended>,
Construct a new Japanese Date with all eras.
Years are specified in the era provided, and must be in range for Japanese eras (e.g. dates past April 30 Heisei 31 must be in Reiwa; “Jun 5 Heisei 31” and “Jan 1 Heisei 32” will not be adjusted to being in Reiwa 1 and 2 respectively)
However, dates may always be specified in “bce” or “ce” and they will be adjusted as necessary.
use icu::calendar::cal::JapaneseExtended;
use icu::calendar::{Date, Ref};
use tinystr::tinystr;
let japanext_calendar = JapaneseExtended::new();
// for easy sharing
let japanext_calendar = Ref(&japanext_calendar);
let era = "kansei-1789";
let date = Date::try_new_japanese_extended_with_calendar(
era,
7,
1,
2,
japanext_calendar,
)
.expect("Constructing a date should succeed");
assert_eq!(date.era_year().era, era);
assert_eq!(date.era_year().year, 7);
assert_eq!(date.month().ordinal, 1);
assert_eq!(date.day_of_month().0, 2);
Source§impl Date<Julian>
impl Date<Julian>
Sourcepub fn try_new_julian(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Julian>, RangeError>
pub fn try_new_julian( year: i32, month: u8, day: u8, ) -> Result<Date<Julian>, RangeError>
Construct new Julian Date.
Years are arithmetic, meaning there is a year 0. Zero and negative years are in BC, with year 0 = 1 BC
use icu::calendar::Date;
let date_julian = Date::try_new_julian(1969, 12, 20)
.expect("Failed to initialize Julian Date instance.");
assert_eq!(date_julian.era_year().year, 1969);
assert_eq!(date_julian.month().ordinal, 12);
assert_eq!(date_julian.day_of_month().0, 20);
Source§impl Date<Persian>
impl Date<Persian>
Sourcepub fn try_new_persian(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Persian>, RangeError>
pub fn try_new_persian( year: i32, month: u8, day: u8, ) -> Result<Date<Persian>, RangeError>
Construct new Persian Date.
Has no negative years, only era is the AH/AP.
use icu::calendar::Date;
let date_persian = Date::try_new_persian(1392, 4, 25)
.expect("Failed to initialize Persian Date instance.");
assert_eq!(date_persian.era_year().year, 1392);
assert_eq!(date_persian.month().ordinal, 4);
assert_eq!(date_persian.day_of_month().0, 25);
Source§impl Date<Roc>
impl Date<Roc>
Sourcepub fn try_new_roc(
year: i32,
month: u8,
day: u8,
) -> Result<Date<Roc>, RangeError>
pub fn try_new_roc( year: i32, month: u8, day: u8, ) -> Result<Date<Roc>, RangeError>
Construct a new Republic of China calendar Date.
Years are specified in the “roc” era. This function accepts an extended year in that era, so dates
before Minguo are negative and year 0 is 1 Before Minguo. To specify dates using explicit era
codes, use Date::try_new_from_codes()
.
use icu::calendar::Date;
use icu::calendar::cal::Gregorian;
use tinystr::tinystr;
// Create a new ROC Date
let date_roc = Date::try_new_roc(1, 2, 3)
.expect("Failed to initialize ROC Date instance.");
assert_eq!(date_roc.era_year().era, tinystr!(16, "roc"));
assert_eq!(date_roc.era_year().year, 1, "ROC year check failed!");
assert_eq!(date_roc.month().ordinal, 2, "ROC month check failed!");
assert_eq!(date_roc.day_of_month().0, 3, "ROC day of month check failed!");
// Convert to an equivalent Gregorian date
let date_gregorian = date_roc.to_calendar(Gregorian);
assert_eq!(date_gregorian.era_year().year, 1912, "Gregorian from ROC year check failed!");
assert_eq!(date_gregorian.month().ordinal, 2, "Gregorian from ROC month check failed!");
assert_eq!(date_gregorian.day_of_month().0, 3, "Gregorian from ROC day of month check failed!");
Source§impl<A> Date<A>where
A: AsCalendar,
impl<A> Date<A>where
A: AsCalendar,
Sourcepub fn try_from_str(
rfc_9557_str: &str,
calendar: A,
) -> Result<Date<A>, ParseError>
pub fn try_from_str( rfc_9557_str: &str, calendar: A, ) -> Result<Date<A>, ParseError>
Creates a Date
in the given calendar from an RFC 9557 string.
Returns an error if the string has a calendar annotation that does not
match the calendar argument, unless the argument is Iso
.
✨ Enabled with the ixdtf
Cargo feature.
§Examples
use icu::calendar::{Date, Gregorian};
let date = Date::try_from_str("2024-07-17", Gregorian).unwrap();
let date =
Date::try_from_str("2024-07-17[u-ca=gregory]", Gregorian).unwrap();
let _ =
Date::try_from_str("2024-07-17[u-ca=hebrew]", Gregorian).unwrap_err();
assert_eq!(date.era_year().year, 2024);
assert_eq!(
date.month().standard_code,
icu::calendar::types::MonthCode(tinystr::tinystr!(4, "M07"))
);
assert_eq!(date.day_of_month().0, 17);
Sourcepub fn try_from_utf8(
rfc_9557_str: &[u8],
calendar: A,
) -> Result<Date<A>, ParseError>
pub fn try_from_utf8( rfc_9557_str: &[u8], calendar: A, ) -> Result<Date<A>, ParseError>
Creates a Date
in the given calendar from an RFC 9557 string.
Returns an error if the string has a calendar annotation that does not match the calendar argument.
See Self::try_from_str()
.
✨ Enabled with the ixdtf
Cargo feature.
Trait Implementations§
Source§impl<C, A> ConvertCalendar for Date<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
impl<C, A> ConvertCalendar for Date<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
Source§type Converted<'a> = Date<Ref<'a, AnyCalendar>>
type Converted<'a> = Date<Ref<'a, AnyCalendar>>
Source§fn to_calendar<'a>(
&self,
calendar: &'a AnyCalendar,
) -> <Date<A> as ConvertCalendar>::Converted<'a>
fn to_calendar<'a>( &self, calendar: &'a AnyCalendar, ) -> <Date<A> as ConvertCalendar>::Converted<'a>
self
to the specified AnyCalendar
.Source§impl<A> Debug for Date<A>where
A: AsCalendar,
impl<A> Debug for Date<A>where
A: AsCalendar,
Source§impl<C, A> GetField<DayOfMonth> for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<DayOfMonth> for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
Source§fn get_field(&self) -> DayOfMonth
fn get_field(&self) -> DayOfMonth
T
.Source§impl<C, A> InSameCalendar for Date<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
impl<C, A> InSameCalendar for Date<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
Source§fn check_any_calendar_kind(
&self,
any_calendar_kind: AnyCalendarKind,
) -> Result<(), MismatchedCalendarError>
fn check_any_calendar_kind( &self, any_calendar_kind: AnyCalendarKind, ) -> Result<(), MismatchedCalendarError>
Source§impl<C, A> Ord for Date<A>
impl<C, A> Ord for Date<A>
Source§impl<C, A, B> PartialOrd<Date<B>> for Date<A>where
C: Calendar,
<C as Calendar>::DateInner: PartialOrd,
A: AsCalendar<Calendar = C>,
B: AsCalendar<Calendar = C>,
impl<C, A, B> PartialOrd<Date<B>> for Date<A>where
C: Calendar,
<C as Calendar>::DateInner: PartialOrd,
A: AsCalendar<Calendar = C>,
B: AsCalendar<Calendar = C>,
impl<A> Copy for Date<A>where
A: AsCalendar + Copy,
impl<A> Eq for Date<A>where
A: AsCalendar,
impl<C, A> InFixedCalendar<C> for Date<A>where
C: CldrCalendar,
A: AsCalendar<Calendar = C>,
impl<C, A> UnstableSealed for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
Auto Trait Implementations§
impl<A> Freeze for Date<A>
impl<A> RefUnwindSafe for Date<A>
impl<A> Send for Date<A>
impl<A> Sync for Date<A>
impl<A> Unpin for Date<A>
impl<A> UnwindSafe for Date<A>
Blanket Implementations§
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> GetField<T> for Twhere
T: Copy + UnstableSealed,
impl<T> GetField<T> for Twhere
T: Copy + UnstableSealed,
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