@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.
33 lines • 1.78 kB
TypeScript
import { TimestampClass } from "../types/transport-timestamps.js";
import "../types/index.js";
/** A validated `TimestampEvent`, with both of its moments as epoch nanoseconds. */
export type ParsedTimestampEvent = {
classifier: TimestampClass;
/** The event's `at`, exactly as the caller wrote it. */
at: string;
atNanoseconds: bigint;
recordedNanoseconds: bigint;
};
/**
* Validate a list of `TimestampEvent`s and put them in recording order, or `null`.
*
* The shared reading behind `bestAvailable` and `estimateDrift`:
*
* - Every event must be an object whose `classifier` is exactly `PLN`, `EST`, `REQ` or `ACT` and
* whose `at` and `recordedAt` are instants (`Z`/offset) or zoned strings, read as
* `parseInstantNanoseconds` reads them: the offset fixes the instant, a minute-rounded offset
* is read as its bracketed zone's real offset, and the bracket is otherwise not checked. One
* invalid event makes the whole list invalid.
* - The result is sorted by `recordedAt`, earliest first. Events recorded at the same instant
* keep their input order, so of two ties the later index is the later record.
* - `at` is kept exactly as written, so a caller can echo it.
* - An empty list is `[]`; the caller decides what that means.
* - A hostile value (a throwing getter, a revoked Proxy) is invalid input: `null`, never a throw.
*
* @param events candidate list of timestamp events
* @returns the events in recording order with their instants, or null on invalid input
*
* @example parseTimestampEvents([]) // []
* @example parseTimestampEvents([{ classifier: "ETA", at: "2024-06-15T12:00:00Z", recordedAt: "2024-06-15T10:00:00Z" }]) // null
*/
export declare function parseTimestampEvents(events: unknown): ParsedTimestampEvent[] | null;