Repository navigation
Leap Seconds and LSK
The leap-second kernel is the only source of truth for TAI - UTC. No leap
second is hard-coded in the conversion logic.
A KPL/LSK file assigns these variables:
| Variable | Meaning |
|---|---|
DELTET/DELTA_T_A |
TT - TAI, nominal 32.184 s
|
DELTET/K |
amplitude of the NAIF TDB - TT term, nominal 1.657e-3 s
|
DELTET/EB |
eccentricity term, nominal 1.671e-2
|
DELTET/M |
two coefficients: mean anomaly at J2000 and its rate, 6.239996 and 1.99096871e-7
|
DELTET/DELTA_AT |
the (TAI - UTC, @DATE) list |
src/lsk.rs parses these variables, reading every \begindata block in the
file. Unknown variables are ignored so newer kernels stay readable.
NAIF text kernels distinguish assignment from accumulation:
-
DELTET/DELTA_AT = ( ... )replaces the accumulated table. -
DELTET/DELTA_AT += ( ... )appends to it. - Any other operator is a parse error (
LskParse).
This matters because a kernel may restate the whole table in a later data
block, or extend an earlier one. tests/kernel_validation.rs covers both
forms.
- Every date must be a real calendar date;
1972-FEB-31is rejected. - Dates must be unique; duplicates are rejected.
- Constants must be finite;
NaNor infinity is rejected. - The TAI start of each entry must be strictly increasing.
For UTC days at or after 1972-01-01, the length of a day is
day_length(jdn) = 86400 + DELTA_AT(jdn + 1) - DELTA_AT(jdn)
so a positive leap second gives 86401, a negative one 86399, and a normal
day 86400. Conversions use that value directly:
| Day length | Last representable label |
|---|---|
| 86 401 s | 23:59:60.999... |
| 86 400 s | 23:59:59.999... |
| 86 399 s | 23:59:58.999... |
Consequences enforced by convert::utc_to_tai:
-
23:59:60.xon a normal day returnsInvalidLeapSecond. -
23:59:59.xon a shortened day returnsInvalidLeapSecond. -
60.xat any time other than23:59returnsInvalidLeapSecond.
The inverse conversion (tai_to_utc) reconstructs 23:59:60.x when the TAI
instant falls inside a positive leap second, using the nominal and TAI start
of each table entry.
LeapSecondTable::coverage() returns (first_jdn, last_jdn): the first and
last effective dates present in the kernel.
UTC input before first_jdn is rejected with UtcOutOfRange rather than
guessed. After last_jdn, the last delta is held constant. This matches
NAIF's documented TableDriven behaviour: a kernel cannot contain a leap
second announced after the kernel was released. A kernel's last entry is not
an expiry date, but it is a data coverage limit — update the kernel when a
new leap second is announced.
LeapSecondPolicy makes this explicit:
| Policy | Behaviour |
|---|---|
TableDriven (default) |
Follow the table; hold the last value indefinitely |
FrozenAfter { jdn } |
Ignore entries after jdn and keep the last applicable value |
LeapSecondPolicy::frozen_after(year, month, day) builds the second form.
Neither policy invents data; both are statements about the input.
UTC seconds were not SI seconds before 1972. Two sources are available:
LeapSecondSource |
Behaviour |
|---|---|
IersOnly (default) |
Integer leap seconds only, from 1972-01-01. Earlier input returns UtcOutOfRange. This matches the NAIF LSK. |
Sofa |
Adds the IAU SOFA iauDat drift model from 1960-01-01, with fractional TAI - UTC and mini-leap labels |
The SOFA rows are stored in src/leap.rs and evaluated as
TAI - UTC = base + (MJD - reference_mjd) * drift_per_day
utc_to_tai applies the daily drift to UTC seconds of day and applies any
separate end-of-day jump, keeping the absolute epoch integral so nanoseconds
are not lost in f64. tai_to_utc uses a nearby integral day estimate for
the inverse to avoid cancellation.
contract::ScientificContext refuses historical UTC unless the SOFA
conversion is selected explicitly (HistoricalUtcRequiresExplicitModel), so
a NAIF-based pipeline cannot silently switch conventions.
LeapSecondTable::builtin() parses src/naif0012.tls, which is compiled
into the crate with include_str!. It covers the leap seconds from 1972
through the 2017-01-01 event. For work near or after the last entry, load a
newer kernel:
let text = std::fs::read_to_string("naif0012.tls")?;
let lsk = LeapSecondTable::from_lsk(&text)?;| Error | Meaning |
|---|---|
LskMissing(var) |
A required DELTET variable is absent |
LskParse |
The kernel text is malformed, a date is invalid, a constant is not finite, or an operator is unsupported |
UtcOutOfRange |
UTC input outside the kernel's coverage, or pre-1972 input with IersOnly
|
InvalidLeapSecond |
A 23:59:60.x or 23:59:59.x label that this day does not have |
Leap seconds are announced by the IERS, and NAIF publishes an updated LSK
when one is needed. The 27th CGPM (2022), Resolution 4, set a target of no
new leap seconds by 2035, with |UT1 - UTC| allowed to grow. A future
without leap seconds is a policy assumption, not a fact encoded here:
use LeapSecondPolicy::FrozenAfter and cite the decision that applies to
your analysis.
