Struct Time
pub struct Time { /* private fields */ }
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
impl Time
const MIN: Time = _;The minimum allowed civil time.
This corresponds to midnight.
const MAX: Time = _;The maximum allowed civil time.
This corresponds to the last nanosecond in a civil day.
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.
const fn hour(self) -> i8Returns the hour component of this civil time.
The value returned is guaranteed to be in the range specified by
Hour.const fn minute(self) -> i8Returns the minute component of this civil time.
The value returned is guaranteed to be in the range specified by
Minute.const fn second(self) -> i8Returns the second component of this civil time.
The value returned is guaranteed to be in the range specified by
Second.const fn millisecond(self) -> i16Returns the "millisecond" component of this time.
The value returned is guaranteed to be in the range
0..=999.const fn microsecond(self) -> i16Returns the "microsecond" component of this time.
The value returned is guaranteed to be in the range
0..=999.const fn nanosecond(self) -> i16Returns the "nanosecond" component of this time.
The value returned is guaranteed to be in the range
0..=999.const fn subsec_nanosecond(self) -> i32Returns the fractional second (to nanosecond precision) component of this civil time.
The value returned is guaranteed to be in the range specified by
SubsecNanosecond.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.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.const fn to_second(self) -> TimeSecondConverts 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.const fn to_nanosecond(self) -> TimeNanosecondConverts 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.const fn on(self, year: i16, month: i8, day: i8) -> DateTimeA convenience function for constructing a
DateTimefrom this time on the date given by its components.Panics
This routine panics when
Date::newwith 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
1and must be at most the number of days in the corresponding month. So for example,2024-02-29is valid but2023-02-29is not.
Similarly, when used in a const context, invalid parameters will prevent your Rust program from compiling.
- The year must be in the range
Trait Implementations
impl Clone for Time
fn clone(&self) -> Time
impl Copy for Time
impl Debug for Time
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Time
impl Hash for Time
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for Time
fn cmp(&self, other: &Time) -> Ordering
impl PartialEq for Time
fn eq(&self, other: &Time) -> bool
impl PartialOrd for Time
fn partial_cmp(&self, other: &Time) -> Option<Ordering>
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
impl<T> Any for Time
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Time
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Time
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Time
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Time
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Time
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Time
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Time
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for Time
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>