Struct holochain_types::prelude::timestamp::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
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
impl Timestamp
impl Timestamp
pub fn now() -> Timestamp
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.
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
impl Timestamp
impl Timestamp
pub const HOLOCHAIN_EPOCH: Timestamp = Timestamp(1640995200000000)
pub const HOLOCHAIN_EPOCH: Timestamp = Timestamp(1640995200000000)
Jan 1, 2022, 12:00:00 AM UTC
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_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 saturating_from_dur(duration: &Duration) -> Timestamp
pub fn saturating_from_dur(duration: &Duration) -> Timestamp
Create a Timestamp
from a core::time::Duration
saturating at i64::MAX.
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
impl<D> Add<D> for Timestampwhere
D: Into<Duration>,
impl<D> Add<D> for Timestampwhere
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
impl<'arbitrary> Arbitrary<'arbitrary> for Timestamp
impl<'arbitrary> Arbitrary<'arbitrary> for Timestamp
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Timestamp, Error>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Timestamp, Error>
Self
from the given unstructured data. Read morefn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Timestamp, Error>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Timestamp, Error>
Self
from the entirety of the given
unstructured data. Read moreimpl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
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).
impl From<&HumanTimestamp> for Timestamp
impl From<&HumanTimestamp> for Timestamp
fn from(h: &HumanTimestamp) -> Timestamp
fn from(h: &HumanTimestamp) -> Timestamp
impl From<HumanTimestamp> for Timestamp
impl From<HumanTimestamp> for Timestamp
fn from(h: HumanTimestamp) -> Timestamp
fn from(h: HumanTimestamp) -> Timestamp
impl From<Timestamp> for HumanTimestamp
impl From<Timestamp> for HumanTimestamp
fn from(t: Timestamp) -> HumanTimestamp
fn from(t: Timestamp) -> HumanTimestamp
impl FromSql for Timestamp
impl FromSql for Timestamp
fn column_result(value: ValueRef<'_>) -> Result<Timestamp, FromSqlError>
fn column_result(value: ValueRef<'_>) -> Result<Timestamp, FromSqlError>
impl Ord for Timestamp
impl Ord for Timestamp
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
impl PartialOrd<Timestamp> for Timestamp
impl PartialOrd<Timestamp> for Timestamp
fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Serialize for Timestamp
impl Serialize for Timestamp
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Sub<Timestamp> for Timestamp
impl Sub<Timestamp> 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.
impl ToSql for Timestamp
impl ToSql for Timestamp
fn to_sql(&self) -> Result<ToSqlOutput<'_>, Error>
fn to_sql(&self) -> Result<ToSqlOutput<'_>, Error>
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralEq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations
impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.impl<T> FutureExt for T
impl<T> FutureExt for T
fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read morefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.