Time

Struct Time 

Source
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 that specify the time an MS-DOS file was last written to, and is used as timestamps such as FAT or ZIP file format.

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

Source

pub const MIN: Self

The smallest value that can be represented by the MS-DOS time.

This is “00:00:00”.

§Examples
assert_eq!(Time::MIN, Time::from_time(time::Time::MIDNIGHT));
Source

pub const MAX: Self

The largest value that can be represented by the MS-DOS time.

This is “23:59:58”.

§Examples
assert_eq!(Time::MAX, Time::from_time(time!(23:59:58)));
Source§

impl Time

Source

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);
Source

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.

§Examples
assert_eq!(unsafe { Time::new_unchecked(u16::MIN) }, Time::MIN);
assert_eq!(
    unsafe { Time::new_unchecked(0b1011_1111_0111_1101) },
    Time::MAX
);
Source

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);
Source

pub fn is_valid(self) -> bool

Returns true if self is a valid MS-DOS time, and false otherwise.

§Examples
assert_eq!(Time::MIN.is_valid(), true);
assert_eq!(Time::MAX.is_valid(), true);

// The DoubleSeconds field is 30.
assert_eq!(
    unsafe { Time::new_unchecked(0b0000_0000_0001_1110) }.is_valid(),
    false
);
Source

pub const fn to_raw(self) -> u16

Returns the MS-DOS time of this Time as the underlying u16 value.

§Examples
assert_eq!(Time::MIN.to_raw(), u16::MIN);
assert_eq!(Time::MAX.to_raw(), 0b1011_1111_0111_1101);
Source

pub fn hour(self) -> u8

Gets the hour of this Time.

§Examples
assert_eq!(Time::MIN.hour(), 0);
assert_eq!(Time::MAX.hour(), 23);
Source

pub fn minute(self) -> u8

Gets the minute of this Time.

§Examples
assert_eq!(Time::MIN.minute(), 0);
assert_eq!(Time::MAX.minute(), 59);
Source

pub fn second(self) -> u8

Gets the second of this Time.

§Examples
assert_eq!(Time::MIN.second(), 0);
assert_eq!(Time::MAX.second(), 58);

Trait Implementations§

Source§

impl Clone for Time

Source§

fn clone(&self) -> Time

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Time

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Time

Source§

fn default() -> Self

Returns the default value of “00:00:00”.

Equivalent to Time::MIN except that it is not callable in const contexts.

§Examples
assert_eq!(Time::default(), Time::MIN);
Source§

impl Display for Time

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Shows the value of this Time in the well-known RFC 3339 format.

§Examples
assert_eq!(format!("{}", Time::MIN), "00:00:00");
assert_eq!(format!("{}", Time::MAX), "23:59:58");
Source§

impl From<NaiveTime> for Time

Available on crate feature chrono only.
Source§

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 NaiveTime

Available on crate feature chrono only.
Source§

fn from(time: Time) -> Self

Converts a Time to a NaiveTime.

§Examples
assert_eq!(NaiveTime::from(Time::MIN), NaiveTime::MIN);
assert_eq!(
    NaiveTime::from(Time::MAX),
    "23:59:58".parse::<NaiveTime>().unwrap()
);
Source§

impl From<Time> for Time

Source§

fn from(time: Time) -> Self

Converts a Time to a time::Time.

§Examples
assert_eq!(time::Time::from(Time::MIN), time::Time::MIDNIGHT);
assert_eq!(time::Time::from(Time::MAX), time!(23:59:58));
Source§

impl From<Time> for Time

Available on crate feature jiff only.
Source§

fn from(time: Time) -> Self

Converts a Time to a civil::Time.

§Examples
assert_eq!(civil::Time::from(Time::MIN), civil::Time::MIN);
assert_eq!(civil::Time::from(Time::MAX), civil::time(23, 59, 58, 0));
Source§

impl From<Time> for Time

Source§

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.
Source§

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);
Source§

impl Hash for Time

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Time

Source§

fn cmp(&self, other: &Time) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Time

Source§

fn eq(&self, other: &Time) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Time

Source§

fn partial_cmp(&self, other: &Time) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Time

Source§

impl Eq for Time

Source§

impl StructuralPartialEq for Time

Auto Trait Implementations§

§

impl Freeze for Time

§

impl RefUnwindSafe for Time

§

impl Send for Time

§

impl Sync for Time

§

impl Unpin for Time

§

impl UnwindSafe for Time

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.