Crate leap_seconds
source ·Expand description
This crate provides a means of accessing current leap second data.
This is achieved through a parser that can read and provide access to the data in a
leap-seconds.list
file. A copy of this file can be obtained from various sources. To name a
few:
- IERS: https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list
- TZDB (from IANA): https://data.iana.org/time-zones/tzdb/leap-seconds.list
- TZDB (from GitHub): https://raw.githubusercontent.com/eggert/tz/main/leap-seconds.list
- Meinberg: https://www.meinberg.de/download/ntp/leap-seconds.list
It is recommended that you get the file from the IERS as they are responsible for announcing leap seconds. Consequently, they will most likely provide the most up to date version of the file.
You do not need to have any knowledge of the structure or contents of the leap-seconds.list
file in order to use this crate. However, if you want to know more about leap-seconds.list
,
here’s an article from Meinberg on the matter:
https://kb.meinbergglobal.com/kb/time_sync/ntp/configuration/ntp_leap_second_file (last accessed 2022-11-26)
Quickstart
reqwest is used in this example, but any other HTTP library or a local file will work just as well.
use leap_seconds::LeapSecondsList;
use std::io::BufReader;
// ======= fetching & parsing the file ======= //
// get the file from the IERS
let file = reqwest::blocking::get("https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list")
.unwrap();
// parse the file
let leap_seconds_list = LeapSecondsList::new(BufReader::new(file)).unwrap();
// make sure the file is up to date
// you should always do this unless you don't mind working with outdated data
assert!(!leap_seconds_list.is_expired());
// ======= some things that are possible ======= //
// get the next leap second that will be introduced
let next_leap_second = leap_seconds_list.next_leap_second();
// get an ordered slice of all future leap seconds currently announced
let future_leap_seconds = leap_seconds_list.planned_leap_seconds();
// get an ordered slice of all leap seconds that have been introduced since 1970
let all_leap_seconds = leap_seconds_list.leap_seconds();
// get the last time the `leap-seconds.list` file was updated
let last_update = leap_seconds_list.last_update();
Re-exports
pub use errors::*;
Modules
Structs
leap-seconds.list
file.leap-seconds.list
.