@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.
63 lines • 3.02 kB
TypeScript
import { Temporal } from "./temporal.js";
import { RollConvention } from "../types/roll-convention.js";
import "../types/index.js";
import { ResolvedBusinessCalendar } from "./businessCalendar.js";
import { ZoneFrame } from "./zoneFrame.js";
/**
* What every cut-off in a stack shares: the zone it is read in and, when it rolls, the parsed
* calendar and the convention. `rolling` is present exactly when a calendar and a convention
* are.
*/
export type SharedCutoffOptions = {
timeZone: string;
/** The zone built once, so a wall time never re-parses it. */
frame: ZoneFrame;
rolling: {
calendar: ResolvedBusinessCalendar;
roll: RollConvention;
} | null;
};
/**
* Validate the options a whole stack shares, parsing the calendar once.
*
* @param timeZone the zone the cut-offs are read in
* @param calendar the working week and holidays, or `undefined`
* @param roll the roll convention, or `undefined`
* @returns the shared options, or `null` when any is invalid, or only one of `calendar` and
* `roll` is given (no standard supplies either one by default)
*
* @example resolveSharedCutoffOptions("Europe/Amsterdam", undefined, undefined) // { timeZone: "Europe/Amsterdam", rolling: null }
* @example resolveSharedCutoffOptions("Europe/Amsterdam", undefined, "preceding") // null (a roll needs a calendar)
* @example resolveSharedCutoffOptions("Not/AZone", undefined, undefined) // null
*/
export declare function resolveSharedCutoffOptions(timeZone: unknown, calendar: unknown, roll: unknown): SharedCutoffOptions | null;
/**
* Validate an entry's local time of day.
*
* @param atLocalTime the local time of day, or `undefined` for none
* @returns `{ time }` (`time` is `null` for none), or `null` when it is not a valid time
*
* @example resolveCutoffTime("17:00") // { time: PlainTime 17:00 }
* @example resolveCutoffTime(undefined) // { time: null }
* @example resolveCutoffTime("25:00") // null
*/
export declare function resolveCutoffTime(atLocalTime: unknown): {
time: Temporal.PlainTime | null;
} | null;
/**
* One cut-off over options already validated: the deadline `duration` before `anchor`, as
* `cutoffAt` defines it.
*
* @param anchor the event the deadline counts back from
* @param duration the offset before the anchor
* @param atLocalTime the local time of day to pin to, or `null` for none
* @param shared the zone and roll the whole stack shares
* @returns the cut-off as a zoned string and its epoch nanoseconds, or `null` when it falls in
* a skipped local hour or the roll runs out
*
* @example cutoffAtResolved(Temporal.Instant.from("2024-06-14T16:00:00Z"), Temporal.Duration.from("P2D"), Temporal.PlainTime.from("17:00"), { timeZone: "Europe/Amsterdam", rolling: null })?.text // "2024-06-12T17:00:00+02:00[Europe/Amsterdam]"
*/
export declare function cutoffAtResolved(anchor: Temporal.Instant, duration: Temporal.Duration, atLocalTime: Temporal.PlainTime | null, shared: SharedCutoffOptions): {
text: string;
ns: bigint;
} | null;