Struct concordium_contracts_common::Timestamp
source · #[repr(transparent)]pub struct Timestamp {
pub millis: u64,
}
Expand description
Timestamp represented as milliseconds since unix epoch.
Timestamps from before January 1st 1970 at 00:00 are not supported.
Fields§
§millis: u64
Milliseconds since unix epoch.
Implementations§
source§impl Timestamp
impl Timestamp
sourcepub const fn from_timestamp_millis(millis: u64) -> Self
pub const fn from_timestamp_millis(millis: u64) -> Self
Construct timestamp from milliseconds since unix epoch.
sourcepub const fn timestamp_millis(&self) -> u64
pub const fn timestamp_millis(&self) -> u64
Milliseconds since the UNIX epoch.
sourcepub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_add(self, duration: Duration) -> Option<Self>
Add duration to the timestamp. Returns None
if the resulting timestamp
is not representable, i.e., too far in the future.
sourcepub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
Subtract duration from the timestamp. Returns None
instead of
overflowing if the resulting timestamp would be before the Unix
epoch.
sourcepub fn duration_between(self, other: Timestamp) -> Duration
pub fn duration_between(self, other: Timestamp) -> Duration
Compute the duration between the self and another timestamp. The duration is always positive, and is the difference between the the more recent timestamp and the one further in the past.
sourcepub fn duration_since(self, before: Timestamp) -> Option<Duration>
pub fn duration_since(self, before: Timestamp) -> Option<Duration>
Compute duration since a given timestamp. Returns None
if given time
is in the future compared to self.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Deserialize from a string via the RFC3339 format.
source§fn deserialize<D: Deserializer<'de>>(des: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(des: D) -> Result<Self, D::Error>
source§impl Display for Timestamp
impl Display for Timestamp
This display implementation attempts to format the timestamp as per
the RFC3339 standard, using the UTC time zone.
If parsing the timestamp into a chrono::DateTime<Utc>
fails, it
simply returns the timestamp in milliseconds as a string.
source§impl FromStr for Timestamp
impl FromStr for Timestamp
The FromStr parses a string representing either an u64
of milliseconds
or the time according to RFC3339.
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 Serialize for Timestamp
impl Serialize for Timestamp
The JSON serialization serialized the string obtained by using the Display implementation of the Timestamp.
source§impl TryFrom<DateTime<Utc>> for Timestamp
impl TryFrom<DateTime<Utc>> for Timestamp
Note that this is a lossy conversion from a datetime to a Timestamp
.
Any precision above milliseconds is lost.