LeapSeconds

Struct LeapSeconds 

Source
pub struct LeapSeconds(pub Vec<(Timestamp, TimeDelta)>);
Expand description

A fully decoded leap second table, suitable for converting between time standards.

This table should contain strictly increasing timestamps and the associated time differences to apply from that timestamp onward. It can be used to get the difference to apply, and can take an invalid timestamp and correct it.

All timestamps should use TAI time starting from the 1970 UNIX epoch, and the timestamps in this table should be no different. That means this does not match the NTP leap second table; use from_ntp_file to parse one appropriately.

This struct doesn’t implement Serialize or Deserialize for a reason; it’s very easy to construct invalid tables. Consider making a format that delta-encodes timestamps and differences instead, which is more amenable to schema-based validation.

Tuple Fields§

§0: Vec<(Timestamp, TimeDelta)>

Implementations§

Source§

impl LeapSeconds

Source

pub fn new(table: Vec<(Timestamp, TimeDelta)>) -> Self

Construct a new leap second table. Assumes the Timestamp values are strictly increasing, that the TimeDelta values don’t change by more than a few seconds, and that the timestamps are spaced more than twice the TimeDelta values apart.

Source

pub fn reverse_leap_seconds(&self, t: Timestamp) -> TimeDelta

Look up the amount of time to subtract from a timestamp that has leap seconds in it. Used for converting from UTC to TAI. This function assumes that the provided Timestamp is incorrect, in that it assumes the Timestamp is in UTC Unix seconds.

Source

pub fn leap_seconds(&self, t: Timestamp) -> TimeDelta

Look up the amount of time to add to a timestamp to compensate for leap seconds, according to this table. Used for converting from TAI to UTC.

Source

pub fn from_ntp_file(file: &str) -> Option<Self>

Parse a NTP leap seconds file that has been read in as a string.

The latest leap seconds file can be fetched from https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list. This is the file published by IERS, the official source of leap second publications.

Historical leap seconds files are available at https://hpiers.obspm.fr/iers/bul/bulc/ntp/.

The default leap seconds list is loaded from a compiled-in version of this list, which will be updated whenever a new list is published (bumping the patch version of this crate).

Trait Implementations§

Source§

impl Clone for LeapSeconds

Source§

fn clone(&self) -> LeapSeconds

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 LeapSeconds

Source§

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

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

impl Default for LeapSeconds

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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, 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.