Skip to main content

Timestamp

Struct Timestamp 

Source
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

Source

pub const MIN: Self

The earliest point the count holds.

Source

pub const MAX: Self

The latest point the count holds.

Source

pub const fn checked_add(self, span: Timedelta) -> Option<Self>

The point span later, or None past the range.

Source

pub const fn checked_sub(self, span: Timedelta) -> Option<Self>

The point span earlier, or None past the range.

Source

pub const fn checked_since(self, start: Self) -> Option<Timedelta>

The span since start, or None past the span’s range.

Source

pub const fn floor(self, unit: Timedelta) -> Self

The nearest multiple of |unit| at or below the point, or the point for a zero unit.

Source

pub const fn ceil(self, unit: Timedelta) -> Self

The nearest multiple of |unit| at or above the point, or the point for a zero unit.

Source§

impl Timestamp

Source

pub const fn from_nanos(nanos: i64) -> Self

The point nanos nanoseconds after the Unix epoch.

Source

pub const fn from_micros(micros: i64) -> Self

The point micros microseconds after the Unix epoch, saturating.

Source

pub const fn from_millis(millis: i64) -> Self

The point millis milliseconds after the Unix epoch, saturating.

Source

pub const fn from_secs(secs: i64) -> Self

The point secs seconds after the Unix epoch, saturating.

Source

pub const fn as_nanos(self) -> i64

Nanoseconds since the Unix epoch.

Source

pub const fn as_micros(self) -> i64

Whole microseconds since the Unix epoch, rounded down.

Source

pub const fn as_millis(self) -> i64

Whole milliseconds since the Unix epoch, rounded down.

Source

pub const fn as_secs(self) -> i64

Whole seconds since the Unix epoch, rounded down.

Source§

impl Timestamp

Source

pub const UNIX_EPOCH: Self

1970-01-01T00:00:00Z, the point the count runs from.

Source§

impl Timestamp

Source

pub const fn to_utc(self) -> UtcDateTime

This point read as a date and a time of day in UTC.

Trait Implementations§

Source§

impl Add<Timedelta> for Timestamp

Saturates at MIN and MAX.

Source§

type Output = Timestamp

The resulting type after applying the + operator.
Source§

fn add(self, span: Timedelta) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<Timedelta> for Timestamp

Saturates at MIN and MAX.

Source§

fn add_assign(&mut self, span: Timedelta)

Performs the += operation. Read more
Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Timestamp

Source§

impl Debug for Timestamp

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Timestamp

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Timestamp

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

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.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Timestamp

Source§

impl From<Timestamp> for DateTime<Utc>

Every timestamp, in UTC, since chrono’s reach years -262143 to 262142.

Source§

fn from(instant: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for Timestamp

Every timestamp, since jiff’s reach years -9999 to 9999.

Source§

fn from(instant: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for SystemTime

A SystemTime here counts 64-bit seconds, which reach past both ends of a Timestamp.

Source§

fn from(instant: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for OffsetDateTime

Every timestamp, in UTC, since time’s reach years -9999 to 9999.

Source§

fn from(instant: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for UtcDateTime

Source§

fn from(instant: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl FromBytes for Timestamp
where i64: FromBytes,

§

fn ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>
where Self: KnownLayout + Immutable,

Interprets the given source as a &Self. Read more
§

fn ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>
where Self: KnownLayout + Immutable,

Interprets the prefix of the given source as a &Self without copying. Read more
§

fn ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, !>>
where Self: Immutable + KnownLayout,

Interprets the suffix of the given bytes as a &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,

Interprets the given source as a &mut Self. Read more
§

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,

Interprets the prefix of the given source as a &mut Self without copying. Read more
§

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,

Interprets the suffix of the given source as a &mut Self without copying. Read more
§

fn read_from_bytes(source: &[u8]) -> Result<Self, SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the given source. Read more
§

fn read_from_prefix( source: &[u8], ) -> Result<(Self, &[u8]), SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the prefix of the given source. Read more
§

fn read_from_suffix( source: &[u8], ) -> Result<(&[u8], Self), SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the suffix of the given source. Read more
§

fn read_from_io<R>(src: R) -> Result<Self, Error>
where Self: Sized, R: Read,

Reads a copy of self from an io::Read. Read more
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.

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§

type Err = ParseTimestampError

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromZeros for Timestamp
where i64: FromZeros,

§

fn zero(&mut self)

Overwrites self with zeros. Read more
§

fn new_zeroed() -> Self
where Self: Sized,

Creates an instance of Self from zeroed bytes. Read more
§

fn new_box_zeroed() -> Result<Box<Self>, AllocError>
where Self: Sized,

Creates a Box<Self> from zeroed bytes. Read more
§

fn new_vec_zeroed(len: usize) -> Result<Vec<Self>, AllocError>
where Self: Sized,

Creates a Vec<Self> from zeroed bytes. Read more
§

fn extend_vec_zeroed( v: &mut Vec<Self>, additional: usize, ) -> Result<(), AllocError>
where Self: Sized,

Extends a Vec<Self> by pushing additional new items onto the end of the vector. The new items are initialized with zeros.
§

fn insert_vec_zeroed( v: &mut Vec<Self>, position: usize, additional: usize, ) -> Result<(), AllocError>
where Self: Sized,

Inserts additional new items into Vec<Self> at position. The new items are initialized with zeros. Read more
Source§

impl Hash for Timestamp

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Immutable for Timestamp
where i64: Immutable,

Source§

impl IntoBytes for Timestamp
where i64: IntoBytes,

§

fn as_bytes(&self) -> &[u8] ⓘ
where Self: Immutable,

Gets the bytes of this value. Read more
§

fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
where Self: FromBytes,

Gets the bytes of this value mutably. Read more
§

fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to dst. Read more
§

fn write_to_prefix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the prefix of dst. Read more
§

fn write_to_suffix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the suffix of dst. Read more
§

fn write_to_io<W>(&self, dst: W) -> Result<(), Error>
where Self: Immutable, W: Write,

Writes a copy of self to an io::Write. Read more
Source§

impl JsonSchema for Timestamp

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn json_schema(_generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

impl KnownLayout for Timestamp
where Self: Sized,

Source§

type PointerMetadata = ()

The type of metadata stored in a pointer to Self. Read more
§

fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>

Computes the size of an object of type Self with the given pointer metadata. Read more
Source§

impl Ord for Timestamp

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Timestamp

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Timestamp

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Timestamp

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Timestamp

Source§

impl Sub for Timestamp

The span since the other point, saturating at the span’s range.

Source§

type Output = Timedelta

The resulting type after applying the - operator.
Source§

fn sub(self, start: Self) -> Timedelta

Performs the - operation. Read more
Source§

impl Sub<Timedelta> for Timestamp

Saturates at MIN and MAX.

Source§

type Output = Timestamp

The resulting type after applying the - operator.
Source§

fn sub(self, span: Timedelta) -> Self

Performs the - operation. Read more
Source§

impl SubAssign<Timedelta> for Timestamp

Saturates at MIN and MAX.

Source§

fn sub_assign(&mut self, span: Timedelta)

Performs the -= operation. Read more
Source§

impl TimePoint for Timestamp

Source§

type Span = Timedelta

The span between two points.
Source§

fn from_count(count: i64) -> Self

The point count units after the origin.
Source§

fn count(self) -> i64

The point’s count of units since the origin.
Source§

impl<Z: TimeZone> TryFrom<DateTime<Z>> for Timestamp

Refuses an instant outside Timestamp::MIN to Timestamp::MAX, in any zone.

Source§

type Error = OutOfRangeError

The type returned in the event of a conversion error.
Source§

fn try_from(instant: DateTime<Z>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OffsetDateTime> for Timestamp

Refuses an instant outside Timestamp::MIN to Timestamp::MAX, at any offset.

Source§

type Error = OutOfRangeError

The type returned in the event of a conversion error.
Source§

fn try_from(instant: OffsetDateTime) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<SystemTime> for Timestamp

Refuses a SystemTime outside 1677-09-21 to 2262-04-11.

Source§

type Error = OutOfRangeError

The type returned in the event of a conversion error.
Source§

fn try_from(instant: SystemTime) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Timestamp> for Timestamp

Refuses an instant outside Timestamp::MIN to Timestamp::MAX.

Source§

type Error = OutOfRangeError

The type returned in the event of a conversion error.
Source§

fn try_from(instant: JiffTimestamp) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFromBytes for Timestamp
where i64: TryFromBytes,

§

fn try_ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the given source as a &Self. Read more
§

fn try_ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the prefix of the given source as a &Self. Read more
§

fn try_ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the suffix of the given source as a &Self. Read more
§

fn try_mut_from_bytes( bytes: &mut [u8], ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the given source as a &mut Self without copying. Read more
§

fn try_mut_from_prefix( source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the prefix of the given source as a &mut Self. Read more
§

fn try_mut_from_suffix( source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the suffix of the given source as a &mut Self. Read more
§

fn try_read_from_bytes( source: &[u8], ) -> Result<Self, ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read the given source as a Self. Read more
§

fn try_read_from_prefix( source: &[u8], ) -> Result<(Self, &[u8]), ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the prefix of the given source. Read more
§

fn try_read_from_suffix( source: &[u8], ) -> Result<(&[u8], Self), ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the suffix of the given source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<A, T> Read<A, BecauseImmutable> for T
where A: Aliasing, T: Immutable + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.