# Leap Seconds and TAI

Industry: Core

UTC has had a second 60 on some days since 1972. Each one was inserted so that UTC stays close to
the rotation of the Earth, and each one made the number of seconds that UTC trails TAI (International
Atomic Time) grow by one. The `timescale/` namespace holds that table and the functions that read
it. A date, a count and a conversion all come from the same table, so none of them takes a
number you typed in.

## The insertions

The table follows the IERS file `Leap_Second.dat` as of IERS Bulletin C 72. Each row is the last
second of a UTC day, and the number is TAI − UTC after it.

| Inserted second | TAI − UTC after |
| --- | --- |
| `1972-06-30T23:59:60Z` | 11 |
| `1972-12-31T23:59:60Z` | 12 |
| `1973-12-31T23:59:60Z` | 13 |
| `1974-12-31T23:59:60Z` | 14 |
| `1975-12-31T23:59:60Z` | 15 |
| `1976-12-31T23:59:60Z` | 16 |
| `1977-12-31T23:59:60Z` | 17 |
| `1978-12-31T23:59:60Z` | 18 |
| `1979-12-31T23:59:60Z` | 19 |
| `1981-06-30T23:59:60Z` | 20 |
| `1982-06-30T23:59:60Z` | 21 |
| `1983-06-30T23:59:60Z` | 22 |
| `1985-06-30T23:59:60Z` | 23 |
| `1987-12-31T23:59:60Z` | 24 |
| `1989-12-31T23:59:60Z` | 25 |
| `1990-12-31T23:59:60Z` | 26 |
| `1992-06-30T23:59:60Z` | 27 |
| `1993-06-30T23:59:60Z` | 28 |
| `1994-06-30T23:59:60Z` | 29 |
| `1995-12-31T23:59:60Z` | 30 |
| `1997-06-30T23:59:60Z` | 31 |
| `1998-12-31T23:59:60Z` | 32 |
| `2005-12-31T23:59:60Z` | 33 |
| `2008-12-31T23:59:60Z` | 34 |
| `2012-06-30T23:59:60Z` | 35 |
| `2015-06-30T23:59:60Z` | 36 |
| `2016-12-31T23:59:60Z` | 37 |

The table is closed. The General Conference on Weights and Measures (CGPM) decided in 2022
(Resolution 4) to let the difference between UTC and the rotation of the Earth grow past one
second, and in 2026 (Resolution 5) that continuous UTC becomes effective on 20 May 2027. No
insertion after 2016 is known and none is planned. A weekly check compares the table with the
IERS file and fails if the two differ, so a row added by IERS shows up as a failed run.

## TAI − UTC by date

[`taiMinusUtc(instant)`](/gmt/reference/timescale/calculate/taiMinusUtc/) returns the whole seconds TAI
leads UTC by at an instant. Before 1972 UTC did not differ from TAI by whole seconds, so there
is no integer and the function returns `null`. An integer written for all dates is wrong for
every date before 1972.

```typescript
import { taiMinusUtc } from "@northguild/gmt/timescale/calculate";

taiMinusUtc("1971-12-31T23:59:59Z");
// null
taiMinusUtc("1972-01-01T00:00:00Z");
// 10
taiMinusUtc("1999-08-22T00:00:00Z");
// 32
taiMinusUtc("2016-12-31T23:59:60Z");
// 36
taiMinusUtc("2017-01-01T00:00:00Z");
// 37
```

## `23:59:60` is real only on listed days

A second 60 is a real reading on the days of the table and an invalid one on every other day.
[`hasSecond60`](/gmt/reference/plain/validate/hasSecond60/) only asks whether the text has a 60 in the
seconds place, so it accepts a day UTC never inserted a second on.
[`isLeapSecond`](/gmt/reference/timescale/validate/isLeapSecond/) asks the table, and it reads any offset,
because an inserted second is the same instant everywhere:

```typescript
import { hasSecond60 } from "@northguild/gmt/plain/validate";
import { isLeapSecond } from "@northguild/gmt/timescale/validate";

hasSecond60("2017-12-31T23:59:60Z");
// true
isLeapSecond("2017-12-31T23:59:60Z");
// false
isLeapSecond("2016-12-31T23:59:60Z");
// true
isLeapSecond("2017-01-01T08:59:60+09:00");
// true
```

See [A Leap Second That Never Happened](/gmt/scenarios/a-leap-second-that-never-happened/). Every
other function in the library rejects a second of 60, including `isValidInstant`.

## Counting and finding

[`leapSecondsBetween(start, end)`](/gmt/reference/timescale/calculate/leapSecondsBetween/) counts the
insertions in the half-open range from `start` up to but not including `end`. It is signed: the
reverse order gives the negative. It returns `null` if either end is before 1972.
[`nextLeapSecond(instant)`](/gmt/reference/timescale/calculate/nextLeapSecond/) returns the first
insertion after an instant, or an empty string when there is none, as there is none after the
last row of the table.

```typescript
import { leapSecondsBetween, nextLeapSecond } from "@northguild/gmt/timescale/calculate";

leapSecondsBetween("2000-01-01T00:00:00Z", "2024-01-01T00:00:00Z");
// 5
leapSecondsBetween("2024-01-01T00:00:00Z", "2000-01-01T00:00:00Z");
// -5
leapSecondsBetween("2016-12-31T23:59:59Z", "2017-01-01T00:00:00Z");
// 1
leapSecondsBetween("1971-01-01T00:00:00Z", "2024-01-01T00:00:00Z");
// null
nextLeapSecond("2016-01-01T00:00:00Z");
// "2016-12-31T23:59:60Z"
nextLeapSecond("2024-01-01T00:00:00Z");
// ""
```

## UTC and TAI through an inserted second

[`toTAI`](/gmt/reference/timescale/convert/toTAI/) and [`fromTAI`](/gmt/reference/timescale/convert/fromTAI/)
move an instant between the two scales. TAI has no second 60, so the inserted second maps to its
own TAI reading, and the readings across it run without a repeat:

```typescript
import { fromTAI, toTAI } from "@northguild/gmt/timescale/convert";

toTAI("2016-12-31T23:59:59Z");
// "2017-01-01T00:00:35 TAI"
toTAI("2016-12-31T23:59:60Z");
// "2017-01-01T00:00:36 TAI"
toTAI("2017-01-01T00:00:00Z");
// "2017-01-01T00:00:37 TAI"
toTAI("2017-12-31T23:59:60Z");
// ""
fromTAI("2017-01-01T00:00:36 TAI");
// "2016-12-31T23:59:60Z"
```

## CCSDS ASCII time codes

CCSDS 301.0-B-4 section 3.5 defines two text codes for a UTC instant. Code A is a calendar date,
`YYYY-MM-DDThh:mm:ss.d…dZ`. Code B is a day of the year, `YYYY-DDDThh:mm:ss.d…dZ`. The `Z` is
optional when a code is read, and the formatters always write it.

A second of `60` is read only where UTC inserted one. A code coarser than whole seconds names a
span and not an instant, so it returns `""`. A code that is read keeps its fraction as sent, up to
nine digits. A code that is written cuts the fraction to the digits you ask for and never rounds
it, so the last second of a year stays in that year.

```ts
import { parseCcsdsAsciiA, parseCcsdsAsciiB } from "@northguild/gmt/timescale/parse";
import { formatCcsdsAsciiA, formatCcsdsAsciiB } from "@northguild/gmt/timescale/format";

parseCcsdsAsciiB("2016-366T23:59:60.5Z"); // "2016-12-31T23:59:60.5Z"
parseCcsdsAsciiA("1988-01-18T17:20:43.123456"); // "1988-01-18T17:20:43.123456Z"
formatCcsdsAsciiA("2024-06-15T16:30:00+02:00"); // "2024-06-15T14:30:00Z"
formatCcsdsAsciiB("2026-12-31T23:59:59.9999999Z", 3); // "2026-365T23:59:59.999Z"
```

## TT and TCG

Terrestrial Time (TT) is TAI plus a fixed 32.184 seconds (IERS Technical Note 36, section 10.1). It
is the time argument an Earth ephemeris takes, so TT − UTC follows the leap-second steps: it was
42.184 seconds at the start of 1972 and has been 69.184 seconds since the end of 2016.
[`toTT`](/gmt/reference/timescale/convert/toTT/) and [`fromTT`](/gmt/reference/timescale/convert/fromTT/)
move an instant between UTC and a TT label, through the same table as `toTAI`.

Geocentric Coordinate Time (TCG) differs from TT by a rate, not by a label. IAU 2000 Resolution
B1.9 fixes TCG − TT at zero at 32.184 seconds past midnight on 1977-01-01 TT, and the gap grows
by a constant fraction of every second after that. It is negative before 1977 and has grown by
about 22 milliseconds a year since. [`toTCG`](/gmt/reference/timescale/convert/toTCG/) and
[`fromTCG`](/gmt/reference/timescale/convert/fromTCG/) apply it, and
[`tcgMinusTt`](/gmt/reference/timescale/calculate/tcgMinusTt/) is exported so that a caller sees the
size of the gap and not only the label it makes.

Before 1972 there is no whole-second TAI − UTC, so every one of these returns the sentinel:
`""` for the converters and `null` for `tcgMinusTt`.

```typescript
import { tcgMinusTt } from "@northguild/gmt/timescale/calculate";
import { fromTCG, fromTT, toTCG, toTT } from "@northguild/gmt/timescale/convert";

toTT("2026-01-01T00:00:00Z");
// "2026-01-01T00:01:09.184 TT"
toTCG("2026-01-01T00:00:00Z");
// "2026-01-01T00:01:10.261661917 TCG"
tcgMinusTt("2026-01-01T00:00:00Z");
// 1.077661917
tcgMinusTt("1976-12-31T23:59:45Z");
// 0
tcgMinusTt("1971-01-01T00:00:00Z");
// null
toTT("1971-01-01T00:00:00Z");
// ""
fromTT("2026-01-01T00:01:09.184 TT");
// "2026-01-01T00:00:00Z"
fromTCG("2026-01-01T00:01:10.261661917 TCG");
// "2026-01-01T00:00:00Z"
```

The [Terrestrial Time Stack](/gmt/tools/terrestrial-time-stack/) draws the three pieces of the gap as
one bar, and plots `tcgMinusTt` across the years.

## Elapsed seconds against the clock difference

Two UTC readings two hours apart on the clock are 7201 seconds apart in elapsed time when an
insertion falls between them. [`spanNs`](/gmt/reference/span/calculate/spanNs/) subtracts readings as
written, so on UTC readings it misses the inserted second. It returns `null` for a reading with a
second of 60, which it cannot place on a straight line. Give it the TAI readings of the same
instants and the inserted second counts:

```typescript
import { spanNs } from "@northguild/gmt/span/calculate";

spanNs("2016-12-31T23:59:59Z", "2017-01-01T00:00:00Z");
// 1000000000n
spanNs("2016-12-31T23:59:60Z", "2017-01-01T00:00:00Z");
// null
spanNs("2016-12-31T23:00:36Z", "2017-01-01T01:00:37Z");
// 7201000000000n
```

The last call is the span between the TAI readings of `2016-12-31T23:00:00Z` and
`2017-01-01T01:00:00Z`, written with a `Z` because `spanNs` reads one. The two UTC instants are two
hours apart on the clock and 7201 seconds apart in elapsed time. See [Mistakes: leap
seconds](/gmt/mistakes/leap-seconds/).

## Tools

- The [Leap Second Timeline](/gmt/tools/leap-second-timeline/?w=leapline&wa=%7B%22check%22%3A%222016-12-31T23%3A59%3A60Z%22%7D) draws every insertion, and the
  integer-seconds era before and the continuous era after.
- The [Terrestrial Time Stack](/gmt/tools/terrestrial-time-stack/) shows one instant on UTC, TAI, TT and TCG, with
  TAI − UTC, TT − TAI and TCG − TT as one bar and the growth of TCG − TT across the years.
- [Elapsed vs. Clock Difference](/gmt/tools/elapsed-vs-clock-difference/?w=elapsed&wa=%7B%22start%22%3A%222016-12-31T23%3A00%3A00Z%22%2C%22end%22%3A%222017-01-01T01%3A00%3A00Z%22%7D) shows the clock difference and
  the elapsed seconds of two readings side by side.
- The [CCSDS Time Code Decoder](/gmt/tools/ccsds-time-code-decoder/?w=ccsds&wa=%7B%22code%22%3A%222016-366T23%3A59%3A60.5Z%22%7D) reads a Code A or Code B text and shows the
  inserted second at `2016-366T23:59:60.5Z`.
- The [Code B Day Ruler](/gmt/tools/code-b-day-ruler/?w=dayruler&wa=%7B%22year%22%3A%222024%22%2C%22compare%22%3A%222026%22%2C%22day%22%3A%2261%22%7D) reads one Code B day in two years and draws each year's
  months on one scale, so the leap-day shift and the missing day 366 show.

## Sources

- IERS, `Leap_Second.dat`, and Bulletin C 72.
- ITU-R Recommendation TF.460-6: the standard-frequency and time-signal emissions, with UTC defined
  from 1972.
- CGPM 2022, Resolution 4, and CGPM 2026, Resolution 5, on the future of UTC.
