Struct icu_calendar::DateTime
source · pub struct DateTime<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_datetime(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize ISO DateTime instance.");
assert_eq!(datetime_iso.date.year().number, 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: AsCalendar> DateTime<A>
impl<A: AsCalendar> DateTime<A>
sourcepub fn try_new_from_codes(
era: Era,
year: i32,
month_code: MonthCode,
day: u8,
time: Time,
calendar: A,
) -> Result<Self, CalendarError>
pub fn try_new_from_codes( era: Era, year: i32, month_code: MonthCode, day: u8, time: Time, calendar: A, ) -> Result<Self, CalendarError>
Construct a datetime from from era/month codes and fields, and some calendar representation
sourcepub fn new_from_iso(iso: DateTime<Iso>, calendar: A) -> Self
pub fn new_from_iso(iso: DateTime<Iso>, calendar: A) -> Self
Construct a DateTime from an ISO datetime and some calendar representation
sourcepub fn to_calendar<A2: AsCalendar>(&self, calendar: A2) -> DateTime<A2>
pub fn to_calendar<A2: AsCalendar>(&self, calendar: A2) -> DateTime<A2>
Convert the DateTime to a DateTime in a different calendar
source§impl<C: IntoAnyCalendar, A: AsCalendar<Calendar = C>> DateTime<A>
impl<C: IntoAnyCalendar, A: AsCalendar<Calendar = C>> DateTime<A>
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: Calendar> DateTime<C>
impl<C: Calendar> DateTime<C>
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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Buddhist>, CalendarError>
pub fn try_new_buddhist_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Buddhist>, CalendarError>
Construct a new Buddhist datetime from integers.
Years are specified as BE years.
use icu::calendar::DateTime;
let datetime_buddhist =
DateTime::try_new_buddhist_datetime(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize Buddhist DateTime instance.");
assert_eq!(datetime_buddhist.date.year().number, 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: AsCalendar<Calendar = Chinese>> DateTime<A>
impl<A: AsCalendar<Calendar = Chinese>> DateTime<A>
sourcepub fn try_new_chinese_datetime_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_chinese_datetime_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, CalendarError>
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::{chinese::Chinese, DateTime};
let chinese = Chinese::new_always_calculating();
let chinese_datetime = DateTime::try_new_chinese_datetime_with_calendar(
4660, 6, 11, 13, 1, 0, chinese,
)
.expect("Failed to initialize Chinese DateTime instance.");
assert_eq!(chinese_datetime.date.year().number, 4660);
assert_eq!(chinese_datetime.date.year().related_iso, Some(2023));
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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Coptic>, CalendarError>
pub fn try_new_coptic_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Coptic>, CalendarError>
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_datetime(1686, 5, 6, 13, 1, 0)
.expect("Failed to initialize Coptic DateTime instance.");
assert_eq!(datetime_coptic.date.year().number, 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: AsCalendar<Calendar = Dangi>> DateTime<A>
impl<A: AsCalendar<Calendar = Dangi>> DateTime<A>
sourcepub fn try_new_dangi_datetime_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_dangi_datetime_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct a new Dangi DateTime from integers. See try_new_dangi_date_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::dangi::Dangi;
use icu::calendar::DateTime;
let dangi = Dangi::new();
let dangi_datetime = DateTime::try_new_dangi_datetime_with_calendar(
4356, 6, 6, 13, 1, 0, dangi,
)
.expect("Failed to initialize Dangi DateTime instance.");
assert_eq!(dangi_datetime.date.year().number, 4356);
assert_eq!(dangi_datetime.date.year().related_iso, Some(2023));
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_datetime(
era_style: EthiopianEraStyle,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Ethiopian>, CalendarError>
pub fn try_new_ethiopian_datetime( era_style: EthiopianEraStyle, year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Ethiopian>, CalendarError>
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::ethiopian::EthiopianEraStyle;
use icu::calendar::DateTime;
let datetime_ethiopian = DateTime::try_new_ethiopian_datetime(
EthiopianEraStyle::AmeteMihret,
2014,
8,
25,
13,
1,
0,
)
.expect("Failed to initialize Ethiopian DateTime instance.");
assert_eq!(datetime_ethiopian.date.year().number, 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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Gregorian>, CalendarError>
pub fn try_new_gregorian_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Gregorian>, CalendarError>
Construct a new Gregorian datetime from integers.
Years are specified as ISO years.
use icu::calendar::DateTime;
let datetime_gregorian =
DateTime::try_new_gregorian_datetime(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize Gregorian DateTime instance.");
assert_eq!(datetime_gregorian.date.year().number, 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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Hebrew>, CalendarError>
pub fn try_new_hebrew_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Hebrew>, CalendarError>
Construct a new Hebrew datetime from integers.
use icu::calendar::DateTime;
let datetime_hebrew =
DateTime::try_new_hebrew_datetime(4201, 10, 11, 13, 1, 0)
.expect("Failed to initialize Hebrew DateTime instance");
assert_eq!(datetime_hebrew.date.year().number, 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<A: AsCalendar<Calendar = Hebrew>> DateTime<A>
impl<A: AsCalendar<Calendar = Hebrew>> DateTime<A>
sourcepub fn try_new_hebrew_datetime_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, CalendarError>
👎Deprecated since 1.5.0: Use DateTime::try_new_hebrew_datetime()
pub fn try_new_hebrew_datetime_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct new Hebrew DateTime given a calendar.
This is deprecated since Hebrew
is a zero-sized type,
but if you find yourself needing this functionality please let us know.
source§impl DateTime<Indian>
impl DateTime<Indian>
sourcepub fn try_new_indian_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Indian>, CalendarError>
pub fn try_new_indian_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Indian>, CalendarError>
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_datetime(1891, 10, 12, 13, 1, 0)
.expect("Failed to initialize Indian DateTime instance.");
assert_eq!(datetime_indian.date.year().number, 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: AsCalendar<Calendar = IslamicObservational>> DateTime<A>
impl<A: AsCalendar<Calendar = IslamicObservational>> DateTime<A>
sourcepub fn try_new_observational_islamic_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_observational_islamic_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct a new Islamic Observational datetime from integers.
use icu::calendar::islamic::IslamicObservational;
use icu::calendar::DateTime;
let islamic = IslamicObservational::new_always_calculating();
let datetime_islamic = DateTime::try_new_observational_islamic_datetime(
474, 10, 11, 13, 1, 0, islamic,
)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().number, 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: AsCalendar<Calendar = IslamicUmmAlQura>> DateTime<A>
impl<A: AsCalendar<Calendar = IslamicUmmAlQura>> DateTime<A>
sourcepub fn try_new_ummalqura_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_ummalqura_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct a new Islamic Umm al-Qura datetime from integers.
use icu::calendar::islamic::IslamicUmmAlQura;
use icu::calendar::DateTime;
let islamic = IslamicUmmAlQura::new_always_calculating();
let datetime_islamic =
DateTime::try_new_ummalqura_datetime(474, 10, 11, 13, 1, 0, islamic)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().number, 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: AsCalendar<Calendar = IslamicCivil>> DateTime<A>
impl<A: AsCalendar<Calendar = IslamicCivil>> DateTime<A>
sourcepub fn try_new_islamic_civil_datetime_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_islamic_civil_datetime_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct a new Civil Islamic datetime from integers.
use icu::calendar::islamic::IslamicCivil;
use icu::calendar::DateTime;
let islamic = IslamicCivil::new_always_calculating();
let datetime_islamic =
DateTime::try_new_islamic_civil_datetime_with_calendar(
474, 10, 11, 13, 1, 0, islamic,
)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().number, 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: AsCalendar<Calendar = IslamicTabular>> DateTime<A>
impl<A: AsCalendar<Calendar = IslamicTabular>> DateTime<A>
sourcepub fn try_new_islamic_tabular_datetime_with_calendar(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_islamic_tabular_datetime_with_calendar( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct a new Tabular Islamic datetime from integers.
use icu::calendar::islamic::IslamicTabular;
use icu::calendar::DateTime;
let islamic = IslamicTabular::new_always_calculating();
let datetime_islamic =
DateTime::try_new_islamic_tabular_datetime_with_calendar(
474, 10, 11, 13, 1, 0, islamic,
)
.expect("Failed to initialize Islamic DateTime instance.");
assert_eq!(datetime_islamic.date.year().number, 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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Iso>, CalendarError>
pub fn try_new_iso_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Iso>, CalendarError>
Construct a new ISO datetime from integers.
use icu::calendar::DateTime;
let datetime_iso = DateTime::try_new_iso_datetime(1970, 1, 2, 13, 1, 0)
.expect("Failed to initialize ISO DateTime instance.");
assert_eq!(datetime_iso.date.year().number, 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);
sourcepub fn local_unix_epoch() -> Self
pub fn local_unix_epoch() -> Self
Constructs an ISO datetime representing the UNIX epoch on January 1, 1970 at midnight.
sourcepub fn minutes_since_local_unix_epoch(&self) -> i32
pub fn minutes_since_local_unix_epoch(&self) -> i32
Minute count representation of calendars starting from 00:00:00 on Jan 1st, 1970.
use icu::calendar::DateTime;
let today = DateTime::try_new_iso_datetime(2020, 2, 29, 0, 0, 0).unwrap();
assert_eq!(today.minutes_since_local_unix_epoch(), 26382240);
assert_eq!(
DateTime::from_minutes_since_local_unix_epoch(26382240),
today
);
let today = DateTime::try_new_iso_datetime(1970, 1, 1, 0, 0, 0).unwrap();
assert_eq!(today.minutes_since_local_unix_epoch(), 0);
assert_eq!(DateTime::from_minutes_since_local_unix_epoch(0), today);
sourcepub fn from_minutes_since_local_unix_epoch(minute: i32) -> DateTime<Iso>
pub fn from_minutes_since_local_unix_epoch(minute: i32) -> DateTime<Iso>
Convert minute count since 00:00:00 on Jan 1st, 1970 to ISO Date.
§Examples
use icu::calendar::DateTime;
// After Unix Epoch
let today = DateTime::try_new_iso_datetime(2020, 2, 29, 0, 0, 0).unwrap();
assert_eq!(today.minutes_since_local_unix_epoch(), 26382240);
assert_eq!(
DateTime::from_minutes_since_local_unix_epoch(26382240),
today
);
// Unix Epoch
let today = DateTime::try_new_iso_datetime(1970, 1, 1, 0, 0, 0).unwrap();
assert_eq!(today.minutes_since_local_unix_epoch(), 0);
assert_eq!(DateTime::from_minutes_since_local_unix_epoch(0), today);
// Before Unix Epoch
let today = DateTime::try_new_iso_datetime(1967, 4, 6, 20, 40, 0).unwrap();
assert_eq!(today.minutes_since_local_unix_epoch(), -1440200);
assert_eq!(
DateTime::from_minutes_since_local_unix_epoch(-1440200),
today
);
source§impl DateTime<Japanese>
impl DateTime<Japanese>
sourcepub fn try_new_japanese_datetime<A: AsCalendar<Calendar = Japanese>>(
era: Era,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
japanese_calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_japanese_datetime<A: AsCalendar<Calendar = Japanese>>( era: Era, year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, japanese_calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct a new Japanese datetime from integers.
Years are specified in the era provided.
use icu::calendar::japanese::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_datetime(
era,
14,
1,
2,
13,
1,
0,
japanese_calendar,
)
.expect("Constructing a date should succeed");
assert_eq!(datetime.date.year().era, era);
assert_eq!(datetime.date.year().number, 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_datetime<A: AsCalendar<Calendar = JapaneseExtended>>(
era: Era,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
japanext_calendar: A,
) -> Result<DateTime<A>, CalendarError>
pub fn try_new_japanese_extended_datetime<A: AsCalendar<Calendar = JapaneseExtended>>( era: Era, year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, japanext_calendar: A, ) -> Result<DateTime<A>, CalendarError>
Construct a new Japanese datetime from integers with all eras.
Years are specified in the era provided.
use icu::calendar::japanese::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_datetime(
era,
7,
1,
2,
13,
1,
0,
japanext_calendar,
)
.expect("Constructing a date should succeed");
assert_eq!(datetime.date.year().era, era);
assert_eq!(datetime.date.year().number, 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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Julian>, CalendarError>
pub fn try_new_julian_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Julian>, CalendarError>
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_datetime(1969, 12, 20, 13, 1, 0)
.expect("Failed to initialize Julian DateTime instance.");
assert_eq!(datetime_julian.date.year().number, 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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Persian>, CalendarError>
pub fn try_new_persian_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Persian>, CalendarError>
Construct a new Persian datetime from integers.
use icu::calendar::DateTime;
let datetime_persian =
DateTime::try_new_persian_datetime(474, 10, 11, 13, 1, 0)
.expect("Failed to initialize Persian DateTime instance.");
assert_eq!(datetime_persian.date.year().number, 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_datetime(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Roc>, CalendarError>
pub fn try_new_roc_datetime( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime<Roc>, CalendarError>
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_datetime(1, 2, 3, 13, 1, 0)
.expect("Failed to initialize ROC DateTime instance.");
assert_eq!(datetime_roc.date.year().era.0, tinystr!(16, "roc"));
assert_eq!(datetime_roc.date.year().number, 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> Ord for DateTime<A>
impl<C, A> Ord for DateTime<A>
source§impl<C, A, B> PartialEq<DateTime<B>> for DateTime<A>
impl<C, A, B> PartialEq<DateTime<B>> for DateTime<A>
source§impl<C, A, B> PartialOrd<DateTime<B>> for DateTime<A>where
C: Calendar,
C::DateInner: PartialOrd,
A: AsCalendar<Calendar = C>,
B: AsCalendar<Calendar = C>,
impl<C, A, B> PartialOrd<DateTime<B>> for DateTime<A>where
C: Calendar,
C::DateInner: PartialOrd,
A: AsCalendar<Calendar = C>,
B: AsCalendar<Calendar = C>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more