Skip to content

instantLeapSecond

const instantLeapSecond: RegExp = /^[^[]*?[Tt ]\d{2}:?\d{2}:?60(?:[.,]\d+)?[-+Zz[]/;

RegExp fragment matching an ISO 8601 leap second in every shape Temporal.Instant.from accepts.

import { instantLeapSecond } from "@northguild/gmt";
instantLeapSecond.test("2016-12-31T23:59:60Z") // true
instantLeapSecond.test("2016-12-31 23:59:60Z") // true (space separator)
instantLeapSecond.test("20161231t235960Z") // true (basic format)
instantLeapSecond.test("2016-12-31T23:59:59Z") // false (second = 59)
instantLeapSecond.test("2016-12-31T23:59:60") // false (no designator, so not an instant)
instantLeapSecond.test("2024-01-01T00:00:00Z[x=T123460Z]") // false (inside an annotation value)

regex/leap-second.ts