#[repr(C)]pub struct Time {
nanosecond: RangedU32<0, { _ }>,
second: RangedU8<0, { _ }>,
minute: RangedU8<0, { _ }>,
hour: RangedU8<0, { _ }>,
padding: Padding,
}
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.
Fields§
§nanosecond: RangedU32<0, { _ }>
§second: RangedU8<0, { _ }>
§minute: RangedU8<0, { _ }>
§hour: RangedU8<0, { _ }>
§padding: Padding
Implementations§
source§impl Time
impl Time
sourceconst fn as_u64(self) -> u64
const fn as_u64(self) -> u64
Provides an u64 based representation of the correct endianness
This representation can be used to do comparisons equality testing or hashing.
sourcepub(crate) const MAX: Self = _
pub(crate) const MAX: Self = _
The largest value that can be represented by Time
.
23:59:59.999_999_999
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(crate) const fn from_hms_nanos_ranged(
hour: RangedU8<0, { _ }>,
minute: RangedU8<0, { _ }>,
second: RangedU8<0, { _ }>,
nanosecond: RangedU32<0, { _ }>,
) -> Self
pub(crate) const fn from_hms_nanos_ranged( hour: RangedU8<0, { _ }>, minute: RangedU8<0, { _ }>, second: RangedU8<0, { _ }>, nanosecond: RangedU32<0, { _ }>, ) -> Self
Create a Time
from the hour, minute, second, and nanosecond.
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(crate) const fn adjusting_add(
self,
duration: Duration,
) -> (DateAdjustment, Self)
pub(crate) const fn adjusting_add( self, duration: Duration, ) -> (DateAdjustment, Self)
Add the sub-day time of the Duration
to the Time
. Wraps on overflow, returning whether
the date is different.
sourcepub(crate) const fn adjusting_sub(
self,
duration: Duration,
) -> (DateAdjustment, Self)
pub(crate) const fn adjusting_sub( self, duration: Duration, ) -> (DateAdjustment, Self)
Subtract the sub-day time of the Duration
to the Time
. Wraps on overflow, returning
whether the date is different.
sourcepub(crate) const fn adjusting_add_std(
self,
duration: StdDuration,
) -> (bool, Self)
pub(crate) const fn adjusting_add_std( self, duration: StdDuration, ) -> (bool, Self)
Add the sub-day time of the std::time::Duration
to the Time
. Wraps on overflow,
returning whether the date is the previous date as the first element of the tuple.
sourcepub(crate) const fn adjusting_sub_std(
self,
duration: StdDuration,
) -> (bool, Self)
pub(crate) const fn adjusting_sub_std( self, duration: StdDuration, ) -> (bool, Self)
Subtract the sub-day time of the std::time::Duration
to the Time
. Wraps on overflow,
returning whether the date is the previous date as the first element of the tuple.
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>
pub fn format_into( self, output: &mut impl Write, format: &(impl Formattable + ?Sized), ) -> Result<usize, Format>
Format the Time
using the provided format description.
sourcepub fn format(
self,
format: &(impl Formattable + ?Sized),
) -> Result<String, Format>
pub fn format( self, format: &(impl Formattable + ?Sized), ) -> Result<String, Format>
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<'a> Deserialize<'a> for Time
impl<'a> Deserialize<'a> for Time
source§fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
source§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§type Metadata = TimeMetadata
type Metadata = TimeMetadata
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 moreimpl Copy for Time
impl Eq 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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)