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.

41 lines • 2.36 kB
import { Temporal } from "./temporal.js"; /** Days in an ISO week. */ export declare const ISO_WEEKDAYS = 7; /** * TC39 `ISODateWithinLimits`: -271821-04-19 and +275760-09-13, counted in days from 1970-01-01, * are the first and last dates a PlainDate holds. */ export declare const MIN_EPOCH_DAY = -100000001; export declare const MAX_EPOCH_DAY = 100000000; /** * Days from 1970-01-01 to an ISO date, in the proleptic Gregorian calendar of ECMA-262 §21.4.1 * that Temporal's ISO calendar extends. Years run from March so the leap day ends each one. */ export declare function epochDayOf(year: number, month: number, day: number): number; /** The ISO year, month and day `epochDay` days from 1970-01-01 — `epochDayOf` inverted. */ export declare function isoFieldsOf(epochDay: number): [number, number, number]; /** `Temporal.PlainDate#toString` for an ISO date: the format `mergeCalendars` returns its holidays in. */ export declare function isoDateString(epochDay: number): string; /** * Days from 1970-01-01 to `date`, an ISO-calendar date. Any other calendar throws a * `RangeError`, which callers turn into their sentinel: its year, month and day are not ISO * fields, so the arithmetic below would silently walk from the wrong day. */ export declare function epochDayOfDate(date: Temporal.PlainDate): number; /** * ISO weekday of an epoch day, Monday 1 to Sunday 7. Follows ECMA-262 `WeekDay` (day 0, 1970-01-01, * is a Thursday) renumbered as Temporal's `ISODayOfWeek` does, Sunday 7 rather than 0. */ export declare function isoWeekdayOf(epochDay: number): number; /** Index of the first element of `days` (sorted ascending) that is >= `epochDay`. */ export declare function lowerBound(days: Int32Array, epochDay: number): number; /** Members of `days` (sorted ascending) within [from, to]; 0 when from > to. */ export declare function countWithin(days: Int32Array, from: number, to: number): number; /** True when `epochDay` is a member of `days` (sorted ascending). */ export declare function hasEpochDay(days: Int32Array, epochDay: number): boolean; /** * `days` ascending with repeats removed. Returns `days` itself when it is already strictly * ascending, so a list written in date order costs one pass and no copy; otherwise sorts a copy * numerically. */ export declare function sortedUnique(days: Int32Array): Int32Array;