#[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.
Source#[doc(hidden)] pub const unsafe fn __from_hms_nanos_unchecked(
hour: u8,
minute: u8,
second: u8,
nanosecond: u32,
) -> Self
#[doc(hidden)] pub const unsafe fn __from_hms_nanos_unchecked( hour: u8, minute: u8, second: u8, nanosecond: u32, ) -> Self
Create a Time
from its components.
§Safety
hours
must be in the range0..=23
.minutes
must be in the range0..=59
.seconds
must be in the range0..=59
.nanoseconds
must be in the range0..=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(crate) const fn as_hms_nano_ranged(
self,
) -> (RangedU8<0, { _ }>, RangedU8<0, { _ }>, RangedU8<0, { _ }>, RangedU32<0, { _ }>)
Available on crate feature quickcheck
only.
pub(crate) const fn as_hms_nano_ranged( self, ) -> (RangedU8<0, { _ }>, RangedU8<0, { _ }>, RangedU8<0, { _ }>, RangedU32<0, { _ }>)
quickcheck
only.Get the clock hour, minute, second, and 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>
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<'a> Deserialize<'a> for Time
Available on crate feature serde
only.
impl<'a> Deserialize<'a> for Time
serde
only.Source§fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
Source§#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
self
from the given Deserializer. Read moreSource§impl Distribution<Time> for Standard
Available on crate feature rand
only.
impl Distribution<Time> for Standard
rand
only.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 more