pub struct Timestamp { /* private fields */ }Expand description
An instant in time, held as seconds and nanoseconds since the Unix epoch, UTC.
The wire form is RFC 3339. Parsing accepts any RFC 3339 spelling — Z, z, a
numeric offset, T or t or a space separator, zero to nine fractional digits —
and converts to UTC. Formatting always emits YYYY-MM-DDTHH:MM:SS[.fff]Z with the
fewest of {0, 3, 6, 9} fractional digits that loses nothing, so re-encoding a
message a proxy did not change is a no-op.
Seconds-plus-nanoseconds rather than a single nanosecond count because a peer may
legitimately send a far-future instant — S2J messages/FRBC.TimerStatus.finished_at
explicitly allows “an arbitrary DateTimeStamp in the past”, and nothing bounds the
future — and a 64-bit nanosecond count only reaches the year 2262.
use s2_kit::types::Timestamp;
let t: Timestamp = "2019-08-24T14:15:22Z".parse().unwrap();
assert_eq!(t.to_string(), "2019-08-24T14:15:22Z");
// Offsets are normalised to UTC.
let t: Timestamp = "2019-08-24T16:15:22+02:00".parse().unwrap();
assert_eq!(t.to_string(), "2019-08-24T14:15:22Z");Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
1970-01-01T00:00:00Z.
Sourcepub const fn from_unix(secs: i64, nanos: u32) -> Self
pub const fn from_unix(secs: i64, nanos: u32) -> Self
The instant secs seconds and nanos nanoseconds after the Unix epoch.
nanos is normalised into 0..1_000_000_000.
Sourcepub const fn from_unix_millis(millis: i64) -> Self
pub const fn from_unix_millis(millis: i64) -> Self
The instant millis milliseconds after the Unix epoch.
Sourcepub const fn subsec_nanos(self) -> u32
pub const fn subsec_nanos(self) -> u32
The sub-second part, in nanoseconds.
Sourcepub const fn unix_millis(self) -> Option<i64>
pub const fn unix_millis(self) -> Option<i64>
Milliseconds since the Unix epoch (floor), or None if it does not fit.
Sourcepub fn now() -> Self
Available on crate feature std only.
pub fn now() -> Self
std only.The current instant.
Provided for drivers, examples and applications. Nothing in the protocol core
calls it: every engine takes now as a parameter, which is what makes a
two-hour timer a microsecond-long unit test.
Sourcepub const fn checked_add(self, d: Duration) -> Option<Self>
pub const fn checked_add(self, d: Duration) -> Option<Self>
This instant plus d, or None on overflow.
Sourcepub const fn checked_sub(self, d: Duration) -> Option<Self>
pub const fn checked_sub(self, d: Duration) -> Option<Self>
This instant minus d, or None on overflow.
Sourcepub const fn checked_duration_since(self, earlier: Self) -> Option<Duration>
pub const fn checked_duration_since(self, earlier: Self) -> Option<Duration>
How long after earlier this instant is, or None when it is not after it.
None also for a gap no Duration can hold. Every step is checked: a peer’s
timestamp is data, and two instants far enough apart to overflow an i64 of
seconds must not be an arithmetic panic in a driver that is answering one.
Sourcepub const fn saturating_duration_since(self, earlier: Self) -> Duration
pub const fn saturating_duration_since(self, earlier: Self) -> Duration
How long after earlier this instant is, or zero when it is not after it.
Sourcepub fn parse(s: &str) -> Result<Self, InvalidTimestamp>
pub fn parse(s: &str) -> Result<Self, InvalidTimestamp>
Parse an RFC 3339 date-time.
Trait Implementations§
impl Copy for Timestamp
Source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Timestamp
Source§impl From<OffsetDateTime> for Timestamp
Available on crate feature time only.
impl From<OffsetDateTime> for Timestamp
time only.Source§fn from(t: OffsetDateTime) -> Self
fn from(t: OffsetDateTime) -> Self
Source§impl JsonSchema for Timestamp
Available on crate feature schemars only.
impl JsonSchema for Timestamp
schemars only.Source§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for Timestamp
impl Ord for Timestamp
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
impl StructuralPartialEq for Timestamp
Source§impl TryFrom<Timestamp> for OffsetDateTime
Available on crate feature time only.
impl TryFrom<Timestamp> for OffsetDateTime
time only.Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnsafeUnpin for Timestamp
impl UnwindSafe for Timestamp
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.