pub struct DateTime { /* private fields */ }Expand description
DateTime is a type that combines a Date and a Time and represents
MS-DOS date and time.
These are packed 16-bit unsigned integer values that specify the date and time an MS-DOS file was last written to, and are used as timestamps such as FAT or ZIP file format.
The resolution of MS-DOS date and time is 2 seconds.
See the format specification for Kaitai Struct for more details on the structure of MS-DOS date and time.
Implementations§
Source§impl DateTime
impl DateTime
Source§impl DateTime
impl DateTime
Sourcepub fn from_date_time(
date: Date,
time: Time,
) -> Result<Self, DateTimeRangeError>
pub fn from_date_time( date: Date, time: Time, ) -> Result<Self, DateTimeRangeError>
Creates a new DateTime with the given time::Date and
time::Time.
The resolution of MS-DOS date and time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Errors
Returns Err if date or time are invalid as MS-DOS date and time.
§Examples
assert_eq!(
DateTime::from_date_time(date!(1980-01-01), Time::MIDNIGHT),
Ok(DateTime::MIN)
);
assert_eq!(
DateTime::from_date_time(date!(2107-12-31), time!(23:59:58)),
Ok(DateTime::MAX)
);
// Before `1980-01-01 00:00:00`.
assert!(DateTime::from_date_time(date!(1979-12-31), time!(23:59:59)).is_err());
// After `2107-12-31 23:59:59`.
assert!(DateTime::from_date_time(date!(2108-01-01), Time::MIDNIGHT).is_err());Sourcepub const fn year(self) -> u16
pub const fn year(self) -> u16
Gets the year of this DateTime.
§Examples
assert_eq!(DateTime::MIN.year(), 1980);
assert_eq!(DateTime::MAX.year(), 2107);Sourcepub fn month(self) -> Month
pub fn month(self) -> Month
Gets the month of this DateTime.
§Examples
assert_eq!(DateTime::MIN.month(), Month::January);
assert_eq!(DateTime::MAX.month(), Month::December);Sourcepub fn day(self) -> u8
pub fn day(self) -> u8
Gets the day of this DateTime.
§Examples
assert_eq!(DateTime::MIN.day(), 1);
assert_eq!(DateTime::MAX.day(), 31);Sourcepub fn hour(self) -> u8
pub fn hour(self) -> u8
Gets the hour of this DateTime.
§Examples
assert_eq!(DateTime::MIN.hour(), 0);
assert_eq!(DateTime::MAX.hour(), 23);Trait Implementations§
Source§impl Default for DateTime
impl Default for DateTime
Source§fn default() -> Self
fn default() -> Self
Returns the default value of “1980-01-01 00:00:00”.
Equivalent to DateTime::MIN except that it is not callable in const
contexts.
§Examples
assert_eq!(DateTime::default(), DateTime::MIN);Source§impl From<DateTime> for NaiveDateTime
Available on crate feature chrono only.
impl From<DateTime> for NaiveDateTime
chrono only.Source§impl From<DateTime> for PrimitiveDateTime
impl From<DateTime> for PrimitiveDateTime
Source§impl Ord for DateTime
impl Ord for DateTime
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
Source§impl TryFrom<DateTime> for DateTime
Available on crate feature jiff only.
impl TryFrom<DateTime> for DateTime
jiff only.Source§fn try_from(dt: DateTime) -> Result<Self, Self::Error>
fn try_from(dt: DateTime) -> Result<Self, Self::Error>
Converts a civil::DateTime to a DateTime.
The resolution of MS-DOS date and time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Errors
Returns Err if dt is out of range for MS-DOS date and time.
§Examples
assert_eq!(
DateTime::try_from(civil::date(1980, 1, 1).at(0, 0, 0, 0)),
Ok(DateTime::MIN)
);
assert_eq!(
DateTime::try_from(civil::date(2107, 12, 31).at(23, 59, 58, 0)),
Ok(DateTime::MAX)
);
// Before `1980-01-01 00:00:00`.
assert!(DateTime::try_from(civil::date(1979, 12, 31).at(23, 59, 59, 0)).is_err());
// After `2107-12-31 23:59:59`.
assert!(DateTime::try_from(civil::date(2108, 1, 1).at(0, 0, 0, 0)).is_err());Source§type Error = DateTimeRangeError
type Error = DateTimeRangeError
Source§impl TryFrom<NaiveDateTime> for DateTime
Available on crate feature chrono only.
impl TryFrom<NaiveDateTime> for DateTime
chrono only.Source§fn try_from(dt: NaiveDateTime) -> Result<Self, Self::Error>
fn try_from(dt: NaiveDateTime) -> Result<Self, Self::Error>
Converts a NaiveDateTime to a DateTime.
The resolution of MS-DOS date and time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Errors
Returns Err if dt is out of range for MS-DOS date and time.
§Examples
assert_eq!(
DateTime::try_from("1980-01-01T00:00:00".parse::<NaiveDateTime>().unwrap()),
Ok(DateTime::MIN)
);
assert_eq!(
DateTime::try_from("2107-12-31T23:59:58".parse::<NaiveDateTime>().unwrap()),
Ok(DateTime::MAX)
);
// Before `1980-01-01 00:00:00`.
assert!(DateTime::try_from("1979-12-31T23:59:59".parse::<NaiveDateTime>().unwrap()).is_err());
// After `2107-12-31 23:59:59`.
assert!(DateTime::try_from("2108-01-01T00:00:00".parse::<NaiveDateTime>().unwrap()).is_err());Source§type Error = DateTimeRangeError
type Error = DateTimeRangeError
Source§impl TryFrom<PrimitiveDateTime> for DateTime
impl TryFrom<PrimitiveDateTime> for DateTime
Source§fn try_from(dt: PrimitiveDateTime) -> Result<Self, Self::Error>
fn try_from(dt: PrimitiveDateTime) -> Result<Self, Self::Error>
Converts a PrimitiveDateTime to a DateTime.
The resolution of MS-DOS date and time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Errors
Returns Err if dt is out of range for MS-DOS date and time.
§Examples
assert_eq!(
DateTime::try_from(datetime!(1980-01-01 00:00:00)),
Ok(DateTime::MIN)
);
assert_eq!(
DateTime::try_from(datetime!(2107-12-31 23:59:58)),
Ok(DateTime::MAX)
);
// Before `1980-01-01 00:00:00`.
assert!(DateTime::try_from(datetime!(1979-12-31 23:59:59)).is_err());
// After `2107-12-31 23:59:59`.
assert!(DateTime::try_from(datetime!(2108-01-01 00:00:00)).is_err());