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".