Skip to main content

Time

Struct Time 

Source
pub struct Time { /* private fields */ }
Expand description

The civil time of day.

This time’s representation uses nanosecond precision. The full range of clock values are 00:00:00.000000000 to 23:59:59.999999999 inclusive.

Implementations§

Source§

impl Time

Source

pub const MIN: Time

The minimum allowed civil time.

This corresponds to midnight.

Source

pub const MAX: Time

The maximum allowed civil time.

This corresponds to the last nanosecond in a civil day.

Source

pub const fn new( hour: i8, minute: i8, second: i8, subsec_nanosecond: i32, ) -> Result<Time, RangeError>

Creates a new civil time from its constituent components.

If any of the values are out of their supported ranges, then an error is returned.

Source

pub const fn hour(self) -> i8

Returns the hour component of this civil time.

The value returned is guaranteed to be in the range specified by Hour.

Source

pub const fn minute(self) -> i8

Returns the minute component of this civil time.

The value returned is guaranteed to be in the range specified by Minute.

Source

pub const fn second(self) -> i8

Returns the second component of this civil time.

The value returned is guaranteed to be in the range specified by Second.

Source

pub const fn millisecond(self) -> i16

Returns the “millisecond” component of this time.

The value returned is guaranteed to be in the range 0..=999.

Source

pub const fn microsecond(self) -> i16

Returns the “microsecond” component of this time.

The value returned is guaranteed to be in the range 0..=999.

Source

pub const fn nanosecond(self) -> i16

Returns the “nanosecond” component of this time.

The value returned is guaranteed to be in the range 0..=999.

Source

pub const fn subsec_nanosecond(self) -> i32

Returns the fractional second (to nanosecond precision) component of this civil time.

The value returned is guaranteed to be in the range specified by SubsecNanosecond.

Source

pub const fn with_subsec_parts( self, millisecond: i16, microsecond: i16, nanosecond: i16, ) -> Result<Time, RangeError>

Returns this time with its subsecond component replaced with the three given subsecond components.

If any of the given components are out of range (0..=999), then an error is returned.

Source

pub const fn with_subsec_nanosecond( self, subsec_nanosecond: i32, ) -> Result<Time, RangeError>

Returns this time with its subsecond component replaced with the nanosecond component given.

If the number of nanoseconds is out of range (0..=999_999_999), then an error is returned.

Source

pub const fn to_second(self) -> TimeSecond

Converts this civil time to a second value corresponding to the number of seconds that has elapsed since midnight until this time. If this time is midnight, then the second value returned is 0.

Note that this drops any subsecond component on this civil time.

The value returned is guaranteed to be in the range specified by CivilDaySecond.

Source

pub const fn to_nanosecond(self) -> TimeNanosecond

Converts this civil time to a nanosecond value corresponding to the number of nanoseconds that has elapsed since midnight until this time. If this time is midnight, then the nanosecond value returned is 0.

The value returned is guaranteed to be in the range specified by CivilDayNanosecond.

Source

pub const fn on(self, year: i16, month: i8, day: i8) -> DateTime

A convenience function for constructing a DateTime from this time on the date given by its components.

§Panics

This routine panics when Date::new with the given inputs would return an error. That is, when the given year-month-day does not correspond to a valid date. Namely, all of the following must be true:

  • The year must be in the range -9999..=9999.
  • The month must be in the range 1..=12.
  • The day must be at least 1 and must be at most the number of days in the corresponding month. So for example, 2024-02-29 is valid but 2023-02-29 is not.

Similarly, when used in a const context, invalid parameters will prevent your Rust program from compiling.

Trait Implementations§

Source§

impl Clone for Time

Source§

fn clone(&self) -> Time

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Time

Source§

impl Debug for Time

Source§

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

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

impl Eq for Time

Source§

impl Format for Time

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
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 · Source§

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 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 (const: unstable) · Source§

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

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

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 (const: unstable) · Source§

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

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

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 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 UnsafeUnpin for Time

§

impl UnwindSafe for Time

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.