@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
23 lines (22 loc) • 1.11 kB
TypeScript
import type { DateTimeDurationUnit, Overflow } from "../../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.
*
* `overflow` ("constrain" (default) | "reject") controls out-of-range results, e.g. adding 1 month
* to Jan 31: "constrain" clamps to Feb 29/28, "reject" throws (resulting in "").
*
* @param value ISO PlainDateTime string
* @param units Partial<Record<DateTimeDurationUnit, number>> object specifying units to add
* @param options optional: overflow ("constrain" | "reject")
* @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?: {
overflow?: Overflow;
}): string;