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
impl Timestamp
sourcepub 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.
sourcepub 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.
sourcepub 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
source§impl Timestamp
impl Timestamp
sourcepub const HOLOCHAIN_EPOCH: Timestamp = _
pub const HOLOCHAIN_EPOCH: Timestamp = _
Jan 1, 2022, 12:00:00 AM UTC
sourcepub fn from_micros(micros: i64) -> Self
pub fn from_micros(micros: i64) -> Self
Construct from microseconds
sourcepub 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
sourcepub 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
sourcepub 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.
sourcepub fn saturating_add(&self, rhs: &Duration) -> Timestamp
pub fn saturating_add(&self, rhs: &Duration) -> Timestamp
Add a duration, clamping to MAX if overflow
sourcepub fn saturating_sub(&self, rhs: &Duration) -> Timestamp
pub fn saturating_sub(&self, rhs: &Duration) -> Timestamp
Subtract a duration, clamping to MIN if overflow
sourcepub fn saturating_from_dur(duration: &Duration) -> Self
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
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
source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for Timestamp
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§impl From<&HumanTimestamp> for Timestamp
impl From<&HumanTimestamp> for Timestamp
source§fn from(h: &HumanTimestamp) -> Self
fn from(h: &HumanTimestamp) -> Self
source§impl From<HumanTimestamp> for Timestamp
impl From<HumanTimestamp> for Timestamp
source§fn from(h: HumanTimestamp) -> Self
fn from(h: HumanTimestamp) -> Self
source§impl From<Timestamp> for HumanTimestamp
impl From<Timestamp> for HumanTimestamp
source§impl Ord for Timestamp
impl Ord for Timestamp
source§impl PartialEq for Timestamp
impl PartialEq for Timestamp
source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Sub for Timestamp
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.