pub struct Timestamp(/* private fields */);Expand description
A whole-second Unix timestamp used for access time and expiration.
Also used for object creation times. Values range from the Unix epoch through
9999-12-31T23:59:59Z. When constructed with fractional seconds, the timestamp rounds up to
the next whole second. Values outside this range are rejected.
Serializes in the same format as SystemTime, with secs_since_epoch and nanos_since_epoch
fields. The nanoseconds field is always zero when serialized. Deserialization accepts legacy
fractional timestamps and rounds them upward.
use std::time::Duration;
use objectstore_types::time::Timestamp;
let deadline = Timestamp::from_unix_micros(1_700_000_000_123_456)?;
assert_eq!(deadline.as_rfc3339().to_string(), "2023-11-14T22:13:21Z");
let extended = deadline + Duration::from_secs(60);
assert_eq!(extended.as_secs(), deadline.as_secs() + 60);Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
The Unix epoch.
Sourcepub fn now() -> Self
pub fn now() -> Self
Captures the current wall-clock time, rounded up to a whole second.
§Panics
Panics if the system clock is outside the supported timestamp range.
Sourcepub fn from_unix_secs(seconds: u64) -> Result<Self, InvalidTimestamp>
pub fn from_unix_secs(seconds: u64) -> Result<Self, InvalidTimestamp>
Constructs a timestamp from whole Unix seconds.
Sourcepub fn from_unix_micros(micros: i64) -> Result<Self, InvalidTimestamp>
pub fn from_unix_micros(micros: i64) -> Result<Self, InvalidTimestamp>
Constructs a timestamp from Unix microseconds, rounding fractional seconds upward.
Sourcepub fn from_rfc3339(value: &str) -> Result<Self, TimestampError>
pub fn from_rfc3339(value: &str) -> Result<Self, TimestampError>
Parses an RFC3339 timestamp, rounding fractional seconds upward.
Returns an error if the input is invalid or outside the supported timestamp range.
Sourcepub fn as_rfc3339(self) -> Rfc3339Timestamp
pub fn as_rfc3339(self) -> Rfc3339Timestamp
Returns a copy that displays and serializes as an RFC3339 string.
Sourcepub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_add(self, duration: Duration) -> Option<Self>
Adds a duration, rounding upward, or returns None if the result is out of range.
Sourcepub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
Subtracts a duration, rounding upward, or returns None if the result precedes the epoch.
Sourcepub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
pub fn checked_duration_since(self, earlier: Self) -> Option<Duration>
Returns the elapsed duration, or None if earlier is later than this timestamp.