pub struct DateTime<A: AsCalendar> {
pub date: Date<A>,
pub time: Time,
}Expand description
A date and time for a given calendar.
The primary definition of this type is in the icu_time crate. Other ICU4X crates re-export it for convenience.
This type exists as an input type for datetime formatting and should only be constructed to pass to a datetime formatter.
§Semantics
This type represents the date and time that are displayed to a user. It does not identify the absolute time that an event happens, nor does it represent the general concept of a “local date time”, which would require time zone and leap second information for operations like validation, arithmetic, and comparisons.
Hence, while this type implements PartialEq/Eq (equal DateTimes will display
equally), it does not implement PartialOrd/Ord, arithmetic, and it is possible to
create DateTimes that do not exist for a particular timezone.
Fields§
§date: Date<A>The date
time: TimeThe time
Implementations§
Source§impl<A: AsCalendar> DateTime<A>
impl<A: AsCalendar> DateTime<A>
Sourcepub fn try_from_str(rfc_9557_str: &str, calendar: A) -> Result<Self, ParseError>
pub fn try_from_str(rfc_9557_str: &str, calendar: A) -> Result<Self, ParseError>
Creates a DateTime in any calendar from an RFC 9557 string.
Returns an error if the string has a calendar annotation that does not match the calendar argument.
✨ Enabled with the ixdtf Cargo feature.
§Examples
use icu::calendar::cal::Hebrew;
use icu::time::DateTime;
let datetime =
DateTime::try_from_str("2024-07-17T16:01:17.045[u-ca=hebrew]", Hebrew)
.unwrap();
assert_eq!(datetime.date.era_year().year, 5784);
assert_eq!(
datetime.date.month().to_input().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.subsecond.number(), 45000000);Sourcepub fn try_from_utf8(
rfc_9557_str: &[u8],
calendar: A,
) -> Result<Self, ParseError>
pub fn try_from_utf8( rfc_9557_str: &[u8], calendar: A, ) -> Result<Self, ParseError>
Creates a DateTime in any calendar from an RFC 9557 string.
See Self::try_from_str().
✨ Enabled with the ixdtf Cargo feature.