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:

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

Contains all error-related functionality of the crate.

Structs

A date.
A leap second as read from a leap-seconds.list file.
Provides access to the data in leap-seconds.list.
A SHA-1 hash.
A time.
A date and time represented as seconds since 1900-01-01 00:00:00.