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.

39 lines • 2.63 kB
import { Temporal } from "../temporal.js"; import { ArithmeticModel, ArithmeticOverflow, DateDurationFields } from "./nonIsoArithmetic.js"; export type CalendarDateUnit = "year" | "month" | "week" | "day"; /** The arithmetic model `calendarId` is computed with: the owned one where active, else the read-backed one. */ export declare function arithmeticModelFor(calendarId: string): ArithmeticModel; /** * `one.until(two, { largestUnit })`'s date fields, made correct where `@js-temporal/polyfill` is not * (TC39 `CalendarDateUntil`, Intl era/monthCode proposal `NonISODateUntil`). Both dates must carry * the same calendar. * * - `iso8601` is the polyfill's own `until`, untouched. * - `"day"` / `"week"` are ISO `until`: days do not depend on the calendar. * - D6/D7: the polyfill answers first; while its probe fails, the answer is kept only when it is * exactly the spec's (`isNonIsoDateUntilResult`), otherwise the spec loops recompute it. * - D1: a polyfill RangeError near a range limit is answered by the spec loops. * - D2/D3/D4/D5: in a corrected range the spec loops run over ISO (buddhist) or the owned Hebrew * and Indian arithmetic. * - D9: months counted across `LARGE_MONTH_SPAN` months or more run the spec loops, whose month * counts are bounded. * - D18: an Islamic year the polyfill cannot return from (<= 1 in WebKit) at either end runs the * spec loops over the read-backed model, without asking the polyfill. */ export declare function calendarDateUntil(one: Temporal.PlainDate, two: Temporal.PlainDate, largestUnit: CalendarDateUnit): DateDurationFields; /** * `date.add(duration, { overflow })`, made correct where `@js-temporal/polyfill` is not (TC39 * `CalendarDateAdd`, Intl era/monthCode proposal `NonISODateAdd`). * * - `iso8601` is the polyfill's own `add`, untouched. * - Weeks and days alone are ISO day arithmetic. * - D1: a polyfill RangeError near a range limit is answered by the spec algorithm. * - D2/D3/D4/D5: in a corrected range the spec algorithm runs over ISO (buddhist) or the owned * Hebrew and Indian arithmetic. * - D9: `LARGE_MONTH_SPAN` months or more run the spec algorithm, whose month jumps are bounded. * - D18: a sum that may reach an Islamic year the polyfill cannot return from (<= 1 in WebKit) * runs the spec algorithm over the read-backed model, without asking the polyfill. * * @returns a PlainDate in `date`'s calendar; throws RangeError out of range or on `reject` */ export declare function calendarDateAdd(date: Temporal.PlainDate, duration: Partial<DateDurationFields>, overflow: ArithmeticOverflow): Temporal.PlainDate;