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
impl LeapSeconds
Sourcepub fn new(table: Vec<(Timestamp, TimeDelta)>) -> Self
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.
Sourcepub fn reverse_leap_seconds(&self, t: Timestamp) -> TimeDelta
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.
Sourcepub fn leap_seconds(&self, t: Timestamp) -> TimeDelta
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.
Sourcepub fn from_ntp_file(file: &str) -> Option<Self>
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
impl Clone for LeapSeconds
Source§fn clone(&self) -> LeapSeconds
fn clone(&self) -> LeapSeconds
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more