Struct kitsune_p2p_timestamp::Timestamp

source ·
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 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.

source

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

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

source

pub fn checked_sub_signed(&self, rhs: &Duration) -> 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) -> Self

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

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

Trait Implementations§

source§

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

§

type Output = Result<Timestamp, TimestampError>

The resulting type after applying the + operator.
source§

fn add(self, rhs: D) -> Self::Output

Performs the + operation. Read more
source§

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

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) -> Self::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

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

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

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::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

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

impl From<&DateTime<Utc>> for Timestamp

source§

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

Converts to this type from the input type.
source§

impl From<&HumanTimestamp> for Timestamp

source§

fn from(h: &HumanTimestamp) -> Self

Converts to this type from the input type.
source§

impl From<DateTime<Utc>> for Timestamp

source§

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

Converts to this type from the input type.
source§

impl From<HumanTimestamp> for Timestamp

source§

fn from(h: HumanTimestamp) -> Self

Converts to this type from the input type.
source§

impl From<Timestamp> for HumanTimestamp

source§

fn from(t: Timestamp) -> Self

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<Self, Self::Err>

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

impl Hash for Timestamp

source§

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

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::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

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

§

type Output = Result<Timestamp, TimestampError>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: D) -> Self::Output

Performs the - operation. Read more
source§

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

Timestamp - core::time::Duration.

§

type Output = Result<Timestamp, TimestampError>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: D) -> Self::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) -> Self::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<Self, Self::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<Self, Self::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<Self, Self::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<Self, Self::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<Self, Self::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<Self, Self::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> 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,