Timestamp

Struct Timestamp 

Source
pub struct Timestamp { /* private fields */ }
Expand description

Structure for holding a raw fog-pack timestamp. This stores a TAI timestamp relative to the Unix epoch of 1970-01-01T00:00:00Z. This is what a correctly configured Linux TIME_TAI clock would return. It also matches the IEEE 1588 Precision Time Protocol standard epoch and timescale.

This is not UTC time, Unix Time, or POSIX Time.

Functions for converting from and to UTC are available as from_utc and utc. The conversion is handled using a built-in table of leap seconds. This table can be updated by calling set_utc_leap_seconds with a new table. See LeapSeconds for how to create a new table.

While these functions do their best to provide correct round-trip conversion for TAI->UTC->TAI and UTC->TAI->UTC, the handling around the exact leap second point can create a delta, due to UTC Unix time reusing a seconds value during the leap second. Using TAI directly if possible is thus preferred, as is sticking to Timestamps as much as possible and only converting back to UTC when you need to display the timestamp for people.

Implementations§

Source§

impl Timestamp

Source

pub fn from_tai(secs: i64, nanos: u32) -> Option<Timestamp>

Create a TAI timestamp from a raw seconds + nanoseconds value. This should be the number of seconds since the Unix epoch of 1970-01-01T00:00:00Z, without any leap seconds thrown about.

Source

pub fn from_utc(secs: i64, nanos: u32) -> Option<Timestamp>

Create a timestamp from a raw UTC seconds + nanosecond value. This should be the number of seconds since the Unix epoch of 1970-01-01T00:00:00Z, with the usual UTC leap seconds thrown in. This is commonly referred to as Unix time, and is the default timebase for many computer systems.

The UTC-to-TAI conversion is handled using a built-in table of leap seconds. This table can be updated by calling set_utc_leap_seconds with the table.

Source

pub fn from_utc_secs(secs: i64) -> Timestamp

Create a timestamp from a raw UTC seconds value. See from_utc for details.

Source

pub fn from_tai_secs(secs: i64) -> Timestamp

Create a timestamp from a raw TAI seconds value. See from_tai for details.

Source

pub const fn zero() -> Timestamp

Zero time - TAI Unix epoch time

Source

pub const fn min_value() -> Timestamp

Minimum possible time that can be represented

Source

pub const fn max_value() -> Timestamp

Maximum possible time that can be represented

Source

pub fn min(self, other: Timestamp) -> Timestamp

Find the earlier of two timestamps and return it.

Source

pub fn max(self, other: Timestamp) -> Timestamp

Find the later of two timestamps and return it.

Source

pub fn next(self) -> Timestamp

Add 1 nanosecond to timestamp.

Source

pub fn prev(self) -> Timestamp

Subtract 1 nanosecond from timestamp.

Source

pub fn utc(&self) -> (i64, u32)

Return the UNIX timestamp (number of seconds since January 1, 1970 0:00:00 UTC). As a reminder, this is UTC time and thus has leap seconds removed/added.

The TAI-to-UTC conversion is handled using a built-in table of leap seconds. This table can be updated by calling set_utc_leap_seconds with the table.

Source

pub fn tai_secs(&self) -> i64

Return the TAI number of seconds since January 1, 1970 00:00:00 UTC.

Source

pub fn tai_subsec_nanos(&self) -> u32

Returns the number of nanoseconds past the second count.

Source

pub fn time_since(&self, other: &Timestamp) -> TimeDelta

Calculates the time that has elapsed between the other timestamp and this one. Effectively self - other.

Source

pub fn as_vec(&self) -> Vec<u8>

Convert into a byte vector. For extending an existing byte vector, see encode_vec.

Source

pub fn encode_vec(&self, vec: &mut Vec<u8>)

Encode onto a byte vector one of 3 formats:

  1. If nanoseconds is nonzero, encode the seconds as little-endian i64, and the nanoseconds as little-endian u32.
  2. If nanoseconds is zero & seconds maps to a u32, encode just the seconds as little-endian u32.
  3. If nanoseconds is zero & seconds does not map to a u32, encode the seconds as little-endian i64.

The length can be used to determine the format in which it was written.

Source

pub fn size(&self) -> usize

Return the number of bytes needed to encode the timestamp as a byte vector with encode_vec.

Source

pub fn now() -> Timestamp

Create a Timestamp based on the current system time.

Trait Implementations§

Source§

impl Add<TimeDelta> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeDelta) -> Timestamp

Performs the + operation. Read more
Source§

impl Add<i64> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the + operator.
Source§

fn add(self, rhs: i64) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<TimeDelta> for Timestamp

Source§

fn add_assign(&mut self, rhs: TimeDelta)

Performs the += operation. Read more
Source§

impl AddAssign<i64> for Timestamp

Source§

fn add_assign(&mut self, rhs: i64)

Performs the += operation. Read more
Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Timestamp

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Timestamp

Source§

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

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

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

Source§

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

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

impl Display for Timestamp

Source§

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

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

impl From<SystemTime> for Timestamp

Source§

fn from(value: SystemTime) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for Value

Source§

fn from(v: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Timestamp> for ValueRef<'a>

Source§

fn from(v: Timestamp) -> Self

Converts to this type from the input type.
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 Ord for Timestamp

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for Timestamp

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Timestamp

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

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

impl Sub<TimeDelta> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TimeDelta) -> Timestamp

Performs the - operation. Read more
Source§

impl Sub<i64> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: i64) -> Self

Performs the - operation. Read more
Source§

impl Sub for Timestamp

Source§

type Output = TimeDelta

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Timestamp) -> TimeDelta

Performs the - operation. Read more
Source§

impl SubAssign<TimeDelta> for Timestamp

Source§

fn sub_assign(&mut self, rhs: TimeDelta)

Performs the -= operation. Read more
Source§

impl SubAssign<i64> for Timestamp

Source§

fn sub_assign(&mut self, rhs: i64)

Performs the -= operation. Read more
Source§

impl TryFrom<&[u8]> for Timestamp

Parse an encoded timestamp. Must be 4, 8, or 12 bytes (matching what was written by Timestamp::encode_vec)

Source§

type Error = String

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

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Timestamp

Source§

type Error = Value

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

fn try_from(v: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<ValueRef<'a>> for Timestamp

Source§

type Error = ValueRef<'a>

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

fn try_from(v: ValueRef<'a>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Timestamp

Source§

impl Eq for Timestamp

Source§

impl StructuralPartialEq for Timestamp

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
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> 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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

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