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.

27 lines • 1.24 kB
import { DateTimeDurationUnit } from "../../types/date-time-duration-units.js"; import { Overflow } from "../../types/overflow.js"; import "../../types/index.js"; /** * Return a PlainDateTime ISO string with `units` added to `value`. * * - Validates `value`, `units`, and `amount` before performing the add. * - Returns "" for invalid inputs. * * @param value ISO PlainDateTime string * @param units Partial<Record<DateTimeDurationUnit, number>> object specifying units to add * @param options How an out-of-range result is handled * @returns ISO PlainDateTime string after addition, or "" on invalid input * * @example addDateTime("2024-03-10T12:00:00", { days: 5 }) // "2024-03-15T12:00:00" * @example addDateTime("invalid", { days: 5 }) // "" * @example addDateTime("2024-01-31T12:00:00", { months: 1 }, { overflow: "reject" }) // "" */ export declare function addDateTime(value: string, units: Partial<Record<DateTimeDurationUnit, number>>, options?: { /** * What to do when the result is not a real date. `"constrain"` clamps it to the last valid day, * so Jan 31 + 1 month is Feb 29 or 28; `"reject"` returns `""`. * * @defaultValue `"constrain"`, Temporal's default. */ overflow?: Overflow; }): string;