@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.
20 lines • 1.31 kB
TypeScript
import { Temporal } from "./temporal.js";
/**
* `date.add(duration, { overflow })` for a PlainDate in any calendar.
*
* - `iso8601` is the polyfill's own `add`, untouched.
* - Other calendars go through the Temporal compat layer's `calendarDateAdd` (CORE-6: the polyfill's
* calendar add throws near the range limits and is wrong in the corrected calendar ranges). Time
* fields become whole days exactly as TC39 `ToDateDurationRecordWithoutTime` does: the time
* duration in nanoseconds, truncated toward zero to 24-hour days, added to `days`.
* - The duration is validated by `Temporal.Duration.from`, as `add` itself does.
*
* @param date PlainDate to add to
* @param duration a DurationLike (negate it to subtract)
* @param overflow "constrain" (default, as in Temporal) | "reject"
* @returns the resulting PlainDate in `date`'s calendar; throws on invalid input or out of range
*
* @example plainDateAdd(Temporal.PlainDate.from("2024-01-31"), { months: 1 }, "constrain").toString() // "2024-02-29"
* @example plainDateAdd(Temporal.PlainDate.from("2024-01-31"), { months: 1 }, "reject") // throws RangeError
*/
export declare function plainDateAdd(date: Temporal.PlainDate, duration: Temporal.Duration | Temporal.DurationLike, overflow?: "constrain" | "reject"): Temporal.PlainDate;