pub struct DateTime<A>where
A: AsCalendar,{
pub date: Date<A>,
pub time: Time,
}
Expand description
A date+time for a given calendar.
This can work with wrappers around Calendar
types,
e.g. Rc<C>
, via the AsCalendar
trait, much like
Date
.
This can be constructed manually from a Date
and Time
, or can be 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::DateTime;
// Example: Construction of ISO datetime from integers.
let datetime_iso = DateTime::try_new_iso(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize ISO DateTime instance.");
assert_eq!(datetime_iso.date.year().era_year_or_extended(), 1970);
assert_eq!(datetime_iso.date.month().ordinal, 1);
assert_eq!(datetime_iso.date.day_of_month().0, 2);
assert_eq!(datetime_iso.time.hour.number(), 13);
assert_eq!(datetime_iso.time.minute.number(), 1);
assert_eq!(datetime_iso.time.second.number(), 0);
Fields§
§date: Date<A>
The date
time: Time
The time
Implementations§
source§impl<A> DateTime<A>where
A: AsCalendar,
impl<A> DateTime<A>where
A: AsCalendar,
sourcepub fn try_new_from_codes(
era: Option<Era>,
year: i32,
month_code: MonthCode,
day: u8,
time: Time,
calendar: A,
) -> Result<DateTime<A>, DateError>
pub fn try_new_from_codes( era: Option<Era>, year: i32, month_code: MonthCode, day: u8, time: Time, calendar: A, ) -> Result<DateTime<A>, DateError>
Construct a datetime from from era/month codes and fields, and some calendar representation
sourcepub fn new_from_iso(iso: DateTime<Iso>, calendar: A) -> DateTime<A>
pub fn new_from_iso(iso: DateTime<Iso>, calendar: A) -> DateTime<A>
Construct a DateTime from an ISO datetime and some calendar representation
sourcepub fn to_calendar<A2>(&self, calendar: A2) -> DateTime<A2>where
A2: AsCalendar,
pub fn to_calendar<A2>(&self, calendar: A2) -> DateTime<A2>where
A2: AsCalendar,
Convert the DateTime to a DateTime in a different calendar
source§impl<C, A> DateTime<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
impl<C, A> DateTime<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
sourcepub fn to_any(&self) -> DateTime<AnyCalendar>
pub fn to_any(&self) -> DateTime<AnyCalendar>
Type-erase the date, converting it to a date for AnyCalendar
source§impl<C> DateTime<C>where
C: Calendar,
impl<C> DateTime<C>where
C: Calendar,
sourcepub fn wrap_calendar_in_rc(self) -> DateTime<Rc<C>>
pub fn wrap_calendar_in_rc(self) -> DateTime<Rc<C>>
Wrap the calendar type in Rc<T>
Useful when paired with Self::to_any()
to obtain a DateTime<Rc<AnyCalendar>>
sourcepub fn wrap_calendar_in_arc(self) -> DateTime<Arc<C>>
pub fn wrap_calendar_in_arc(self) -> DateTime<Arc<C>>
Wrap the calendar type in Arc<T>
Useful when paired with Self::to_any()
to obtain a DateTime<Rc<AnyCalendar>>
source§impl DateTime<Buddhist>
impl DateTime<Buddhist>
sourcepub fn try_new_buddhist(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Buddhist>, DateError>
pub fn try_new_buddhist( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Buddhist>, DateError>
Construct a new Buddhist datetime from integers.
Years are specified as BE years.
use icu::calendar::DateTime;
let datetime_buddhist =
DateTime::try_new_buddhist(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize Buddhist DateTime instance.");
assert_eq!(datetime_buddhist.date.year().era_year_or_extended(), 1970);
assert_eq!(datetime_buddhist.date.month().ordinal, 1);
assert_eq!(datetime_buddhist.date.day_of_month().0, 2);
assert_eq!(datetime_buddhist.time.hour.number(), 13);
assert_eq!(datetime_buddhist.time.minute.number(), 1);
assert_eq!(datetime_buddhist.time.second.number(), 0);
source§impl<A> DateTime<A>where
A: AsCalendar<Calendar = Chinese>,
impl<A> DateTime<A>where
A: AsCalendar<Calendar = Chinese>,
sourcepub fn try_new_chinese_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, DateError>
pub fn try_new_chinese_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, DateError>
Construct a new Chinese datetime from integers using the -2636-based year system
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::{cal::Chinese, DateTime};
let chinese = Chinese::new_always_calculating();
let chinese_datetime = DateTime::try_new_chinese_with_calendar(
4660, 6, 11, 13, 1, 0, chinese,
)
.expect("Failed to initialize Chinese DateTime instance.");
assert_eq!(chinese_datetime.date.year().era_year_or_extended(), 4660);
assert_eq!(chinese_datetime.date.year().cyclic().unwrap().get(), 40);
assert_eq!(chinese_datetime.date.month().ordinal, 6);
assert_eq!(chinese_datetime.date.day_of_month().0, 11);
assert_eq!(chinese_datetime.time.hour.number(), 13);
assert_eq!(chinese_datetime.time.minute.number(), 1);
assert_eq!(chinese_datetime.time.second.number(), 0);
source§impl DateTime<Coptic>
impl DateTime<Coptic>
sourcepub fn try_new_coptic(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Coptic>, DateError>
pub fn try_new_coptic( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Coptic>, DateError>
Construct a new Coptic datetime from integers.
Negative years are in the B.D. era, starting with 0 = 1 B.D.
use icu::calendar::DateTime;
let datetime_coptic =
DateTime::try_new_coptic(1686, 5, 6, 13, 1, 0)
.expect("Failed to initialize Coptic DateTime instance.");
assert_eq!(datetime_coptic.date.year().era_year_or_extended(), 1686);
assert_eq!(datetime_coptic.date.month().ordinal, 5);
assert_eq!(datetime_coptic.date.day_of_month().0, 6);
assert_eq!(datetime_coptic.time.hour.number(), 13);
assert_eq!(datetime_coptic.time.minute.number(), 1);
assert_eq!(datetime_coptic.time.second.number(), 0);
source§impl<A> DateTime<A>where
A: AsCalendar<Calendar = Dangi>,
impl<A> DateTime<A>where
A: AsCalendar<Calendar = Dangi>,
sourcepub fn try_new_dangi_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, DateError>
pub fn try_new_dangi_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, DateError>
Construct a new Dangi DateTime from integers. See try_new_dangi_with_calendar
.
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::cal::Dangi;
use icu::calendar::DateTime;
let dangi = Dangi::new();
let dangi_datetime = DateTime::try_new_dangi_with_calendar(
4356, 6, 6, 13, 1, 0, dangi,
)
.expect("Failed to initialize Dangi DateTime instance.");
assert_eq!(dangi_datetime.date.year().era_year_or_extended(), 4356);
assert_eq!(dangi_datetime.date.year().cyclic().unwrap().get(), 40);
assert_eq!(dangi_datetime.date.month().ordinal, 6);
assert_eq!(dangi_datetime.date.day_of_month().0, 6);
assert_eq!(dangi_datetime.time.hour.number(), 13);
assert_eq!(dangi_datetime.time.minute.number(), 1);
assert_eq!(dangi_datetime.time.second.number(), 0);
source§impl DateTime<Ethiopian>
impl DateTime<Ethiopian>
sourcepub fn try_new_ethiopian(
era_style: EthiopianEraStyle,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Ethiopian>, DateError>
pub fn try_new_ethiopian( era_style: EthiopianEraStyle, year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Ethiopian>, DateError>
Construct a new Ethiopian datetime from integers.
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::DateTime;
let datetime_ethiopian = DateTime::try_new_ethiopian(
EthiopianEraStyle::AmeteMihret,
2014,
8,
25,
13,
1,
0,
)
.expect("Failed to initialize Ethiopian DateTime instance.");
assert_eq!(datetime_ethiopian.date.year().era_year_or_extended(), 2014);
assert_eq!(datetime_ethiopian.date.month().ordinal, 8);
assert_eq!(datetime_ethiopian.date.day_of_month().0, 25);
assert_eq!(datetime_ethiopian.time.hour.number(), 13);
assert_eq!(datetime_ethiopian.time.minute.number(), 1);
assert_eq!(datetime_ethiopian.time.second.number(), 0);
source§impl DateTime<Gregorian>
impl DateTime<Gregorian>
sourcepub fn try_new_gregorian(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Gregorian>, DateError>
pub fn try_new_gregorian( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Gregorian>, DateError>
Construct a new Gregorian datetime from integers.
Years are specified as ISO years.
use icu::calendar::DateTime;
let datetime_gregorian =
DateTime::try_new_gregorian(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize Gregorian DateTime instance.");
assert_eq!(datetime_gregorian.date.year().era_year_or_extended(), 1970);
assert_eq!(datetime_gregorian.date.month().ordinal, 1);
assert_eq!(datetime_gregorian.date.day_of_month().0, 2);
assert_eq!(datetime_gregorian.time.hour.number(), 13);
assert_eq!(datetime_gregorian.time.minute.number(), 1);
assert_eq!(datetime_gregorian.time.second.number(), 0);
source§impl DateTime<Hebrew>
impl DateTime<Hebrew>
sourcepub fn try_new_hebrew(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Hebrew>, DateError>
pub fn try_new_hebrew( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Hebrew>, DateError>
Construct a new Hebrew datetime from integers.
use icu::calendar::DateTime;
let datetime_hebrew =
DateTime::try_new_hebrew(4201, 10, 11, 13, 1, 0)
.expect("Failed to initialize Hebrew DateTime instance");
assert_eq!(datetime_hebrew.date.year().era_year_or_extended(), 4201);
assert_eq!(datetime_hebrew.date.month().ordinal, 10);
assert_eq!(datetime_hebrew.date.day_of_month().0, 11);
assert_eq!(datetime_hebrew.time.hour.number(), 13);
assert_eq!(datetime_hebrew.time.minute.number(), 1);
assert_eq!(datetime_hebrew.time.second.number(), 0);
source§impl DateTime<Indian>
impl DateTime<Indian>
sourcepub fn try_new_indian(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Indian>, DateError>
pub fn try_new_indian( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Indian>, DateError>
Construct a new Indian datetime from integers, with year provided in the Śaka era.
use icu::calendar::DateTime;
let datetime_indian =
DateTime::try_new_indian(1891, 10, 12, 13, 1, 0)
.expect("Failed to initialize Indian DateTime instance.");
assert_eq!(datetime_indian.date.year().era_year_or_extended(), 1891);
assert_eq!(datetime_indian.date.month().ordinal, 10);
assert_eq!(datetime_indian.date.day_of_month().0, 12);
assert_eq!(datetime_indian.time.hour.number(), 13);
assert_eq!(datetime_indian.time.minute.number(), 1);
assert_eq!(datetime_indian.time.second.number(), 0);
source§impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicObservational>,
impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicObservational>,
sourcepub fn try_new_observational_islamic_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, DateError>
pub fn try_new_observational_islamic_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, DateError>
Construct a new Islamic Observational datetime from integers.
use icu::calendar::cal::IslamicObservational;
use icu::calendar::DateTime;
let islamic = IslamicObservational::new_always_calculating();
let datetime_islamic = DateTime::try_new_observational_islamic_with_calendar(
474, 10, 11, 13, 1, 0, islamic,
)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().era_year_or_extended(), 474);
assert_eq!(datetime_islamic.date.month().ordinal, 10);
assert_eq!(datetime_islamic.date.day_of_month().0, 11);
assert_eq!(datetime_islamic.time.hour.number(), 13);
assert_eq!(datetime_islamic.time.minute.number(), 1);
assert_eq!(datetime_islamic.time.second.number(), 0);
source§impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicUmmAlQura>,
impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicUmmAlQura>,
sourcepub fn try_new_ummalqura_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, DateError>
pub fn try_new_ummalqura_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, DateError>
Construct a new Islamic Umm al-Qura datetime from integers.
use icu::calendar::cal::IslamicUmmAlQura;
use icu::calendar::DateTime;
let islamic = IslamicUmmAlQura::new_always_calculating();
let datetime_islamic =
DateTime::try_new_ummalqura_with_calendar(474, 10, 11, 13, 1, 0, islamic)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().era_year_or_extended(), 474);
assert_eq!(datetime_islamic.date.month().ordinal, 10);
assert_eq!(datetime_islamic.date.day_of_month().0, 11);
assert_eq!(datetime_islamic.time.hour.number(), 13);
assert_eq!(datetime_islamic.time.minute.number(), 1);
assert_eq!(datetime_islamic.time.second.number(), 0);
source§impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicCivil>,
impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicCivil>,
sourcepub fn try_new_islamic_civil_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, DateError>
pub fn try_new_islamic_civil_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, DateError>
Construct a new Civil Islamic datetime from integers.
use icu::calendar::cal::IslamicCivil;
use icu::calendar::DateTime;
let islamic = IslamicCivil::new();
let datetime_islamic =
DateTime::try_new_islamic_civil_with_calendar(
474, 10, 11, 13, 1, 0, islamic,
)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().era_year_or_extended(), 474);
assert_eq!(datetime_islamic.date.month().ordinal, 10);
assert_eq!(datetime_islamic.date.day_of_month().0, 11);
assert_eq!(datetime_islamic.time.hour.number(), 13);
assert_eq!(datetime_islamic.time.minute.number(), 1);
assert_eq!(datetime_islamic.time.second.number(), 0);
source§impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicTabular>,
impl<A> DateTime<A>where
A: AsCalendar<Calendar = IslamicTabular>,
sourcepub fn try_new_islamic_tabular_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, DateError>
pub fn try_new_islamic_tabular_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, DateError>
Construct a new Tabular Islamic datetime from integers.
use icu::calendar::cal::IslamicTabular;
use icu::calendar::DateTime;
let islamic = IslamicTabular::new();
let datetime_islamic =
DateTime::try_new_islamic_tabular_with_calendar(
474, 10, 11, 13, 1, 0, islamic,
)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().era_year_or_extended(), 474);
assert_eq!(datetime_islamic.date.month().ordinal, 10);
assert_eq!(datetime_islamic.date.day_of_month().0, 11);
assert_eq!(datetime_islamic.time.hour.number(), 13);
assert_eq!(datetime_islamic.time.minute.number(), 1);
assert_eq!(datetime_islamic.time.second.number(), 0);
source§impl DateTime<Iso>
impl DateTime<Iso>
sourcepub fn try_new_iso(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Iso>, DateError>
pub fn try_new_iso( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Iso>, DateError>
Construct a new ISO datetime from integers.
use icu::calendar::DateTime;
let datetime_iso = DateTime::try_new_iso(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize ISO DateTime instance.");
assert_eq!(datetime_iso.date.year().era_year_or_extended(), 1970);
assert_eq!(datetime_iso.date.month().ordinal, 1);
assert_eq!(datetime_iso.date.day_of_month().0, 2);
assert_eq!(datetime_iso.time.hour.number(), 13);
assert_eq!(datetime_iso.time.minute.number(), 1);
assert_eq!(datetime_iso.time.second.number(), 0);
source§impl DateTime<Iso>
impl DateTime<Iso>
sourcepub fn try_iso_from_str(ixdtf_str: &str) -> Result<DateTime<Iso>, ParseError>
pub fn try_iso_from_str(ixdtf_str: &str) -> Result<DateTime<Iso>, ParseError>
Creates a DateTime
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::DateTime;
let datetime = DateTime::try_iso_from_str("2024-07-17T16:01:17.045").unwrap();
assert_eq!(datetime.date.year().era_year_or_extended(), 2024);
assert_eq!(
datetime.date.month().standard_code,
icu::calendar::types::MonthCode(tinystr::tinystr!(4, "M07"))
);
assert_eq!(datetime.date.day_of_month().0, 17);
assert_eq!(datetime.time.hour.number(), 16);
assert_eq!(datetime.time.minute.number(), 1);
assert_eq!(datetime.time.second.number(), 17);
assert_eq!(datetime.time.nanosecond.number(), 45000000);
sourcepub fn try_iso_from_utf8(ixdtf_str: &[u8]) -> Result<DateTime<Iso>, ParseError>
pub fn try_iso_from_utf8(ixdtf_str: &[u8]) -> Result<DateTime<Iso>, ParseError>
Creates a DateTime
in the ISO-8601 calendar from an IXDTF syntax string.
✨ Enabled with the ixdtf
Cargo feature.
source§impl DateTime<AnyCalendar>
impl DateTime<AnyCalendar>
sourcepub fn try_from_str(
ixdtf_str: &str,
) -> Result<DateTime<AnyCalendar>, ParseError>
pub fn try_from_str( ixdtf_str: &str, ) -> Result<DateTime<AnyCalendar>, ParseError>
Creates a DateTime
in any calendar from an IXDTF syntax string with compiled data.
✨ Enabled with the compiled_data
and ixdtf
Cargo features.
§Examples
use icu::calendar::DateTime;
let datetime = DateTime::try_from_str("2024-07-17T16:01:17.045[u-ca=hebrew]").unwrap();
assert_eq!(datetime.date.year().era_year_or_extended(), 5784);
assert_eq!(
datetime.date.month().standard_code,
icu::calendar::types::MonthCode(tinystr::tinystr!(4, "M10"))
);
assert_eq!(datetime.date.day_of_month().0, 11);
assert_eq!(datetime.time.hour.number(), 16);
assert_eq!(datetime.time.minute.number(), 1);
assert_eq!(datetime.time.second.number(), 17);
assert_eq!(datetime.time.nanosecond.number(), 45000000);
sourcepub fn try_from_utf8(
ixdtf_str: &[u8],
) -> Result<DateTime<AnyCalendar>, ParseError>
pub fn try_from_utf8( ixdtf_str: &[u8], ) -> Result<DateTime<AnyCalendar>, ParseError>
Creates a DateTime
in any calendar from an IXDTF syntax string with compiled data.
See Self::try_from_str()
.
✨ Enabled with the compiled_data
and ixdtf
Cargo features.
source§impl DateTime<Japanese>
impl DateTime<Japanese>
sourcepub fn try_new_japanese_with_calendar<A>(
era: Era,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
japanese_calendar: A,
) -> Result<DateTime<A>, DateError>where
A: AsCalendar<Calendar = Japanese>,
pub fn try_new_japanese_with_calendar<A>(
era: Era,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
japanese_calendar: A,
) -> Result<DateTime<A>, DateError>where
A: AsCalendar<Calendar = Japanese>,
Construct a new Japanese datetime from integers.
Years are specified in the era provided.
use icu::calendar::cal::Japanese;
use icu::calendar::{types, DateTime};
use tinystr::tinystr;
let japanese_calendar = Japanese::new();
let era = types::Era(tinystr!(16, "heisei"));
let datetime = DateTime::try_new_japanese_with_calendar(
era,
14,
1,
2,
13,
1,
0,
japanese_calendar,
)
.expect("Constructing a date should succeed");
assert_eq!(datetime.date.year().standard_era().unwrap(), era);
assert_eq!(datetime.date.year().era_year_or_extended(), 14);
assert_eq!(datetime.date.month().ordinal, 1);
assert_eq!(datetime.date.day_of_month().0, 2);
assert_eq!(datetime.time.hour.number(), 13);
assert_eq!(datetime.time.minute.number(), 1);
assert_eq!(datetime.time.second.number(), 0);
source§impl DateTime<JapaneseExtended>
impl DateTime<JapaneseExtended>
sourcepub fn try_new_japanese_extended_with_calendar<A>(
era: Era,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
japanext_calendar: A,
) -> Result<DateTime<A>, DateError>where
A: AsCalendar<Calendar = JapaneseExtended>,
pub fn try_new_japanese_extended_with_calendar<A>(
era: Era,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
japanext_calendar: A,
) -> Result<DateTime<A>, DateError>where
A: AsCalendar<Calendar = JapaneseExtended>,
Construct a new Japanese datetime from integers with all eras.
Years are specified in the era provided.
use icu::calendar::cal::JapaneseExtended;
use icu::calendar::{types, DateTime};
use tinystr::tinystr;
let japanext_calendar = JapaneseExtended::new();
let era = types::Era(tinystr!(16, "kansei-1789"));
let datetime = DateTime::try_new_japanese_extended_with_calendar(
era,
7,
1,
2,
13,
1,
0,
japanext_calendar,
)
.expect("Constructing a date should succeed");
assert_eq!(datetime.date.year().standard_era().unwrap(), era);
assert_eq!(datetime.date.year().era_year_or_extended(), 7);
assert_eq!(datetime.date.month().ordinal, 1);
assert_eq!(datetime.date.day_of_month().0, 2);
assert_eq!(datetime.time.hour.number(), 13);
assert_eq!(datetime.time.minute.number(), 1);
assert_eq!(datetime.time.second.number(), 0);
source§impl DateTime<Julian>
impl DateTime<Julian>
sourcepub fn try_new_julian(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Julian>, DateError>
pub fn try_new_julian( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Julian>, DateError>
Construct a new Julian datetime from integers.
Years are arithmetic, meaning there is a year 0. Zero and negative years are in BC, with year 0 = 1 BC
use icu::calendar::DateTime;
let datetime_julian =
DateTime::try_new_julian(1969, 12, 20, 13, 1, 0)
.expect("Failed to initialize Julian DateTime instance.");
assert_eq!(datetime_julian.date.year().era_year_or_extended(), 1969);
assert_eq!(datetime_julian.date.month().ordinal, 12);
assert_eq!(datetime_julian.date.day_of_month().0, 20);
assert_eq!(datetime_julian.time.hour.number(), 13);
assert_eq!(datetime_julian.time.minute.number(), 1);
assert_eq!(datetime_julian.time.second.number(), 0);
source§impl DateTime<Persian>
impl DateTime<Persian>
sourcepub fn try_new_persian(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Persian>, DateError>
pub fn try_new_persian( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Persian>, DateError>
Construct a new Persian datetime from integers.
use icu::calendar::DateTime;
let datetime_persian =
DateTime::try_new_persian(474, 10, 11, 13, 1, 0)
.expect("Failed to initialize Persian DateTime instance.");
assert_eq!(datetime_persian.date.year().era_year_or_extended(), 474);
assert_eq!(datetime_persian.date.month().ordinal, 10);
assert_eq!(datetime_persian.date.day_of_month().0, 11);
assert_eq!(datetime_persian.time.hour.number(), 13);
assert_eq!(datetime_persian.time.minute.number(), 1);
assert_eq!(datetime_persian.time.second.number(), 0);
source§impl DateTime<Roc>
impl DateTime<Roc>
sourcepub fn try_new_roc(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Roc>, DateError>
pub fn try_new_roc( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Roc>, DateError>
Construct a new Republic of China calendar datetime from integers.
Years are specified in the “roc” era, Before Minguo dates are negative (year 0 is 1 Before Minguo)
use icu::calendar::DateTime;
use tinystr::tinystr;
// Create a new ROC DateTime
let datetime_roc = DateTime::try_new_roc(1, 2, 3, 13, 1, 0)
.expect("Failed to initialize ROC DateTime instance.");
assert_eq!(datetime_roc.date.year().standard_era().unwrap().0, tinystr!(16, "roc"));
assert_eq!(datetime_roc.date.year().era_year_or_extended(), 1, "ROC year check failed!");
assert_eq!(
datetime_roc.date.month().ordinal,
2,
"ROC month check failed!"
);
assert_eq!(
datetime_roc.date.day_of_month().0,
3,
"ROC day of month check failed!"
);
assert_eq!(datetime_roc.time.hour.number(), 13);
assert_eq!(datetime_roc.time.minute.number(), 1);
assert_eq!(datetime_roc.time.second.number(), 0);
Trait Implementations§
source§impl<C, A> ConvertCalendar for DateTime<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
impl<C, A> ConvertCalendar for DateTime<A>where
C: IntoAnyCalendar,
A: AsCalendar<Calendar = C>,
source§type Converted<'a> = DateTime<Ref<'a, AnyCalendar>>
type Converted<'a> = DateTime<Ref<'a, AnyCalendar>>
source§fn to_calendar<'a>(
&self,
calendar: &'a AnyCalendar,
) -> <DateTime<A> as ConvertCalendar>::Converted<'a>
fn to_calendar<'a>( &self, calendar: &'a AnyCalendar, ) -> <DateTime<A> as ConvertCalendar>::Converted<'a>
self
to the specified AnyCalendar
.source§impl FromStr for DateTime<AnyCalendar>
impl FromStr for DateTime<AnyCalendar>
source§impl<C, A> GetField<DayOfMonth> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<DayOfMonth> for DateTime<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 DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<DayOfYearInfo> for DateTime<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<IsoMinute> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<IsoMinute> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
source§impl<C, A> GetField<IsoSecond> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<IsoSecond> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
source§impl<C, A> GetField<IsoWeekday> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<IsoWeekday> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
source§fn get_field(&self) -> IsoWeekday
fn get_field(&self) -> IsoWeekday
T
.source§impl<C, A> GetField<MonthInfo> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<MonthInfo> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
source§impl<C, A> GetField<NanoSecond> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> GetField<NanoSecond> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
source§fn get_field(&self) -> NanoSecond
fn get_field(&self) -> NanoSecond
T
.source§impl<C, A> IsAnyCalendarKind for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
impl<C, A> IsAnyCalendarKind for DateTime<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 DateTime<A>
impl<C, A> Ord for DateTime<A>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<C, A, B> PartialOrd<DateTime<B>> for DateTime<A>where
C: Calendar,
<C as Calendar>::DateInner: PartialOrd,
A: AsCalendar<Calendar = C>,
B: AsCalendar<Calendar = C>,
impl<C, A, B> PartialOrd<DateTime<B>> for DateTime<A>where
C: Calendar,
<C as Calendar>::DateInner: PartialOrd,
A: AsCalendar<Calendar = C>,
B: AsCalendar<Calendar = C>,
impl<A> Copy for DateTime<A>
impl<A> Eq for DateTime<A>where
A: AsCalendar,
impl<C, A> IsInCalendar<C> for DateTime<A>where
C: Calendar,
A: AsCalendar<Calendar = C>,
Auto Trait Implementations§
impl<A> Freeze for DateTime<A>
impl<A> RefUnwindSafe for DateTime<A>
impl<A> Send for DateTime<A>
impl<A> Sync for DateTime<A>
impl<A> Unpin for DateTime<A>
impl<A> UnwindSafe for DateTime<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