addDateTime
Signature
Section titled “Signature”addDateTime(value: string, units: Partial<Record<DateTimeDurationUnit, number>>, options?: { overflow?: Overflow; }): stringimport { addDateTime } from "@northguild/gmt/plain/calculate";Return a PlainDateTime ISO string with units added to value.
- Validates
value,units, andamountbefore 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 “”).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO PlainDateTime string |
units |
Partial<Record<DateTimeDurationUnit, number>> |
Partial<Record<DateTimeDurationUnit, number>> object specifying units to add |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
overflow? |
Overflow |
— |
Returns
Section titled “Returns”ISO PlainDateTime string after addition, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”addDateTime("2024-03-10T12:00:00", { days: 5 }) // "2024-03-15T12:00:00"addDateTime("invalid", { days: 5 }) // ""addDateTime("2024-01-31T12:00:00", { months: 1 }, { overflow: "reject" }) // ""