Skip to main content

Crate leap_sec

Crate leap_sec 

Source
Expand description

§leap-sec

Leap-second handling and continuous time mappings for flight and space systems.

This crate provides type-safe conversions between UTC, TAI, and GPS time scales using an explicit leap-second table. The API is designed so that you cannot accidentally mix time scales at call sites.

§Quick Start

use leap_sec::prelude::*;

let leaps = LeapSeconds::known();

// Convert UTC to TAI
let utc = UtcUnixSeconds(1_700_000_000);
let tai = leaps.utc_to_tai(utc).unwrap();
assert_eq!(tai, TaiSeconds(1_700_000_037));

// Roundtrip
let back = leaps.tai_to_utc(tai).unwrap();
assert_eq!(back, utc);

§Leap-Second History

Since 1972, the IERS has inserted 27 leap seconds. Each insertion increases the TAI−UTC offset by 1 second. The most recent insertion was on 2016-12-31 at 23:59:60 UTC, making the new offset (TAI−UTC = 37s) effective from 2017-01-01 00:00:00 UTC. No new leap seconds have been inserted since.

The built-in LeapSeconds::known() table contains all 28 entries: the initial 1972-01-01 epoch (offset 10) plus the 27 subsequent insertions.

§The Future of UTC (2030s)

In 2022, the 27th CGPM adopted Resolution 4 on the future of UTC: the plan is to increase the maximum allowed value of |UT1−UTC| (currently kept within ±0.9s using leap seconds) at a date to be determined, with key decisions targeted by or before 2035.

In practice, this is widely understood as the path to ending leap seconds. This crate treats leap seconds as explicit table data, so if they stop being inserted, the table stops growing and historical conversions remain correct.

§Negative Leap Seconds

The ITU-R Recommendation TF.460 allows negative leap seconds (where the TAI−UTC offset decreases by 1 and UTC skips from 23:59:58 directly to 00:00:00). No negative leap second has ever been applied — all 27 historical insertions have been positive.

The table format and conversion logic handle them correctly:

  • A table entry where the new offset is less than the previous offset represents a negative leap second.
  • LeapSeconds::is_during_leap_second() returns false for negative leap seconds (there is no extra second; instead a second is removed).
  • Roundtrip utc_to_taitai_to_utc remains correct.

The custom table builder accepts negative entries for testing.

Modules§

prelude
Prelude for convenient glob imports.

Structs§

GpstNanos
Continuous nanoseconds in the GPS time scale.
GpstSeconds
Continuous seconds count in the GPS time scale.
LeapSeconds
An immutable leap-second schedule.
LeapSecondsBuilder
A builder for constructing custom LeapSeconds tables.
TaiNanos
Continuous nanoseconds in the TAI scale.
TaiSeconds
Continuous seconds count in the TAI scale (no leap seconds).
UtcUnixNanos
Unix-epoch nanoseconds in the UTC scale.
UtcUnixSeconds
Unix-like seconds count in the UTC scale.

Enums§

Error
Errors that can occur during leap-second conversions or table construction.

Functions§

gpst_to_tai
Convert GPS Time to TAI. TAI = GPST + 19s. Always exact.
gpst_to_tai_nanos
Convert GPST nanoseconds to TAI nanoseconds. Always exact.
tai_to_gpst
Convert TAI to GPS Time. GPST = TAI − 19s. Always exact.
tai_to_gpst_nanos
Convert TAI nanoseconds to GPST nanoseconds. Always exact.