#[repr(C)]pub struct Time { /* private fields */ }
Expand description
The clock time within a given date. Nanosecond precision.
All minutes are assumed to have exactly 60 seconds; no attempt is made to handle leap seconds (either positive or negative).
When comparing two Time
s, they are assumed to be in the same calendar date.
Implementations§
Source§impl Time
impl Time
Sourcepub const fn from_hms(
hour: u8,
minute: u8,
second: u8,
) -> Result<Self, ComponentRange>
pub const fn from_hms( hour: u8, minute: u8, second: u8, ) -> Result<Self, ComponentRange>
Attempt to create a Time
from the hour, minute, and second.
Sourcepub const fn from_hms_milli(
hour: u8,
minute: u8,
second: u8,
millisecond: u16,
) -> Result<Self, ComponentRange>
pub const fn from_hms_milli( hour: u8, minute: u8, second: u8, millisecond: u16, ) -> Result<Self, ComponentRange>
Attempt to create a Time
from the hour, minute, second, and millisecond.
assert!(Time::from_hms_milli(24, 0, 0, 0).is_err()); // 24 isn't a valid hour.
assert!(Time::from_hms_milli(0, 60, 0, 0).is_err()); // 60 isn't a valid minute.
assert!(Time::from_hms_milli(0, 0, 60, 0).is_err()); // 60 isn't a valid second.
assert!(Time::from_hms_milli(0, 0, 0, 1_000).is_err()); // 1_000 isn't a valid millisecond.
Sourcepub const fn from_hms_micro(
hour: u8,
minute: u8,
second: u8,
microsecond: u32,
) -> Result<Self, ComponentRange>
pub const fn from_hms_micro( hour: u8, minute: u8, second: u8, microsecond: u32, ) -> Result<Self, ComponentRange>
Attempt to create a Time
from the hour, minute, second, and microsecond.
assert!(Time::from_hms_micro(24, 0, 0, 0).is_err()); // 24 isn't a valid hour.
assert!(Time::from_hms_micro(0, 60, 0, 0).is_err()); // 60 isn't a valid minute.
assert!(Time::from_hms_micro(0, 0, 60, 0).is_err()); // 60 isn't a valid second.
assert!(Time::from_hms_micro(0, 0, 0, 1_000_000).is_err()); // 1_000_000 isn't a valid microsecond.
Sourcepub const fn from_hms_nano(
hour: u8,
minute: u8,
second: u8,
nanosecond: u32,
) -> Result<Self, ComponentRange>
pub const fn from_hms_nano( hour: u8, minute: u8, second: u8, nanosecond: u32, ) -> Result<Self, ComponentRange>
Attempt to create a Time
from the hour, minute, second, and nanosecond.
assert!(Time::from_hms_nano(24, 0, 0, 0).is_err()); // 24 isn't a valid hour.
assert!(Time::from_hms_nano(0, 60, 0, 0).is_err()); // 60 isn't a valid minute.
assert!(Time::from_hms_nano(0, 0, 60, 0).is_err()); // 60 isn't a valid second.
assert!(Time::from_hms_nano(0, 0, 0, 1_000_000_000).is_err()); // 1_000_000_000 isn't a valid nanosecond.
Sourcepub const fn millisecond(self) -> u16
pub const fn millisecond(self) -> u16
Sourcepub const fn microsecond(self) -> u32
pub const fn microsecond(self) -> u32
Sourcepub const fn nanosecond(self) -> u32
pub const fn nanosecond(self) -> u32
Sourcepub const fn replace_hour(self, hour: u8) -> Result<Self, ComponentRange>
pub const fn replace_hour(self, hour: u8) -> Result<Self, ComponentRange>
Sourcepub const fn replace_minute(self, minute: u8) -> Result<Self, ComponentRange>
pub const fn replace_minute(self, minute: u8) -> Result<Self, ComponentRange>
Sourcepub const fn replace_second(self, second: u8) -> Result<Self, ComponentRange>
pub const fn replace_second(self, second: u8) -> Result<Self, ComponentRange>
Sourcepub const fn replace_millisecond(
self,
millisecond: u16,
) -> Result<Self, ComponentRange>
pub const fn replace_millisecond( self, millisecond: u16, ) -> Result<Self, ComponentRange>
Sourcepub const fn replace_microsecond(
self,
microsecond: u32,
) -> Result<Self, ComponentRange>
pub const fn replace_microsecond( self, microsecond: u32, ) -> Result<Self, ComponentRange>
Sourcepub const fn replace_nanosecond(
self,
nanosecond: u32,
) -> Result<Self, ComponentRange>
pub const fn replace_nanosecond( self, nanosecond: u32, ) -> Result<Self, ComponentRange>
Source§impl Time
impl Time
Sourcepub fn format_into(
self,
output: &mut impl Write,
format: &(impl Formattable + ?Sized),
) -> Result<usize, Format>
Available on crate feature formatting
only.
pub fn format_into( self, output: &mut impl Write, format: &(impl Formattable + ?Sized), ) -> Result<usize, Format>
formatting
only.Format the Time
using the provided format description.
Sourcepub fn format(
self,
format: &(impl Formattable + ?Sized),
) -> Result<String, Format>
Available on crate feature formatting
only.
pub fn format( self, format: &(impl Formattable + ?Sized), ) -> Result<String, Format>
formatting
only.Format the Time
using the provided format description.
Trait Implementations§
Source§impl Add<Duration> for Time
impl Add<Duration> for Time
Source§impl Add<Duration> for Time
impl Add<Duration> for Time
Source§fn add(self, duration: StdDuration) -> Self::Output
fn add(self, duration: StdDuration) -> Self::Output
Add the sub-day time of the std::time::Duration
to the Time
. Wraps on overflow.
Source§impl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moreSource§impl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
Source§fn add_assign(&mut self, rhs: StdDuration)
fn add_assign(&mut self, rhs: StdDuration)
+=
operation. Read moreSource§impl Ord for Time
impl Ord for Time
Source§impl PartialOrd for Time
impl PartialOrd for Time
Source§impl SmartDisplay for Time
impl SmartDisplay for Time
Source§fn metadata(&self, _: FormatterOptions) -> Metadata<'_, Self>
fn metadata(&self, _: FormatterOptions) -> Metadata<'_, Self>
Source§impl Sub<Duration> for Time
impl Sub<Duration> for Time
Source§impl Sub<Duration> for Time
impl Sub<Duration> for Time
Source§fn sub(self, duration: StdDuration) -> Self::Output
fn sub(self, duration: StdDuration) -> Self::Output
Subtract the sub-day time of the std::time::Duration
from the Time
. Wraps on overflow.
Source§impl Sub for Time
impl Sub for Time
Source§impl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moreSource§impl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
Source§fn sub_assign(&mut self, rhs: StdDuration)
fn sub_assign(&mut self, rhs: StdDuration)
-=
operation. Read more