@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
61 lines • 3.13 kB
TypeScript
/**
* A UTC label that may be a leap second.
*
* Temporal cannot represent a second of 60: `Temporal.Instant.from("2016-12-31T23:59:60.5Z")`
* clamps it to `…:59.5Z` (proposal-temporal `ParseISODateTime`). A reading keeps the clamped
* instant and a flag, so the inserted second (ITU-R TF.460-6 Annex 1 §2.2) and the second
* before it stay two different readings.
*/
export interface UtcReading {
/** For a leap reading, the instant of `…T23:59:59.f` (Temporal's clamp of `…:60.f`). */
readonly epochNanoseconds: bigint;
/** Whether the label's second field is 60. */
readonly secondSixty: boolean;
}
/** The last year this realm writes: its strings carry four-digit years only (a GMT rule). */
export declare const MAX_FOUR_DIGIT_YEAR = 9999;
/** 9999-12-31T23:59:59.999999999Z in epoch nanoseconds: the last UTC instant this realm writes. */
export declare const LAST_FOUR_DIGIT_UTC_NANOSECONDS = 253402300799999999999n;
/**
* Read a UTC instant string that may carry a second of 60.
*
* Checks shape only: an ordinary instant goes through `parseInstantNanoseconds`; a second-60
* instant in GMT's strict extended shape is read by `Temporal.Instant.from`, which clamps the
* second to 59. Whether that second 60 was a real leap second is `taiOfUtc`'s decision.
*
* @param value candidate ISO 8601 instant string
* @returns the reading, or null when `value` is not an instant string GMT reads
*/
export declare function parseUtcReading(value: unknown): UtcReading | null;
/**
* Write a UTC reading as an ISO 8601 instant string in `Z` form.
*
* - An ordinary reading is `Temporal.Instant#toString()`.
* - A second-60 reading is written `…T23:59:60[.fraction]Z` (ITU-R TF.460-6 Annex 3: "30 June,
* 23h 59m 60.6s UTC"), the fraction in Temporal's shortest digits.
* - Four-digit years only, as in the realm's time-scale strings (a GMT rule): a reading past
* 9999-12-31 is "", never Temporal's six-digit `+010000-…` form.
*
* @param reading the UTC reading
* @returns the instant string, or "" past year 9999 or when Temporal throws
*/
export declare function formatUtcReading(reading: UtcReading): string;
/**
* The wall clock of a second-60 label, `YYYY-MM-DDTHH:MM:60[.fraction]`, from the `…:59.f`
* instant Temporal clamps it to. Throws where Temporal throws, so callers call it inside `try`.
*
* @param nanoseconds the clamped `…:59.f` instant or label, in epoch nanoseconds
* @returns the wall clock with second 60 and no designator
*/
export declare function secondSixtyWallClock(nanoseconds: bigint): string;
/**
* The fraction of the second a nanosecond count falls in, written as Temporal writes a time's
* fraction: `""` for none, else `.` and the shortest digits (`".5"`, `".123456789"`).
*
* The sub-second count is split into milliseconds, microseconds and nanoseconds: passed as
* `nanosecond` alone, Temporal's default `overflow: "constrain"` clamps it to 999.
*
* @param nanoseconds epoch or label nanoseconds
* @returns the fraction, with its leading `.`, or ""
*/
export declare function subsecondFraction(nanoseconds: bigint): string;