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
impl Time
Sourcepub const MAX: Time
pub const MAX: Time
The maximum allowed civil time.
This corresponds to the last nanosecond in a civil day.
Sourcepub const fn new(
hour: i8,
minute: i8,
second: i8,
subsec_nanosecond: i32,
) -> Result<Time, RangeError>
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.
Sourcepub const fn hour(self) -> i8
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.
Sourcepub const fn minute(self) -> i8
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.
Sourcepub const fn second(self) -> i8
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.
Sourcepub const fn millisecond(self) -> i16
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.
Sourcepub const fn microsecond(self) -> i16
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.
Sourcepub const fn nanosecond(self) -> i16
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.
Sourcepub const fn subsec_nanosecond(self) -> i32
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.
Sourcepub const fn with_subsec_parts(
self,
millisecond: i16,
microsecond: i16,
nanosecond: i16,
) -> Result<Time, RangeError>
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.
Sourcepub const fn with_subsec_nanosecond(
self,
subsec_nanosecond: i32,
) -> Result<Time, RangeError>
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.
Sourcepub const fn to_second(self) -> TimeSecond
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.
Sourcepub const fn to_nanosecond(self) -> TimeNanosecond
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.
Sourcepub const fn on(self, year: i16, month: i8, day: i8) -> DateTime
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
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.