pub struct Timestamp(/* private fields */);Expand description
A point on the wall clock, in nanoseconds since the Unix epoch.
It names a moment another machine can name too, which is what makes it the stamp to capture
with; the clock behind it may step, so a span that must never run backwards is measured on an
Uptime instead. It holds 1677-09-21 to 2262-04-11, and its operators saturate
at either end. It is written as RFC 3339 in UTC, and parses back from it.
§Examples
use t2t_core::{Timedelta, Timestamp};
let published = Timestamp::from_secs(1_700_000_000);
let captured = published + Timedelta::from_micros(850);
assert_eq!(captured - published, Timedelta::from_micros(850), "a point minus a point");
assert_eq!(format!("{captured:.6}"), "2023-11-14T22:13:20.000850Z", "to the microsecond");
let minute = captured.floor(Timedelta::MINUTE);
assert_eq!(format!("{minute:.0}"), "2023-11-14T22:13:00Z", "the minute it falls in");Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const fn checked_add(self, span: Timedelta) -> Option<Self>
pub const fn checked_add(self, span: Timedelta) -> Option<Self>
The point span later, or None past the range.
Sourcepub const fn checked_sub(self, span: Timedelta) -> Option<Self>
pub const fn checked_sub(self, span: Timedelta) -> Option<Self>
The point span earlier, or None past the range.
Sourcepub const fn checked_since(self, start: Self) -> Option<Timedelta>
pub const fn checked_since(self, start: Self) -> Option<Timedelta>
The span since start, or None past the span’s range.
Source§impl Timestamp
impl Timestamp
Sourcepub const fn from_nanos(nanos: i64) -> Self
pub const fn from_nanos(nanos: i64) -> Self
The point nanos nanoseconds after the Unix epoch.
Sourcepub const fn from_micros(micros: i64) -> Self
pub const fn from_micros(micros: i64) -> Self
The point micros microseconds after the Unix epoch, saturating.
Sourcepub const fn from_millis(millis: i64) -> Self
pub const fn from_millis(millis: i64) -> Self
The point millis milliseconds after the Unix epoch, saturating.
Source§impl Timestamp
impl Timestamp
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
1970-01-01T00:00:00Z, the point the count runs from.
Trait Implementations§
Source§impl AddAssign<Timedelta> for Timestamp
impl AddAssign<Timedelta> for Timestamp
Source§fn add_assign(&mut self, span: Timedelta)
fn add_assign(&mut self, span: Timedelta)
+= operation. Read moreimpl Copy for Timestamp
Source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for Timestamp
RFC 3339 in UTC, with Z: 2026-09-16T07:45:35.123456789Z.
impl Display for Timestamp
RFC 3339 in UTC, with Z: 2026-09-16T07:45:35.123456789Z.
The precision chooses the fraction’s digits, nine by default and at most nine: {:.3} writes
milliseconds and {:.0} none. A width pads the spelling.
impl Eq for Timestamp
Source§impl From<Timestamp> for DateTime<Utc>
Every timestamp, in UTC, since chrono’s reach years -262143 to 262142.
impl From<Timestamp> for DateTime<Utc>
Every timestamp, in UTC, since chrono’s reach years -262143 to 262142.
Source§impl From<Timestamp> for SystemTime
A SystemTime here counts 64-bit seconds, which reach past both ends of a Timestamp.
impl From<Timestamp> for SystemTime
A SystemTime here counts 64-bit seconds, which reach past both ends of a Timestamp.
Source§impl From<Timestamp> for OffsetDateTime
Every timestamp, in UTC, since time’s reach years -9999 to 9999.
impl From<Timestamp> for OffsetDateTime
Every timestamp, in UTC, since time’s reach years -9999 to 9999.
Source§impl From<Timestamp> for UtcDateTime
impl From<Timestamp> for UtcDateTime
Source§impl FromBytes for Timestampwhere
i64: FromBytes,
impl FromBytes for Timestampwhere
i64: FromBytes,
§fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
§fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: KnownLayout + Immutable,
§fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: Immutable + KnownLayout,
fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>where
Self: Immutable + KnownLayout,
&Self. Read more§fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, !>>where
Self: IntoBytes + KnownLayout,
§fn read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), SizeError<&[u8], Self>>where
Self: Sized,
fn read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), SizeError<&[u8], Self>>where
Self: Sized,
Source§impl FromStr for Timestamp
Reads what Display writes, T and Z in either case, and a fraction of one
to nine digits or none.
impl FromStr for Timestamp
Reads what Display writes, T and Z in either case, and a fraction of one
to nine digits or none.
It refuses an offset, a 60th second, a date that does not exist, and an instant outside 1677-09-21 to 2262-04-11.
Source§impl FromZeros for Timestampwhere
i64: FromZeros,
impl FromZeros for Timestampwhere
i64: FromZeros,
§fn new_zeroed() -> Selfwhere
Self: Sized,
fn new_zeroed() -> Selfwhere
Self: Sized,
Self from zeroed bytes. Read more§fn new_box_zeroed() -> Result<Box<Self>, AllocError>where
Self: Sized,
fn new_box_zeroed() -> Result<Box<Self>, AllocError>where
Self: Sized,
Box<Self> from zeroed bytes. Read more§fn new_vec_zeroed(len: usize) -> Result<Vec<Self>, AllocError>where
Self: Sized,
fn new_vec_zeroed(len: usize) -> Result<Vec<Self>, AllocError>where
Self: Sized,
Vec<Self> from zeroed bytes. Read moreimpl Immutable for Timestampwhere
i64: Immutable,
Source§impl IntoBytes for Timestampwhere
i64: IntoBytes,
impl IntoBytes for Timestampwhere
i64: IntoBytes,
§fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
§fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
§fn write_to_prefix(
&self,
dst: &mut [u8],
) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to_prefix(
&self,
dst: &mut [u8],
) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
Source§impl JsonSchema for Timestamp
impl JsonSchema for Timestamp
Source§fn json_schema(_generator: &mut SchemaGenerator) -> Schema
fn json_schema(_generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl KnownLayout for Timestampwhere
Self: Sized,
impl KnownLayout for Timestampwhere
Self: Sized,
Source§type PointerMetadata = ()
type PointerMetadata = ()
Self. Read more§fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
Self with the given pointer
metadata. Read moreSource§impl Ord for Timestamp
impl Ord for Timestamp
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 PartialOrd for Timestamp
impl PartialOrd for Timestamp
impl StructuralPartialEq for Timestamp
Source§impl SubAssign<Timedelta> for Timestamp
impl SubAssign<Timedelta> for Timestamp
Source§fn sub_assign(&mut self, span: Timedelta)
fn sub_assign(&mut self, span: Timedelta)
-= operation. Read moreSource§impl<Z: TimeZone> TryFrom<DateTime<Z>> for Timestamp
Refuses an instant outside Timestamp::MIN to Timestamp::MAX, in any zone.
impl<Z: TimeZone> TryFrom<DateTime<Z>> for Timestamp
Refuses an instant outside Timestamp::MIN to Timestamp::MAX, in any zone.
Source§impl TryFrom<OffsetDateTime> for Timestamp
Refuses an instant outside Timestamp::MIN to Timestamp::MAX, at any offset.
impl TryFrom<OffsetDateTime> for Timestamp
Refuses an instant outside Timestamp::MIN to Timestamp::MAX, at any offset.
Source§impl TryFrom<SystemTime> for Timestamp
Refuses a SystemTime outside 1677-09-21 to 2262-04-11.
impl TryFrom<SystemTime> for Timestamp
Refuses a SystemTime outside 1677-09-21 to 2262-04-11.
Source§type Error = OutOfRangeError
type Error = OutOfRangeError
Source§impl TryFrom<Timestamp> for Timestamp
Refuses an instant outside Timestamp::MIN to Timestamp::MAX.
impl TryFrom<Timestamp> for Timestamp
Refuses an instant outside Timestamp::MIN to Timestamp::MAX.