@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
23 lines (22 loc) • 1.16 kB
TypeScript
import type { DateTimeDurationUnit, Overflow } from "../../types/index.js";
/**
* Return a PlainDateTime ISO string with `units` subtracted from `value`.
*
* - Validates `value`, `units`, and `amount` before performing the subtract.
* - Returns "" for invalid inputs.
*
* `overflow` ("constrain" (default) | "reject") controls out-of-range results, e.g. subtracting
* 1 month from Mar 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 subtract
* @param options optional: overflow ("constrain" | "reject")
* @returns ISO PlainDateTime string after subtraction, or "" on invalid input
*
* @example subtractDateTime("2024-03-15T12:00:00", { days: 5 }) // "2024-03-10T12:00:00"
* @example subtractDateTime("invalid", { days: 5 }) // ""
* @example subtractDateTime("2024-03-31T12:00:00", { months: 1 }, { overflow: "reject" }) // ""
*/
export declare function subtractDateTime(value: string, units: Partial<Record<DateTimeDurationUnit, number>>, options?: {
overflow?: Overflow;
}): string;