pub struct Timestamp(/* private fields */);Expand description
A point in time (UTC), the canonical instant type.
Serializes as a millisecond-precision RFC 3339 string with a Z UTC
designator (e.g. 2023-11-14T22:13:20.000Z).
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn now() -> Timestamp
pub fn now() -> Timestamp
The current instant from the system clock.
Prefer a Clock in code that should be testable; this is for the edges
(e.g. constructing the SystemClock itself).
Sourcepub fn from_offset_datetime(dt: OffsetDateTime) -> Timestamp
pub fn from_offset_datetime(dt: OffsetDateTime) -> Timestamp
Wrap a time::OffsetDateTime, normalising it to UTC.
Sourcepub const fn as_offset_datetime(&self) -> &OffsetDateTime
pub const fn as_offset_datetime(&self) -> &OffsetDateTime
The underlying time::OffsetDateTime (always UTC).
Sourcepub const fn into_offset_datetime(self) -> OffsetDateTime
pub const fn into_offset_datetime(self) -> OffsetDateTime
Consume into the underlying time::OffsetDateTime (always UTC).
Sourcepub fn from_unix_millis_opt(millis: i64) -> Option<Timestamp>
pub fn from_unix_millis_opt(millis: i64) -> Option<Timestamp>
Construct from milliseconds since the Unix epoch, or None if millis
falls outside the representable range (roughly years ±9999).
Prefer this over from_unix_millis when
millis is untrusted or computed and an out-of-range value should be
treated as an error rather than silently clamped.
Sourcepub fn from_unix_millis(millis: i64) -> Timestamp
pub fn from_unix_millis(millis: i64) -> Timestamp
Construct from milliseconds since the Unix epoch.
Saturating: a millis value outside the representable range is
clamped to the earliest or latest representable instant, preserving
order — a far-future overflow stays in the far future and a far-past
underflow stays in the far past; neither collapses to “now”. Use
from_unix_millis_opt to detect
out-of-range input instead of saturating.
Sourcepub fn from_unix_seconds_opt(secs: i64) -> Option<Timestamp>
pub fn from_unix_seconds_opt(secs: i64) -> Option<Timestamp>
Construct from seconds since the Unix epoch, or None if secs falls
outside the representable range.
Sourcepub fn from_unix_seconds(secs: i64) -> Timestamp
pub fn from_unix_seconds(secs: i64) -> Timestamp
Construct from seconds since the Unix epoch, saturating on out-of-range
input (see from_unix_millis).
Sourcepub fn unix_millis(&self) -> i64
pub fn unix_millis(&self) -> i64
Milliseconds since the Unix epoch.
Sourcepub fn unix_seconds(&self) -> i64
pub fn unix_seconds(&self) -> i64
Whole seconds since the Unix epoch.
Sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
RFC 3339 / ISO 8601 representation (millisecond precision, Z suffix).
Sourcepub fn parse_rfc3339(s: &str) -> Option<Timestamp>
pub fn parse_rfc3339(s: &str) -> Option<Timestamp>
Parse an RFC 3339 / ISO 8601 timestamp (e.g. from to_rfc3339), or
None if it is malformed. The inverse of to_rfc3339.
Sourcepub fn duration_since(&self, earlier: Timestamp) -> Duration
pub fn duration_since(&self, earlier: Timestamp) -> Duration
The signed duration elapsed since earlier (negative if earlier is later).
Sourcepub fn checked_add(&self, delta: Duration) -> Option<Timestamp>
pub fn checked_add(&self, delta: Duration) -> Option<Timestamp>
This instant shifted by delta, or None on over/underflow.