pub struct TimestampMs(/* private fields */);Expand description
A timestamp in milliseconds since the UNIX epoch (January 1, 1970). Serialized as a non-negative integer.
Implementations§
Source§impl TimestampMs
impl TimestampMs
pub const MIN: Self
pub const MAX: Self
Sourcepub fn now() -> Self
pub fn now() -> Self
Creates a new TimestampMs from the current SystemTime.
Panics if the current time is not within bounds.
Sourcepub fn from_secs(secs: u64) -> Result<Self, Error>
pub fn from_secs(secs: u64) -> Result<Self, Error>
Construct TimestampMs from seconds since Unix epoch.
Sourcepub fn from_secs_u32(secs: u32) -> Self
pub fn from_secs_u32(secs: u32) -> Self
Infallibly construct TimestampMs from seconds since Unix epoch.
Sourcepub fn from_millis(millis: u64) -> Result<Self, Error>
pub fn from_millis(millis: u64) -> Result<Self, Error>
Construct TimestampMs from milliseconds since Unix epoch.
Sourcepub fn from_duration(dur_since_epoch: Duration) -> Result<Self, Error>
pub fn from_duration(dur_since_epoch: Duration) -> Result<Self, Error>
Construct TimestampMs from Duration since Unix epoch.
Sourcepub fn from_system_time(system_time: SystemTime) -> Result<Self, Error>
pub fn from_system_time(system_time: SystemTime) -> Result<Self, Error>
Construct TimestampMs from a SystemTime.
Sourcepub fn to_millis(self) -> u64
pub fn to_millis(self) -> u64
Get this unix timestamp as a u64 in milliseconds from unix epoch.
Sourcepub fn to_duration(self) -> Duration
pub fn to_duration(self) -> Duration
Get this unix timestamp as a Duration from the unix epoch.
Sourcepub fn to_system_time(self) -> SystemTime
pub fn to_system_time(self) -> SystemTime
Get this unix timestamp as a SystemTime.
pub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn saturating_add(self, duration: Duration) -> Self
pub fn saturating_sub(self, duration: Duration) -> Self
Sourcepub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
pub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
Sourcepub fn saturating_duration_since(self, earlier: Self) -> Duration
pub fn saturating_duration_since(self, earlier: Self) -> Duration
Returns the Duration elapsed from earlier to self,
saturating to Duration::ZERO if earlier is later than self.
Sourcepub fn checked_elapsed(self) -> Option<Duration>
pub fn checked_elapsed(self) -> Option<Duration>
Sourcepub fn saturating_elapsed(self) -> Duration
pub fn saturating_elapsed(self) -> Duration
Returns the Duration elapsed since this timestamp,
saturating to Duration::ZERO if it is in the future.
Sourcepub fn to_relative_string(self, now: Self) -> String
pub fn to_relative_string(self, now: Self) -> String
Formats this timestamp into a human-readable string relative to now,
e.g. “just now”, “5 minutes ago”, “in 3 hours”,
“in 2 years and 5 weeks”.
Picks the largest whole unit that fits; weeks and years also carry the remainder in the next unit down. Sub-second differences in either direction read as “just now”.
Trait Implementations§
Source§impl Clone for TimestampMs
impl Clone for TimestampMs
impl Copy for TimestampMs
Source§impl Debug for TimestampMs
impl Debug for TimestampMs
Source§impl<'de> Deserialize<'de> for TimestampMs
impl<'de> Deserialize<'de> for TimestampMs
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for TimestampMs
impl Display for TimestampMs
impl Eq for TimestampMs
Source§impl From<TimestampMs> for Duration
impl From<TimestampMs> for Duration
Source§fn from(t: TimestampMs) -> Self
fn from(t: TimestampMs) -> Self
Source§impl From<TimestampMs> for SystemTime
impl From<TimestampMs> for SystemTime
Source§fn from(t: TimestampMs) -> Self
fn from(t: TimestampMs) -> Self
Source§impl FromStr for TimestampMs
impl FromStr for TimestampMs
Source§impl Hash for TimestampMs
impl Hash for TimestampMs
Source§impl Ord for TimestampMs
impl Ord for TimestampMs
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TimestampMs
impl PartialEq for TimestampMs
Source§impl PartialOrd for TimestampMs
impl PartialOrd for TimestampMs
Source§impl Serialize for TimestampMs
impl Serialize for TimestampMs
impl StructuralPartialEq for TimestampMs
Source§impl TryFrom<Duration> for TimestampMs
Attempts to convert a Duration since the UNIX epoch into a
TimestampMs.
impl TryFrom<Duration> for TimestampMs
Attempts to convert a Duration since the UNIX epoch into a
TimestampMs.
Returns an error if the Duration is too large.
Source§impl TryFrom<SystemTime> for TimestampMs
Attempts to convert a SystemTime into a TimestampMs.
impl TryFrom<SystemTime> for TimestampMs
Attempts to convert a SystemTime into a TimestampMs.
Returns an error if the SystemTime is not within bounds.