Struct compact_time::Time
source · pub struct Time(/* private fields */);Expand description
A time value with nanosecond precision.
Implementations§
source§impl Time
impl Time
sourcepub fn try_now() -> Result<Self, OutOfRange>
pub fn try_now() -> Result<Self, OutOfRange>
sourcepub fn try_coarse() -> Result<Self, OutOfRange>
pub fn try_coarse() -> Result<Self, OutOfRange>
sourcepub fn from_seconds(s: u64) -> Self
pub fn from_seconds(s: u64) -> Self
sourcepub fn try_from_seconds(s: u64) -> Result<Self, OutOfRange>
pub fn try_from_seconds(s: u64) -> Result<Self, OutOfRange>
Construct a time value from the given seconds.
Fails if the given seconds are greater than Time::MAX seconds.
sourcepub const fn from_nanos(n: u64) -> Self
pub const fn from_nanos(n: u64) -> Self
Construct a time value from the given nanoseconds.
sourcepub const fn second_nanos(self) -> u64
pub const fn second_nanos(self) -> u64
Subsecond nanoseconds.
sourcepub fn try_add(self, t: Time) -> Result<Self, OutOfRange>
pub fn try_add(self, t: Time) -> Result<Self, OutOfRange>
Try to add the given time value.
Fails if the result would be greater than Time::MAX.
sourcepub fn try_sub(self, t: Time) -> Result<Self, OutOfRange>
pub fn try_sub(self, t: Time) -> Result<Self, OutOfRange>
Try to substract the given time value.
Fails if the result would be less than Time::MIN.
sourcepub fn add_nanos(self, n: u64) -> Self
pub fn add_nanos(self, n: u64) -> Self
Add the given number of nanoseconds.
§Panics
If the result would be greater than Time::MAX. See
Time::add_nanos_checked for an alternative that does
not panic.
sourcepub fn add_seconds(self, s: u64) -> Self
pub fn add_seconds(self, s: u64) -> Self
Add the given number of seconds.
§Panics
If the result would be greater than Time::MAX. See
Time::add_seconds_checked for an alternative that does
not panic.
sourcepub fn add_minutes(self, m: u64) -> Self
pub fn add_minutes(self, m: u64) -> Self
Add the given number of minutes.
§Panics
If the result would be greater than Time::MAX. See
Time::add_minutes_checked for an alternative that does
not panic.
sourcepub fn add_hours(self, h: u64) -> Self
pub fn add_hours(self, h: u64) -> Self
Add the given number of hours.
§Panics
If the result would be greater than Time::MAX. See
Time::add_hours_checked for an alternative that does
not panic.
sourcepub fn add_days(self, d: u64) -> Self
pub fn add_days(self, d: u64) -> Self
Add the given number of days.
§Panics
If the result would be greater than Time::MAX. See
Time::add_days_checked for an alternative that does
not panic.
sourcepub fn add_nanos_checked(self, n: u64) -> Result<Self, OutOfRange>
pub fn add_nanos_checked(self, n: u64) -> Result<Self, OutOfRange>
Add the given number of nanoseconds.
Fails if the result would be greater than Time::MAX.
sourcepub fn add_seconds_checked(self, s: u64) -> Result<Self, OutOfRange>
pub fn add_seconds_checked(self, s: u64) -> Result<Self, OutOfRange>
Add the given number of seconds.
Fails if the result would be greater than Time::MAX.
sourcepub fn add_minutes_checked(self, m: u64) -> Result<Self, OutOfRange>
pub fn add_minutes_checked(self, m: u64) -> Result<Self, OutOfRange>
Add the given number of minutes.
Fails if the result would be greater than Time::MAX.
sourcepub fn add_hours_checked(self, h: u64) -> Result<Self, OutOfRange>
pub fn add_hours_checked(self, h: u64) -> Result<Self, OutOfRange>
Add the given number of hours.
Fails if the result would be greater than Time::MAX.
sourcepub fn add_days_checked(self, d: u64) -> Result<Self, OutOfRange>
pub fn add_days_checked(self, d: u64) -> Result<Self, OutOfRange>
Add the given number of days.
Fails if the result would be greater than Time::MAX.
sourcepub fn sub_nanos(self, n: u64) -> Self
pub fn sub_nanos(self, n: u64) -> Self
Substract the given number of nanoseconds.
§Panics
If the result would be less than Time::MIN. See
Time::sub_nanos_checked for an alternative that does
not panic.
sourcepub fn sub_seconds(self, s: u64) -> Self
pub fn sub_seconds(self, s: u64) -> Self
Substract the given number of seconds.
§Panics
If the result would be less than Time::MIN. See
Time::sub_seconds_checked for an alternative that does
not panic.
sourcepub fn sub_minutes(self, m: u64) -> Self
pub fn sub_minutes(self, m: u64) -> Self
Substract the given number of minutes.
§Panics
If the result would be less than Time::MIN. See
Time::sub_minutes_checked for an alternative that does
not panic.
sourcepub fn sub_hours(self, h: u64) -> Self
pub fn sub_hours(self, h: u64) -> Self
Substract the given number of hours.
§Panics
If the result would be less than Time::MIN. See
Time::sub_hours_checked for an alternative that does
not panic.
sourcepub fn sub_days(self, d: u64) -> Self
pub fn sub_days(self, d: u64) -> Self
Substract the given number of days.
§Panics
If the result would be less than Time::MIN. See
Time::sub_days_checked for an alternative that does
not panic.
sourcepub fn sub_nanos_checked(self, n: u64) -> Result<Self, OutOfRange>
pub fn sub_nanos_checked(self, n: u64) -> Result<Self, OutOfRange>
Substract the given number of nanoseconds.
Fails if the result would be less than Time::MIN.
sourcepub fn sub_seconds_checked(self, s: u64) -> Result<Self, OutOfRange>
pub fn sub_seconds_checked(self, s: u64) -> Result<Self, OutOfRange>
Substract the given number of seconds.
Fails if the result would be less than Time::MIN.
sourcepub fn sub_minutes_checked(self, m: u64) -> Result<Self, OutOfRange>
pub fn sub_minutes_checked(self, m: u64) -> Result<Self, OutOfRange>
Substract the given number of minutes.
Fails if the result would be less than Time::MIN.
sourcepub fn sub_hours_checked(self, h: u64) -> Result<Self, OutOfRange>
pub fn sub_hours_checked(self, h: u64) -> Result<Self, OutOfRange>
Substract the given number of hours.
Fails if the result would be less than Time::MIN.
sourcepub fn sub_days_checked(self, d: u64) -> Result<Self, OutOfRange>
pub fn sub_days_checked(self, d: u64) -> Result<Self, OutOfRange>
Substract the given number of days.
Fails if the result would be less than Time::MIN.
sourcepub const fn to_duration(self) -> Duration
pub const fn to_duration(self) -> Duration
Convert this time value to the std::time::Duration since the Unix epoch.
sourcepub fn duration_since(self, earlier: Self) -> Option<Duration>
pub fn duration_since(self, earlier: Self) -> Option<Duration>
Convert the delta between this time and the given one into a std::time::Duration.
Returns None if the argument is greater that self.
sourcepub fn to_utc_string(self) -> Option<String>
pub fn to_utc_string(self) -> Option<String>
Format this time value as YYYY-MM-DDThh:mm:ss.nnnnnnnnnZ.
Requires feature "utc".
Trait Implementations§
source§impl<'de> Deserialize<'de> for Time
impl<'de> Deserialize<'de> for Time
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Ord for Time
impl Ord for Time
source§impl PartialEq for Time
impl PartialEq for Time
source§impl PartialOrd for Time
impl PartialOrd for Time
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more