Struct hdk::prelude::Timestamp [−]
pub struct Timestamp(_);
Expand description
A microsecond-precision UTC timestamp for use in Holochain’s headers.
It is assumed to be untrustworthy:
it may contain times offset from the UNIX epoch with the full +/- i64 range.
Most of these times are not representable by a chrono::DateTime
Also, most differences between two Timestamps are not representable by either a chrono::Duration (which limits itself to +/- i64 microseconds), nor by core::time::Duration (which limits itself to +’ve u64 seconds). Many constructions of these chrono and core::time types will panic!, so painful measures must be taken to avoid this outcome – it is not acceptable for our core Holochain algorithms to panic when accessing DHT Header information committed by other random Holochain nodes!
Timestamp implements Serialize
and Display
as rfc3339 time strings (if possible).
Supports +/- chrono::Duration directly. There is no Timestamp::now() method, since this is not supported by WASM; however, holochain_types provides a Timestamp::now() method.
Implementations
impl Timestamp
impl Timestamp
pub fn from_micros(micros: i64) -> Timestamp
pub fn from_micros(micros: i64) -> Timestamp
Construct from microseconds
pub fn as_seconds_and_nanos(&self) -> (i64, u32)
pub fn as_seconds_and_nanos(&self) -> (i64, u32)
Access seconds since UNIX epoch plus nanosecond offset
pub fn checked_difference_signed(&self, rhs: &Timestamp) -> Option<Duration>
pub fn checked_difference_signed(&self, rhs: &Timestamp) -> Option<Duration>
Compute signed difference between two Timestamp, returning None
if overflow occurred, or
Some(chrono::Duration). Produces Duration for differences of up to +/- i64::MIN/MAX
microseconds.
pub fn checked_add_signed(&self, rhs: &Duration) -> Option<Timestamp>
pub fn checked_add_signed(&self, rhs: &Duration) -> Option<Timestamp>
Add a signed chrono::Duration{ secs: i64, nanos: i32 } to a Timestamp.
pub fn checked_sub_signed(&self, rhs: &Duration) -> Option<Timestamp>
pub fn checked_sub_signed(&self, rhs: &Duration) -> Option<Timestamp>
Subtracts a chrono::Duration from a Timestamp
pub fn checked_add(&self, rhs: &Duration) -> Option<Timestamp>
pub fn checked_add(&self, rhs: &Duration) -> Option<Timestamp>
Add unsigned core::time::Duration{ secs: u64, nanos: u32 } to a Timestamp. See: https://doc.rust-lang.org/src/core/time.rs.html#53-56
pub fn checked_sub(&self, rhs: &Duration) -> Option<Timestamp>
pub fn checked_sub(&self, rhs: &Duration) -> Option<Timestamp>
Sub unsigned core::time::Duration{ secs: u64, nanos: u32 } from a Timestamp.
pub fn saturating_add(&self, rhs: &Duration) -> Timestamp
pub fn saturating_add(&self, rhs: &Duration) -> Timestamp
Add a duration, clamping to MAX if overflow
pub fn saturating_sub(&self, rhs: &Duration) -> Timestamp
pub fn saturating_sub(&self, rhs: &Duration) -> Timestamp
Subtract a duration, clamping to MIN if overflow
pub fn into_sql_lossy(self) -> Timestamp
pub fn into_sql_lossy(self) -> Timestamp
Convert this timestamp to fit into a SQLite integer which is an i64. The value will be clamped to the valid range supported by SQLite
Trait Implementations
Timestamp +/- Intocore::time::Duration: Anything that can be converted into a core::time::Duration can be used as an overflow-checked offset (unsigned) for a Timestamp. A core::time::Duration allows only +’ve offsets
impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Display as RFC3339 Date+Time for sane value ranges (0000-9999AD). Beyond that, format as (seconds, nanoseconds) tuple (output and parsing of large +/- years is unreliable).
impl PartialOrd<Timestamp> for Timestamp
impl PartialOrd<Timestamp> for Timestamp
pub fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Timestamp - core::time::Duration.
Distance between two Timestamps as a chrono::Duration (subject to overflow). A Timestamp represents a signed distance from the UNIX Epoch (1970-01-01T00:00:00Z). A chrono::Duration is limited to +/- i64::MIN/MAX microseconds.
impl StructuralEq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations
impl RefUnwindSafe for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more