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.

28 lines • 1.33 kB
import { DateTimeDurationUnit } from "../../types/date-time-duration-units.js"; import { Overflow } from "../../types/overflow.js"; import "../../types/index.js"; /** * Add a temporal amount to a UTC datetime string and return a new UTC Instant string. * * - Uses Temporal.Instant.from to parse, adds duration, returns new Instant. * - Validates duration units and values. * - Returns "" for invalid input. * * @param value ISO UTC datetime string (e.g. "2024-03-10T12:00:00Z") * @param units Partial<Record<DateTimeDurationUnit, number>> object specifying units to add * @param options How an out-of-range result is handled * @returns UTC Instant string after addition, or "" on invalid input * * @example addUtc("2024-03-10T12:00:00Z", { days: 5 }) // "2024-03-15T12:00:00Z" * @example addUtc("2024-03-10T12:00:00Z", { months: 1, years: 1 }) // "2025-04-10T12:00:00Z" * @example addUtc("invalid", { days: 5 }) // "" */ export declare function addUtc(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/28 (TC39 Temporal); `"reject"` returns `""`. * * @defaultValue `"constrain"`, Temporal's default. */ overflow?: Overflow; }): string;