pub struct Date<A>where
A: AsCalendar,{ /* private fields */ }
Expand description
A date for a given calendar.
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>_datetime()
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.year().era_year_or_extended(), 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<Era>,
year: i32,
month_code: MonthCode,
day: u8,
calendar: A,
) -> Result<Date<A>, DateError>
pub fn try_new_from_codes( era: Option<Era>, 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 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) -> IsoWeekday
pub fn day_of_week(&self) -> IsoWeekday
The day of the week for this date
Monday is 1, Sunday is 7, according to ISO
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_info(&self) -> DayOfYearInfo
pub fn day_of_year_info(&self) -> DayOfYearInfo
The calendar-specific day-of-month represented by self
sourcepub fn week_of_month(&self, first_weekday: IsoWeekday) -> WeekOfMonth
pub fn week_of_month(&self, first_weekday: IsoWeekday) -> WeekOfMonth
The week of the month containing this date.
§Examples
use icu::calendar::types::IsoWeekday;
use icu::calendar::types::WeekOfMonth;
use icu::calendar::Date;
let date = Date::try_new_iso(2022, 8, 10).unwrap(); // second Wednesday
// The following info is usually locale-specific
let first_weekday = IsoWeekday::Sunday;
assert_eq!(date.week_of_month(first_weekday), WeekOfMonth(2));
sourcepub fn week_of_year(&self, config: &WeekCalculator) -> WeekOf
pub fn week_of_year(&self, config: &WeekCalculator) -> WeekOf
The week of the year containing this date.
§Examples
use icu::calendar::week::RelativeUnit;
use icu::calendar::week::WeekCalculator;
use icu::calendar::week::WeekOf;
use icu::calendar::Date;
let date = Date::try_new_iso(2022, 8, 26).unwrap();
// The following info is usually locale-specific
let week_calculator = WeekCalculator::default();
assert_eq!(
date.week_of_year(&week_calculator),
WeekOf {
week: 35,
unit: RelativeUnit::Current
}
);
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<C, A> Date<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
impl<C, A> Date<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
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<C> Date<C>where
C: Calendar,
impl<C> Date<C>where
C: Calendar,
sourcepub fn wrap_calendar_in_rc(self) -> Date<Rc<C>>
pub fn wrap_calendar_in_rc(self) -> Date<Rc<C>>
Wrap the calendar type in Rc<T>
Useful when paired with Self::to_any()
to obtain a Date<Rc<AnyCalendar>>
sourcepub fn wrap_calendar_in_arc(self) -> Date<Arc<C>>
pub fn wrap_calendar_in_arc(self) -> Date<Arc<C>>
Wrap the calendar type in Arc<T>
Useful when paired with Self::to_any()
to obtain a Date<Rc<AnyCalendar>>
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.year().era_year_or_extended(), 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(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, DateError>
pub fn try_new_chinese_with_calendar( 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 Chinese year counted infinitely with -2636 (2637 BCE) as Chinese year 1;
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(4660, 6, 11, chinese)
.expect("Failed to initialize Chinese Date instance.");
assert_eq!(date_chinese.year().era_year_or_extended(), 4660);
assert_eq!(date_chinese.year().cyclic().unwrap().get(), 40);
assert_eq!(date_chinese.year().related_iso(), Some(2023));
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.
Negative years are in the B.D. era, starting with 0 = 1 B.D.
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.year().era_year_or_extended(), 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(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, DateError>
pub fn try_new_dangi_with_calendar( 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 Chinese year counted infinitely with -2332 (2333 BCE) as year 1;
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(4356, 6, 18, dangi)
.expect("Failed to initialize Dangi Date instance.");
assert_eq!(date_dangi.year().era_year_or_extended(), 4356);
assert_eq!(date_dangi.year().cyclic().unwrap().get(), 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.
For the Amete Mihret era style, negative years work with year 0 as 1 pre-Incarnation, year -1 as 2 pre-Incarnation, and so on.
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.year().era_year_or_extended(), 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.year().era_year_or_extended(), 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 datetime 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.year().era_year_or_extended(), 3425);
assert_eq!(date_hebrew.month().ordinal, 4);
assert_eq!(date_hebrew.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.year().era_year_or_extended(), 1891);
assert_eq!(date_indian.month().ordinal, 10);
assert_eq!(date_indian.day_of_month().0, 12);
source§impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicObservational>,
impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicObservational>,
sourcepub fn try_new_observational_islamic_with_calendar(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, RangeError>
pub fn try_new_observational_islamic_with_calendar( year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, RangeError>
Construct new Islamic Observational Date.
Has no negative years, only era is the AH.
use icu::calendar::cal::IslamicObservational;
use icu::calendar::Date;
let islamic = IslamicObservational::new_always_calculating();
let date_islamic =
Date::try_new_observational_islamic_with_calendar(1392, 4, 25, islamic)
.expect("Failed to initialize Islamic Date instance.");
assert_eq!(date_islamic.year().era_year_or_extended(), 1392);
assert_eq!(date_islamic.month().ordinal, 4);
assert_eq!(date_islamic.day_of_month().0, 25);
source§impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicUmmAlQura>,
impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicUmmAlQura>,
sourcepub fn try_new_ummalqura_with_calendar(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, RangeError>
pub fn try_new_ummalqura_with_calendar( year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, RangeError>
Construct new Islamic Umm al-Qura Date.
Has no negative years, only era is the AH.
use icu::calendar::cal::IslamicUmmAlQura;
use icu::calendar::Date;
let islamic = IslamicUmmAlQura::new_always_calculating();
let date_islamic = Date::try_new_ummalqura_with_calendar(1392, 4, 25, islamic)
.expect("Failed to initialize Islamic Date instance.");
assert_eq!(date_islamic.year().era_year_or_extended(), 1392);
assert_eq!(date_islamic.month().ordinal, 4);
assert_eq!(date_islamic.day_of_month().0, 25);
source§impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicCivil>,
impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicCivil>,
sourcepub fn try_new_islamic_civil_with_calendar(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, RangeError>
pub fn try_new_islamic_civil_with_calendar( year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, RangeError>
Construct new Civil Islamic Date.
Has no negative years, only era is the AH.
use icu::calendar::cal::IslamicCivil;
use icu::calendar::Date;
let islamic = IslamicCivil::new();
let date_islamic =
Date::try_new_islamic_civil_with_calendar(1392, 4, 25, islamic)
.expect("Failed to initialize Islamic Date instance.");
assert_eq!(date_islamic.year().era_year_or_extended(), 1392);
assert_eq!(date_islamic.month().ordinal, 4);
assert_eq!(date_islamic.day_of_month().0, 25);
source§impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicTabular>,
impl<A> Date<A>where
A: AsCalendar<Calendar = IslamicTabular>,
sourcepub fn try_new_islamic_tabular_with_calendar(
year: i32,
month: u8,
day: u8,
calendar: A,
) -> Result<Date<A>, RangeError>
pub fn try_new_islamic_tabular_with_calendar( year: i32, month: u8, day: u8, calendar: A, ) -> Result<Date<A>, RangeError>
Construct new Tabular Islamic Date.
Has no negative years, only era is the AH.
use icu::calendar::cal::IslamicTabular;
use icu::calendar::Date;
let islamic = IslamicTabular::new();
let date_islamic =
Date::try_new_islamic_tabular_with_calendar(1392, 4, 25, islamic)
.expect("Failed to initialize Islamic Date instance.");
assert_eq!(date_islamic.year().era_year_or_extended(), 1392);
assert_eq!(date_islamic.month().ordinal, 4);
assert_eq!(date_islamic.day_of_month().0, 25);
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.year().era_year_or_extended(), 1970);
assert_eq!(date_iso.month().ordinal, 1);
assert_eq!(date_iso.day_of_month().0, 2);
source§impl Date<Iso>
impl Date<Iso>
sourcepub fn try_iso_from_str(ixdtf_str: &str) -> Result<Date<Iso>, ParseError>
pub fn try_iso_from_str(ixdtf_str: &str) -> Result<Date<Iso>, ParseError>
Creates a Date
in the ISO-8601 calendar from an IXDTF syntax string.
Ignores any calendar annotations in the string.
✨ Enabled with the ixdtf
Cargo feature.
§Examples
use icu::calendar::Date;
let date = Date::try_iso_from_str("2024-07-17").unwrap();
assert_eq!(date.year().era_year_or_extended(), 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_iso_from_utf8(ixdtf_str: &[u8]) -> Result<Date<Iso>, ParseError>
pub fn try_iso_from_utf8(ixdtf_str: &[u8]) -> Result<Date<Iso>, ParseError>
Creates a Date
in the ISO-8601 calendar from an IXDTF syntax string.
✨ Enabled with the ixdtf
Cargo feature.
source§impl Date<AnyCalendar>
impl Date<AnyCalendar>
sourcepub fn try_from_str(ixdtf_str: &str) -> Result<Date<AnyCalendar>, ParseError>
pub fn try_from_str(ixdtf_str: &str) -> Result<Date<AnyCalendar>, ParseError>
Creates a Date
in any calendar from an IXDTF syntax string with compiled data.
✨ Enabled with the compiled_data
and ixdtf
Cargo features.
§Examples
use icu::calendar::Date;
let date = Date::try_from_str("2024-07-17[u-ca=hebrew]").unwrap();
assert_eq!(date.year().era_year_or_extended(), 5784);
assert_eq!(
date.month().standard_code,
icu::calendar::types::MonthCode(tinystr::tinystr!(4, "M10"))
);
assert_eq!(date.day_of_month().0, 11);
sourcepub fn try_from_utf8(ixdtf_str: &[u8]) -> Result<Date<AnyCalendar>, ParseError>
pub fn try_from_utf8(ixdtf_str: &[u8]) -> Result<Date<AnyCalendar>, ParseError>
Creates a Date
in any calendar from an IXDTF syntax string with compiled data.
✨ Enabled with the compiled_data
and ixdtf
Cargo features.
See Self::try_from_str()
.
source§impl Date<Japanese>
impl Date<Japanese>
sourcepub fn try_new_japanese_with_calendar<A>(
era: Era,
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: Era,
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::{types, Date, Ref};
use tinystr::tinystr;
let japanese_calendar = Japanese::new();
// for easy sharing
let japanese_calendar = Ref(&japanese_calendar);
let era = types::Era(tinystr!(16, "heisei"));
let date = Date::try_new_japanese_with_calendar(era, 14, 1, 2, japanese_calendar)
.expect("Constructing a date should succeed");
assert_eq!(date.year().standard_era().unwrap(), era);
assert_eq!(date.year().era_year_or_extended(), 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 = types::Era(tinystr!(16, "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: Era,
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: Era,
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::{types, Date, Ref};
use tinystr::tinystr;
let japanext_calendar = JapaneseExtended::new();
// for easy sharing
let japanext_calendar = Ref(&japanext_calendar);
let era = types::Era(tinystr!(16, "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.year().standard_era().unwrap(), era);
assert_eq!(date.year().era_year_or_extended(), 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.year().era_year_or_extended(), 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.year().era_year_or_extended(), 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 Roc::date_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.year().standard_era().unwrap().0, tinystr!(16, "roc"));
assert_eq!(date_roc.year().era_year_or_extended(), 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.year().era_year_or_extended(), 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!");
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 FromStr for Date<AnyCalendar>
impl FromStr for Date<AnyCalendar>
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> GetField<DayOfYearInfo> for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<DayOfYearInfo> for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
source§fn get_field(&self) -> DayOfYearInfo
fn get_field(&self) -> DayOfYearInfo
T
.source§impl<C, A> GetField<IsoWeekday> for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<IsoWeekday> for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
source§fn get_field(&self) -> IsoWeekday
fn get_field(&self) -> IsoWeekday
T
.source§impl<C, A> IsAnyCalendarKind for Date<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> IsAnyCalendarKind for Date<A>where
C: Calendar,
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>
impl<A> Eq for Date<A>where
A: AsCalendar,
impl<C, A> IsInCalendar<C> 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§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