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<Utc> (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§

source§

impl Timestamp

source

pub fn now() -> Timestamp

Returns the current system time as a Timestamp.

This is behind a feature because we need Timestamp to be WASM compatible, and chrono doesn’t have a now() implementation for WASM.

source

pub fn checked_difference_signed(&self, rhs: &Timestamp) -> Option<TimeDelta>

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.

source

pub fn checked_add_signed(&self, rhs: &TimeDelta) -> Option<Timestamp>

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

source

pub fn checked_sub_signed(&self, rhs: &TimeDelta) -> Option<Timestamp>

Subtracts a chrono::Duration from a Timestamp

source§

impl Timestamp

source

pub const ZERO: Timestamp = _

The Timestamp corresponding to the UNIX epoch

source

pub const MIN: Timestamp = _

The smallest possible Timestamp

source

pub const MAX: Timestamp = _

The largest possible Timestamp

source

pub const HOLOCHAIN_EPOCH: Timestamp = _

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

source

pub fn max() -> Timestamp

Largest possible Timestamp.

source

pub fn from_micros(micros: i64) -> Timestamp

Construct from microseconds

source

pub fn as_micros(&self) -> i64

Access time as microseconds since UNIX epoch

source

pub fn as_millis(&self) -> i64

Access time as milliseconds since UNIX epoch

source

pub fn as_seconds_and_nanos(&self) -> (i64, u32)

Access seconds since UNIX epoch plus nanosecond offset

source

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

source

pub fn checked_sub(&self, rhs: &Duration) -> Option<Timestamp>

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

source

pub fn saturating_add(&self, rhs: &Duration) -> Timestamp

Add a duration, clamping to MAX if overflow

source

pub fn saturating_sub(&self, rhs: &Duration) -> Timestamp

Subtract a duration, clamping to MIN if overflow

source

pub fn saturating_from_dur(duration: &Duration) -> Timestamp

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

Trait Implementations§

source§

impl<D> Add<D> for &Timestamp
where D: Into<Duration>,

§

type Output = Result<Timestamp, TimestampError>

The resulting type after applying the + operator.
source§

fn add(self, rhs: D) -> <&Timestamp as Add<D>>::Output

Performs the + operation. Read more
source§

impl<D> Add<D> for Timestamp
where D: Into<Duration>,

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

§

type Output = Result<Timestamp, TimestampError>

The resulting type after applying the + operator.
source§

fn add(self, rhs: D) -> <Timestamp as Add<D>>::Output

Performs the + operation. Read more
source§

impl Clone for Timestamp

source§

fn clone(&self) -> Timestamp

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Timestamp

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Timestamp

source§

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
source§

impl Display for Timestamp

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<&DateTime<Utc>> for Timestamp

source§

fn from(t: &DateTime<Utc>) -> Timestamp

Converts to this type from the input type.
source§

impl From<&HumanTimestamp> for Timestamp

source§

fn from(h: &HumanTimestamp) -> Timestamp

Converts to this type from the input type.
source§

impl From<DateTime<Utc>> for Timestamp

source§

fn from(t: DateTime<Utc>) -> Timestamp

Converts to this type from the input type.
source§

impl From<HumanTimestamp> for Timestamp

source§

fn from(h: HumanTimestamp) -> Timestamp

Converts to this type from the input type.
source§

impl From<Timestamp> for HumanTimestamp

source§

fn from(t: Timestamp) -> HumanTimestamp

Converts to this type from the input type.
source§

impl FromStr for Timestamp

§

type Err = TimestampError

The associated error which can be returned from parsing.
source§

fn from_str(t: &str) -> Result<Timestamp, <Timestamp as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Timestamp

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Timestamp

source§

fn cmp(&self, other: &Timestamp) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Timestamp

source§

fn eq(&self, other: &Timestamp) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Timestamp

source§

fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Timestamp

source§

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
source§

impl<D> Sub<D> for &Timestamp
where D: Into<Duration>,

§

type Output = Result<Timestamp, TimestampError>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: D) -> <&Timestamp as Sub<D>>::Output

Performs the - operation. Read more
source§

impl<D> Sub<D> for Timestamp
where D: Into<Duration>,

Timestamp - core::time::Duration.

§

type Output = Result<Timestamp, TimestampError>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: D) -> <Timestamp as Sub<D>>::Output

Performs the - operation. Read more
source§

impl Sub for Timestamp

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.

§

type Output = Result<TimeDelta, TimestampError>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Timestamp) -> <Timestamp as Sub>::Output

Performs the - operation. Read more
source§

impl TryFrom<&String> for Timestamp

§

type Error = TimestampError

The type returned in the event of a conversion error.
source§

fn try_from( t: &String ) -> Result<Timestamp, <Timestamp as TryFrom<&String>>::Error>

Performs the conversion.
source§

impl TryFrom<&Timestamp> for DateTime<Utc>

§

type Error = TimestampError

The type returned in the event of a conversion error.
source§

fn try_from( t: &Timestamp ) -> Result<DateTime<Utc>, <DateTime<Utc> as TryFrom<&Timestamp>>::Error>

Performs the conversion.
source§

impl TryFrom<&str> for Timestamp

§

type Error = TimestampError

The type returned in the event of a conversion error.
source§

fn try_from(t: &str) -> Result<Timestamp, <Timestamp as TryFrom<&str>>::Error>

Performs the conversion.
source§

impl TryFrom<Duration> for Timestamp

§

type Error = TimestampError

The type returned in the event of a conversion error.
source§

fn try_from( value: Duration ) -> Result<Timestamp, <Timestamp as TryFrom<Duration>>::Error>

Performs the conversion.
source§

impl TryFrom<String> for Timestamp

§

type Error = TimestampError

The type returned in the event of a conversion error.
source§

fn try_from( t: String ) -> Result<Timestamp, <Timestamp as TryFrom<String>>::Error>

Performs the conversion.
source§

impl TryFrom<Timestamp> for DateTime<Utc>

§

type Error = TimestampError

The type returned in the event of a conversion error.
source§

fn try_from( t: Timestamp ) -> Result<DateTime<Utc>, <DateTime<Utc> as TryFrom<Timestamp>>::Error>

Performs the conversion.
source§

impl Copy for Timestamp

source§

impl Eq for Timestamp

source§

impl StructuralPartialEq for Timestamp

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CallHasher for T
where T: Hash + ?Sized,

source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> LayoutRaw for T

source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> Scalar for T
where T: Copy + PartialEq + Debug + Any,

source§

fn inlined_clone(&self) -> T

Performance hack: Clone doesn’t get inlined for Copy types in debug mode, so make it inline anyway.
source§

fn is<T>() -> bool
where T: Scalar,

Tests if Self the same as the type T Read more
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcastable for T
where T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,