Struct hdk::prelude::Timestamp

pub struct Timestamp(pub i64);
Expand description

A microsecond-precision UTC timestamp for use in Holochain’s actions.

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 (which limits itself to a +/- i32 offset in days from Jan 1, 0AD and from 1970AD).

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

Tuple Fields

0: i64

Microseconds from UNIX Epoch, positive or negative

Implementations

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.

Add a signed chrono::Duration{ secs: i64, nanos: i32 } to a Timestamp.

Subtracts a chrono::Duration from a Timestamp

The Timestamp corresponding to the UNIX epoch

The smallest possible Timestamp

The largest possible Timestamp

Jan 1, 2022, 12:00:00 AM UTC

Largest possible Timestamp.

Construct from microseconds

Access time as microseconds since UNIX epoch

Access time as milliseconds since UNIX epoch

Access seconds since UNIX epoch plus nanosecond offset

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

Sub unsigned core::time::Duration{ secs: u64, nanos: u32 } from a Timestamp.

Add a duration, clamping to MAX if overflow

Subtract a duration, clamping to MIN if overflow

Create a Timestamp from a core::time::Duration saturating at i64::MAX.

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

The resulting type after applying the + operator.
Performs the + operation. Read more

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

The resulting type after applying the + operator.
Performs the + operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
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).

Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more

Timestamp - core::time::Duration.

The resulting type after applying the - operator.
Performs the - operation. Read more

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.

The resulting type after applying the - operator.
Performs the - operation. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type for metadata in pointers and references to Self.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
upcast ref
upcast mut ref
upcast boxed dyn
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