pub struct Instant<S: TimeScale> { /* private fields */ }Expand description
Instant on one time scale, nanosecond resolution.
Comparison and subtraction only within one scale (see the module
docs). Stored as seconds and nanoseconds since the scale’s
1970-01-01T00:00:00: range far beyond any calendar, and any i64 of Unix
nanoseconds fits.
Implementations§
Source§impl<S: TimeScale> Instant<S>
impl<S: TimeScale> Instant<S>
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
1970-01-01T00:00:00 on this scale.
Sourcepub fn new(seconds: i64, nanos: u32) -> Result<Self>
pub fn new(seconds: i64, nanos: u32) -> Result<Self>
Instant from whole seconds and nanoseconds within the second.
§Errors
KernelError::OutOfRange if nanos ≥ 1 s.
Sourcepub const fn from_unix_seconds(seconds: i64) -> Self
pub const fn from_unix_seconds(seconds: i64) -> Self
Instant a whole number of seconds from the epoch.
Sourcepub const fn from_unix_nanos(nanos: i64) -> Self
pub const fn from_unix_nanos(nanos: i64) -> Self
Instant nanos from the epoch (negative before it). Every i64 is
representable.
Sourcepub const fn subsec_nanos(self) -> u32
pub const fn subsec_nanos(self) -> u32
Nanoseconds past the whole second, 0..1_000_000_000.
Sourcepub const fn checked_unix_nanos(self) -> Option<i64>
pub const fn checked_unix_nanos(self) -> Option<i64>
Nanoseconds since the epoch, if within ~292 years (the i64 range).
Sourcepub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_add(self, duration: Duration) -> Option<Self>
self + duration; None on overflow.
Sourcepub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
self − duration; None on underflow.
Sourcepub fn saturating_add(self, duration: Duration) -> Self
pub fn saturating_add(self, duration: Duration) -> Self
self + duration, saturating.
Sourcepub fn saturating_sub(self, duration: Duration) -> Self
pub fn saturating_sub(self, duration: Duration) -> Self
self − duration, saturating.
Sourcepub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
pub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
Duration since earlier; None unless self ≥ earlier.
Sourcepub fn duration_since(self, earlier: Self) -> Result<Duration>
pub fn duration_since(self, earlier: Self) -> Result<Duration>
Duration since earlier.
§Errors
KernelError::TimeReversed if earlier is later (clock stepped back
or arguments swapped), with the amount.
Sourcepub fn from_civil(civil: Civil) -> Result<Self>
pub fn from_civil(civil: Civil) -> Result<Self>
Instant for a calendar reading on this scale.
§Errors
KernelError::OutOfRange for an invalid month, day, hour, minute,
second or nanosecond. Second 60 (leap second) is rejected: the count
has no place for it; the parser decides which side of the step it
belongs to.