Struct hdk::prelude::Timestamp [−][src]
A UTC timestamp for use in Holochain’s headers. 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
Timestamp implements Serialize
and Display
as rfc3339 time strings (if possible).
- Field 0: i64 - Seconds since UNIX epoch UTC (midnight 1970-01-01).
- Field 1: u32 - Nanoseconds in addition to above seconds, always in positive direction.
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.
Create a new Timestamp instance from the supplied secs/nsecs. Note that we can easily create a
Timestamp that cannot be converted to a valid DateTime
Implementations
impl Timestamp
[src]
pub fn normalize(secs: i64, nanos: i64) -> Option<Timestamp>
[src]
Construct a normalized Timestamp from the given secs/nanos. Allows a full, signed range of
seconds and/or nanoseconds; produces a Timestamp with a properly signed i64 seconds, and an
always positive-offset u32 nanoseconds. Differs from typical new
implementation in that
it returns an Option
use holochain_zome_types::prelude::*; assert_eq!( Timestamp::normalize( 0, -1 ).unwrap(), Timestamp( -1, 999_999_999 ))
pub fn checked_difference_signed(&self, rhs: &Timestamp) -> Option<Duration>
[src]
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
milliseconds (the full range of a signed chrono::Duration). Note that, surprisingly, there
is almost no way to create a chrono::Duration that does not (directly or indirectly) have
the possibility of panic! One of the few paths is Duration::milliseconds() and smaller (all
larger use Duration::seconds, which may directly panic!), followed by a
Duration::checked_add for the nanoseconds.
pub fn checked_add_signed(&self, rhs: &Duration) -> Option<Timestamp>
[src]
Add a signed chrono::Duration{ secs: i64, nanos: i32 } (-’ve nanos are invalid) to a Timestamp( i64, u32 ). May overflow. Unfortunately, there is no way in the provided API to actually obtain the raw { secs, nanos }, nor their component parts without overflow! The closest is to obtain the millis, subtract them out and obtain the residual nanoseconds…
use holochain_zome_types::prelude::*; assert_eq!( Timestamp::normalize( 0, 1 ).unwrap() .checked_sub_signed(&chrono::Duration::nanoseconds(2)), Some(Timestamp( -1, 999_999_999 ))); //assert_eq!((Timestamp::normalize( 0, 1 ).unwrap() // - chrono::Duration::nanoseconds(2)), // Some(Timestamp( -1, 999_999_999 )));
pub fn checked_sub_signed(&self, rhs: &Duration) -> Option<Timestamp>
[src]
Subtracts a chrono::Duration from a Timestamp
pub fn checked_add(&self, rhs: &Duration) -> Option<Timestamp>
[src]
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
use holochain_zome_types::prelude::*; assert_eq!( Timestamp::normalize( 0, -3 ).unwrap() .checked_add(&core::time::Duration::from_nanos(2)), Some(Timestamp( -1, 999_999_999 ))); assert_eq!( Timestamp::normalize( 0, 0 ).unwrap() .checked_add(&core::time::Duration::from_secs(2_u64.pow(32)-1)), Some(Timestamp( 2_i64.pow(32)-1, 0 ))); assert_eq!( Timestamp::normalize( 0, 0 ).unwrap() .checked_add(&core::time::Duration::from_secs(2_u64.pow(63)-1)), Some(Timestamp( (2_u64.pow(63)-1) as i64, 0 ))); assert_eq!( Timestamp::normalize( 0, 0 ).unwrap() .checked_add(&core::time::Duration::from_secs(2_u64.pow(63))), None);
pub fn checked_sub(&self, rhs: &Duration) -> Option<Timestamp>
[src]
Sub unsigned core::time::Duration{ secs: u64, nanos: u32 } from a Timestamp.
use holochain_zome_types::prelude::*; assert_eq!( Timestamp::normalize( 0, 1 ).unwrap() .checked_sub(&core::time::Duration::from_nanos(2)), Some(Timestamp( -1, 999_999_999 ))); assert_eq!((Timestamp::normalize( 0, 1 ).unwrap() - core::time::Duration::from_nanos(2)), Ok(Timestamp( -1, 999_999_999 ))); assert_eq!( Timestamp::normalize( 550, 5_500_000_000 ).unwrap() .checked_sub(&core::time::Duration::from_nanos(2)), Some(Timestamp( 555, 499_999_998 )));
Trait Implementations
impl<'_, D> Add<D> for &'_ Timestamp where
D: Into<Duration>,
[src]
D: Into<Duration>,
type Output = Result<Timestamp, TimestampError>
The resulting type after applying the +
operator.
pub fn add(self, rhs: D) -> <&'_ Timestamp as Add<D>>::Output
[src]
impl<D> Add<D> for Timestamp where
D: Into<Duration>,
[src]
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.
pub fn add(self, rhs: D) -> <Timestamp as Add<D>>::Output
[src]
impl Clone for Timestamp
[src]
impl Copy for Timestamp
[src]
impl Debug for Timestamp
[src]
impl<'de> Deserialize<'de> for Timestamp
[src]
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
impl Display for Timestamp
[src]
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 Eq for Timestamp
[src]
impl<'_> From<&'_ DateTime<Utc>> for Timestamp
[src]
impl From<DateTime<Utc>> for Timestamp
[src]
impl From<i32> for Timestamp
[src]
impl From<i64> for Timestamp
[src]
Infallible conversions into a Timestamp. The only infallible ways to create a Timestamp are
from
a Unix timestamp, or normalize
with a timestamp and nanoseconds, or converting from
a DateTime
impl From<u32> for Timestamp
[src]
impl FromStr for Timestamp
[src]
type Err = TimestampError
The associated error which can be returned from parsing.
pub fn from_str(t: &str) -> Result<Timestamp, <Timestamp as FromStr>::Err>
[src]
impl Hash for Timestamp
[src]
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Timestamp
[src]
pub fn cmp(&self, other: &Timestamp) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Timestamp> for Timestamp
[src]
impl PartialOrd<Timestamp> for Timestamp
[src]
pub fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for Timestamp
[src]
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
impl StructuralEq for Timestamp
[src]
impl StructuralPartialEq for Timestamp
[src]
impl<D> Sub<D> for Timestamp where
D: Into<Duration>,
[src]
D: Into<Duration>,
Timestamp - core::time::Duration.
type Output = Result<Timestamp, TimestampError>
The resulting type after applying the -
operator.
pub fn sub(self, rhs: D) -> <Timestamp as Sub<D>>::Output
[src]
impl<'_, D> Sub<D> for &'_ Timestamp where
D: Into<Duration>,
[src]
D: Into<Duration>,
type Output = Result<Timestamp, TimestampError>
The resulting type after applying the -
operator.
pub fn sub(self, rhs: D) -> <&'_ Timestamp as Sub<D>>::Output
[src]
impl Sub<Timestamp> for Timestamp
[src]
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 milliseconds.
type Output = Result<Duration, TimestampError>
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Timestamp) -> <Timestamp as Sub<Timestamp>>::Output
[src]
impl<'_> TryFrom<&'_ String> for Timestamp
[src]
type Error = TimestampError
The type returned in the event of a conversion error.
pub fn try_from(
t: &String
) -> Result<Timestamp, <Timestamp as TryFrom<&'_ String>>::Error>
[src]
t: &String
) -> Result<Timestamp, <Timestamp as TryFrom<&'_ String>>::Error>
impl<'_> TryFrom<&'_ Timestamp> for SerializedBytes
[src]
type Error = SerializedBytesError
The type returned in the event of a conversion error.
pub fn try_from(t: &Timestamp) -> Result<SerializedBytes, SerializedBytesError>
[src]
impl<'_> TryFrom<&'_ Timestamp> for DateTime<Utc>
[src]
type Error = TimestampError
The type returned in the event of a conversion error.
pub fn try_from(
t: &Timestamp
) -> Result<DateTime<Utc>, <DateTime<Utc> as TryFrom<&'_ Timestamp>>::Error>
[src]
t: &Timestamp
) -> Result<DateTime<Utc>, <DateTime<Utc> as TryFrom<&'_ Timestamp>>::Error>
impl<'_> TryFrom<&'_ str> for Timestamp
[src]
type Error = TimestampError
The type returned in the event of a conversion error.
pub fn try_from(
t: &str
) -> Result<Timestamp, <Timestamp as TryFrom<&'_ str>>::Error>
[src]
t: &str
) -> Result<Timestamp, <Timestamp as TryFrom<&'_ str>>::Error>
impl TryFrom<SerializedBytes> for Timestamp
[src]
type Error = SerializedBytesError
The type returned in the event of a conversion error.
pub fn try_from(sb: SerializedBytes) -> Result<Timestamp, SerializedBytesError>
[src]
impl TryFrom<String> for Timestamp
[src]
type Error = TimestampError
The type returned in the event of a conversion error.
pub fn try_from(
t: String
) -> Result<Timestamp, <Timestamp as TryFrom<String>>::Error>
[src]
t: String
) -> Result<Timestamp, <Timestamp as TryFrom<String>>::Error>
impl TryFrom<Timestamp> for SerializedBytes
[src]
type Error = SerializedBytesError
The type returned in the event of a conversion error.
pub fn try_from(t: Timestamp) -> Result<SerializedBytes, SerializedBytesError>
[src]
impl TryFrom<Timestamp> for DateTime<Utc>
[src]
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 T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
pub fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,