addUtc
Signature
Section titled “Signature”addUtc(value: string, units: Partial<Record<keyof DurationLike, number>>, options?: { overflow?: "reject" | "constrain" | undefined; }): stringAdd 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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO UTC datetime string (e.g. “2024-03-10T12:00:00Z”) |
units | Partial<Record<keyof DurationLike, number>> | Partial<Record<DateTimeDurationUnit, number>> object specifying units to add |
Options
Section titled “Options”options
How an out-of-range result is handled
| Option | Type | Default | Description |
|---|---|---|---|
overflow? | "reject" | "constrain" (Overflow) | "constrain", Temporal’s default. | 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 "". |
Returns
Section titled “Returns”UTC Instant string after addition, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { addUtc } from "@northguild/gmt/utc/calculate";
addUtc("2024-03-10T12:00:00Z", { days: 5 }) // "2024-03-15T12:00:00Z"