subtractDate
Signature
Section titled “Signature”subtractDate(value: string, units: Partial<Record<DateDurationUnit, number>>, options?: { overflow?: Overflow; }): stringimport { subtractDate } from "@northguild/gmt/plain/calculate";Return a PlainDate ISO string with units subtracted from value.
- Validates
value,units, andamountbefore performing the subtract. - Accepts a GMT calendar-annotated PlainDate string (as produced by
convertDateToCalendar), not just a bare ISO string — E5 (issue #78). SeeaddDate’s JSDoc for the full calendar-unit arithmetic rationale (leap months/years, era transitions, theoverflowasymmetry); this function is the mirror image (.subtractinstead of.add). - 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 “”).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO PlainDate string, optionally calendar-annotated |
units |
Partial<Record<DateDurationUnit, number>> |
Partial<Record<DateDurationUnit, number>> object specifying units to subtract |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
overflow? |
Overflow |
— |
Returns
Section titled “Returns”ISO PlainDate string after subtraction, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”subtractDate("2024-03-15", { day: 5 }) // "2024-03-10"subtractDate("invalid", { day: 5 }) // ""subtractDate("2024-03-31", { months: 1 }, { overflow: "reject" }) // ""subtractDate("5784-07-15[u-ca=hebrew]", { months: 1 }) // "5784-06-15[u-ca=hebrew]" (Adar -> Adar I)