pub struct Time(/* private fields */);Expand description
Time is a type that represents the MS-DOS time.
This is a packed 16-bit unsigned integer value.
The resolution of MS-DOS time is 2 seconds.
See the format specification for Kaitai Struct for more details on the structure of the MS-DOS time.
Implementations§
Source§impl Time
impl Time
Source§impl Time
impl Time
Sourcepub fn new(time: u16) -> Option<Self>
pub fn new(time: u16) -> Option<Self>
Creates a new Time with the given MS-DOS time.
Returns None if the given MS-DOS time is not a valid MS-DOS time.
§Examples
assert_eq!(Time::new(u16::MIN), Some(Time::MIN));
assert_eq!(Time::new(0b1011_1111_0111_1101), Some(Time::MAX));
// The DoubleSeconds field is 30.
assert_eq!(Time::new(0b0000_0000_0001_1110), None);Sourcepub const unsafe fn new_unchecked(time: u16) -> Self
pub const unsafe fn new_unchecked(time: u16) -> Self
Creates a new Time with the given MS-DOS time.
§Safety
The given MS-DOS time must be a valid MS-DOS time.
Sourcepub fn from_time(time: Time) -> Self
pub fn from_time(time: Time) -> Self
Creates a new Time with the given time::Time.
The resolution of MS-DOS time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Examples
assert_eq!(Time::from_time(time::Time::MIDNIGHT), Time::MIN);
assert_eq!(Time::from_time(time!(23:59:58)), Time::MAX);Sourcepub fn hour(self) -> u8
pub fn hour(self) -> u8
Gets the hour of this Time.
§Examples
assert_eq!(Time::MIN.hour(), 0);
assert_eq!(Time::MAX.hour(), 23);Trait Implementations§
Source§impl From<NaiveTime> for Time
Available on crate feature chrono only.
impl From<NaiveTime> for Time
chrono only.Source§fn from(time: NaiveTime) -> Self
fn from(time: NaiveTime) -> Self
Converts a NaiveTime to a Time.
The resolution of MS-DOS time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Examples
assert_eq!(Time::from(NaiveTime::MIN), Time::MIN);
assert_eq!(
Time::from("23:59:58".parse::<NaiveTime>().unwrap()),
Time::MAX
);Source§impl From<Time> for Time
impl From<Time> for Time
Source§fn from(time: Time) -> Self
fn from(time: Time) -> Self
Converts a time::Time to a Time.
The resolution of MS-DOS time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Examples
assert_eq!(Time::from(time::Time::MIDNIGHT), Time::MIN);
assert_eq!(Time::from(time!(23:59:58)), Time::MAX);Source§impl From<Time> for Time
Available on crate feature jiff only.
impl From<Time> for Time
jiff only.Source§fn from(time: Time) -> Self
fn from(time: Time) -> Self
Converts a civil::Time to a Time.
The resolution of MS-DOS time is 2 seconds. So this method rounds towards zero, truncating any fractional part of the exact result of dividing seconds by 2.
§Examples
assert_eq!(Time::from(civil::Time::MIN), Time::MIN);
assert_eq!(Time::from(civil::time(23, 59, 58, 0)), Time::MAX);