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.

36 lines • 1.79 kB
import { Temporal } from "./temporal.js"; import { ZoneFrame } from "./zoneFrame.js"; import { UnixEpochUnit } from "./unixEpochValue.js"; export interface ResolvedUnixInterval { startVal: Temporal.ZonedDateTime; endVal: Temporal.ZonedDateTime; resolvedUnit: Temporal.DateTimeUnit; epochUnit: UnixEpochUnit; /** The frame both ends were placed on; `frameInstant` turns a result back into an instant. */ frame: ZoneFrame; } /** * Resolve the shared arguments of `intervalLengthUnix`, `intervalCountUnix` and * `splitIntervalByUnitUnix`: a non-reversed epoch pair in `epochUnit`, a singular-or-plural * `DateTimeUnit`, and the zone both ends are read in. * * - Epochs follow the one `unix/` grammar (`parseUnixEpochValue`) and must name Temporal instants. * - `epochUnit` defaults to `"milliseconds"`; `timeZone` defaults to `"UTC"` (`"local"` is the * system zone; a time zone identifier or a stored UTC offset `±HH:MM[:SS]` is read as written; * anything else is invalid). * - The ends are placed with `frameZoned`: for a seconds offset they sit in the offset's * whole-minute zone, moved by its seconds, to compute with and never to write. * * @param start interval start epoch * @param end interval end epoch * @param unit unit name, singular or plural * @param options optional `{ epochUnit, timeZone }` * @returns the zoned ends, singular unit, epoch unit and frame, or null on invalid input * * @example resolveUnixIntervalPair(0, 86400, "days", { epochUnit: "seconds" })?.resolvedUnit // "day" * @example resolveUnixIntervalPair(10, 0, "day") // null (reversed) */ export declare function resolveUnixIntervalPair(start: unknown, end: unknown, unit: unknown, options?: { epochUnit?: unknown; timeZone?: unknown; }): ResolvedUnixInterval | null;