UNPKG

@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.

67 lines • 3.27 kB
import { ZoneFrame } from "./zoneFrame.js"; import { WallClassification } from "./earlierOccurrence.js"; import { LocalMoment } from "./recurrenceExpansion.js"; /** * How a local wall time reads in a zone: the instant each disambiguation takes and, for a repeated * or skipped time, the offset change between them. */ export type ResolvedLocal = { /** Whether the wall time is one instant, a repeated one or a skipped one. */ kind: WallClassification; /** The instant `"earlier"` gives, in epoch nanoseconds. */ earlier: bigint; /** The instant `"later"` gives, in epoch nanoseconds. */ later: bigint; /** The offset change between `earlier` and `later` (`earlier < transition <= later`), or null when unique. */ transition: bigint | null; }; /** A window as `expandRecurrence` reads it: an interval, or the first `count` after an instant. */ export type OccurrenceWindowNanoseconds = { kind: "interval"; start: bigint; end: bigint; } | { kind: "after"; after: bigint; count: number; }; /** * Read an `OccurrenceWindow` once. * * @param window the caller's window * @returns the window in epoch nanoseconds, or null when it is neither an interval with * `start <= end` nor `{ after, count }` with an integer `count` from 1 to 10,000 * * @example readOccurrenceWindow({ after: "1970-01-01T00:00:00Z", count: 2 }) // { kind: "after", after: 0n, count: 2 } * @example readOccurrenceWindow({ after: "1970-01-01T00:00:00Z", count: 0 }) // null */ export declare function readOccurrenceWindow(window: unknown): OccurrenceWindowNanoseconds | null; /** A local moment read as UTC, in epoch nanoseconds. */ export declare function localNanoseconds(moment: LocalMoment): bigint; /** * Build a function that places local moments in a zone. * * Meant for moments in ascending order, as the expansion visits them: a cursor walks the zone's * offset changes forward, so the cost is one offset lookup per change rather than per moment. * A moment more than eight days past the next change starts the cursor again near it, so a moment * costs a few lookups however many changes lie between it and the one before. * A moment that is not within two days of a change is placed with plain arithmetic; one that is * goes to `classifyWall` (TC39 disambiguation). A moment before the cursor starts it again, so * order costs speed, never correctness. * * @param frame the zone, from `zoneFrame`; a stored offset (seconds, or a fixed-offset zone) makes every moment unique * @returns the placing function; it throws what Temporal throws for a moment outside its range * * @example createLocalResolver({ timeZone: "UTC", shiftNanoseconds: 0n })({ day: 0, second: 0 }).earlier // 0n */ export declare function createLocalResolver(frame: ZoneFrame): (moment: LocalMoment) => ResolvedLocal; /** * Place one local moment in a zone, for a wall time that arrives out of order (an `RDATE`). * * @param frame the zone, from `zoneFrame` * @param moment the local moment * @returns how the moment reads in the zone * * @example resolveLocalMoment({ timeZone: "UTC", shiftNanoseconds: 0n }, { day: 0, second: 60 }).earlier // 60000000000n */ export declare function resolveLocalMoment(frame: ZoneFrame, moment: LocalMoment): ResolvedLocal;