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<Timestamp>
pub fn from_unix(unix_time: Duration) -> Option<Timestamp>
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<Timestamp, ParseTimestampError>
pub fn try_from_str(ts: &str) -> Result<Timestamp, ParseTimestampError>
Try parse a timestamp from an RFC3339 formatted representation.
Sourcepub fn parse(ts: impl Display) -> Result<Timestamp, ParseTimestampError>
pub fn parse(ts: impl Display) -> Result<Timestamp, ParseTimestampError>
Try parse a timestamp from an RFC3339 formatted value.
Sourcepub fn duration_since(self, earlier: Timestamp) -> Option<Duration>
pub fn duration_since(self, earlier: Timestamp) -> Option<Duration>
Calculate the timespan between two timestamps.
This method will return None if earlier is actually after self.
Sourcepub fn from_system_time(ts: SystemTime) -> Option<Timestamp>
pub fn from_system_time(ts: SystemTime) -> Option<Timestamp>
Convert a system timestamp into a timestamp.
If the ts is within Timestamp::MIN..=Timestamp::MAX then this method will return Some. Otherwise it will return None.
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<Timestamp>
pub fn from_parts(parts: Parts) -> Option<Timestamp>
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<Timestamp>
pub fn checked_add(&self, rhs: Duration) -> Option<Timestamp>
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<Timestamp>
pub fn checked_sub(&self, rhs: Duration) -> Option<Timestamp>
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 Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl Serialize for Timestamp
Available on crate feature serde only.
impl Serialize for Timestamp
serde only.Source§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,
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
Available on crate feature sval only.
impl Value for Timestamp
sval only.Source§fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
Stream.