pub struct Timestamp(/* private fields */);
Expand description
A Unix timestamp with nanosecond precision.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn from_unix(unix_time: Duration) -> Option<Self>
pub fn from_unix(unix_time: Duration) -> Option<Self>
Try create a timestamp from time since the Unix epoch.
If the unix_time
is within Timestamp::MIN
..=Timestamp::MAX
then this method will return Some
. Otherwise it will return None
.
Sourcepub fn try_from_str(ts: &str) -> Result<Self, ParseTimestampError>
pub fn try_from_str(ts: &str) -> Result<Self, ParseTimestampError>
Try parse a timestamp from an RFC3339 formatted representation.
Sourcepub fn parse(ts: impl Display) -> Result<Self, ParseTimestampError>
pub fn parse(ts: impl Display) -> Result<Self, ParseTimestampError>
Try parse a timestamp from an RFC3339 formatted value.
Sourcepub fn duration_since(self, earlier: Self) -> Option<Duration>
pub fn duration_since(self, earlier: Self) -> Option<Duration>
Calculate the timespan between two timestamps.
This method will return None
if earlier
is actually after self
.
Sourcepub fn to_system_time(&self) -> SystemTime
pub fn to_system_time(&self) -> SystemTime
Convert the timestamp into a system timestamp.
This method can be used for interoperability with code expecting a standard library timestamp.
Sourcepub fn from_parts(parts: Parts) -> Option<Self>
pub fn from_parts(parts: Parts) -> Option<Self>
Try get a timestamp from its individual date and time parts.
If the resulting timestamp is within Timestamp::MIN
..=Timestamp::MAX
then this method will return Some
. Otherwise it will return None
.
If any field of parts
would overflow its maximum value, such as days: 32
, then it will wrap into the next unit.
Sourcepub fn to_parts(&self) -> Parts
pub fn to_parts(&self) -> Parts
Get the individual date and time parts of the timestamp.
The returned parts are in exactly the form needed to display them. Months and days are both one-based.
Sourcepub fn checked_add(&self, rhs: Duration) -> Option<Self>
pub fn checked_add(&self, rhs: Duration) -> Option<Self>
Add a duration to this timestamp.
If the result would be greater than Timestamp::MAX
then None
is returned.
Sourcepub fn checked_sub(&self, rhs: Duration) -> Option<Self>
pub fn checked_sub(&self, rhs: Duration) -> Option<Self>
Subtract a duration to this timestamp.
If the result would be less than Timestamp::MIN
then None
is returned.
Sourcepub fn checked_duration_since(&self, earlier: Timestamp) -> Option<Duration>
pub fn checked_duration_since(&self, earlier: Timestamp) -> Option<Duration>
Get the duration between this timestamp and an earlier one.
Trait Implementations§
Source§impl AddAssign<Duration> for Timestamp
impl AddAssign<Duration> for Timestamp
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moreSource§impl<'v> FromValue<'v> for Timestamp
impl<'v> FromValue<'v> for Timestamp
Source§fn from_value(value: Value<'v>) -> Option<Self>
fn from_value(value: Value<'v>) -> Option<Self>
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl SubAssign<Duration> for Timestamp
impl SubAssign<Duration> for Timestamp
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moreSource§impl Value for Timestamp
impl Value for Timestamp
Source§fn stream<'sval, S: Stream<'sval> + ?Sized>(
&'sval self,
stream: &mut S,
) -> Result
fn stream<'sval, S: Stream<'sval> + ?Sized>( &'sval self, stream: &mut S, ) -> Result
Stream
.