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
impl Timestamp
Sourcepub fn from_tai(secs: i64, nanos: u32) -> Option<Timestamp>
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.
Sourcepub fn from_utc(secs: i64, nanos: u32) -> Option<Timestamp>
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.
Sourcepub fn from_utc_secs(secs: i64) -> Timestamp
pub fn from_utc_secs(secs: i64) -> Timestamp
Create a timestamp from a raw UTC seconds value. See
from_utc for details.
Sourcepub fn from_tai_secs(secs: i64) -> Timestamp
pub fn from_tai_secs(secs: i64) -> Timestamp
Create a timestamp from a raw TAI seconds value. See
from_tai for details.
Sourcepub fn min(self, other: Timestamp) -> Timestamp
pub fn min(self, other: Timestamp) -> Timestamp
Find the earlier of two timestamps and return it.
Sourcepub fn max(self, other: Timestamp) -> Timestamp
pub fn max(self, other: Timestamp) -> Timestamp
Find the later of two timestamps and return it.
Sourcepub fn utc(&self) -> (i64, u32)
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.
Sourcepub fn tai_secs(&self) -> i64
pub fn tai_secs(&self) -> i64
Return the TAI number of seconds since January 1, 1970 00:00:00 UTC.
Sourcepub fn tai_subsec_nanos(&self) -> u32
pub fn tai_subsec_nanos(&self) -> u32
Returns the number of nanoseconds past the second count.
Sourcepub fn time_since(&self, other: &Timestamp) -> TimeDelta
pub fn time_since(&self, other: &Timestamp) -> TimeDelta
Calculates the time that has elapsed between the other timestamp and
this one. Effectively self - other.
Sourcepub fn as_vec(&self) -> Vec<u8> ⓘ
pub fn as_vec(&self) -> Vec<u8> ⓘ
Convert into a byte vector. For extending an existing byte vector, see
encode_vec.
Sourcepub fn encode_vec(&self, vec: &mut Vec<u8>)
pub fn encode_vec(&self, vec: &mut Vec<u8>)
Encode onto a byte vector one of 3 formats:
- If nanoseconds is nonzero, encode the seconds as little-endian i64, and the nanoseconds as little-endian u32.
- If nanoseconds is zero & seconds maps to a u32, encode just the seconds as little-endian u32.
- 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.
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Return the number of bytes needed to encode the timestamp as a byte
vector with encode_vec.
Trait Implementations§
Source§impl AddAssign<TimeDelta> for Timestamp
impl AddAssign<TimeDelta> for Timestamp
Source§fn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+= operation. Read moreSource§impl AddAssign<i64> for Timestamp
impl AddAssign<i64> for Timestamp
Source§fn add_assign(&mut self, rhs: i64)
fn add_assign(&mut self, rhs: i64)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<SystemTime> for Timestamp
impl From<SystemTime> for Timestamp
Source§fn from(value: SystemTime) -> Self
fn from(value: SystemTime) -> Self
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl SubAssign<TimeDelta> for Timestamp
impl SubAssign<TimeDelta> for Timestamp
Source§fn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-= operation. Read moreSource§impl SubAssign<i64> for Timestamp
impl SubAssign<i64> for Timestamp
Source§fn sub_assign(&mut self, rhs: i64)
fn sub_assign(&mut self, rhs: i64)
-= operation. Read moreSource§impl TryFrom<&[u8]> for Timestamp
Parse an encoded timestamp. Must be 4, 8, or 12 bytes (matching what was
written by Timestamp::encode_vec)
impl TryFrom<&[u8]> for Timestamp
Parse an encoded timestamp. Must be 4, 8, or 12 bytes (matching what was
written by Timestamp::encode_vec)