intervalFromDurationZoned
Signature
Section titled “Signature”intervalFromDurationZoned(value: string, duration: string, anchor: "start" | "end", options?: { disambiguation?: Disambiguation; offset?: Offset; overflow?: Overflow; }): { start: string; end: string; }import { intervalFromDurationZoned } from "@northguild/gmt/zoned/interval";Construct a zoned interval from a single point plus an ISO 8601 duration, anchored at either end.
anchor: "start"treatsvalueas the interval start and addsdurationto get the end.anchor: "end"treatsvalueas the interval end and subtractsdurationto get the start.- Uses
Temporal.ZonedDateTime.prototype.add/.subtract, so calendar units (years/months/weeks) resolve againstvalueitself — no separaterelativeTois needed. disambiguationcontrols DST resolution ONLY when the arithmetic result lands on an ambiguous local time from a fall-back (DST-end) overlap: “compatible” (default), “earlier”, “later”, or “reject” (returns null). MirrorsaddZoned’s exact semantics — has no effect on a spring-forward (DST-start) gap landing, which Temporal’s arithmetic always resolves before disambiguation runs.offsetis accepted for API consistency withaddZonedbut has no effect here for the same reason documented there: the disambiguation rebuild has no stored offset to prefer/use/ignore/reject.- A negative
duration(e.g."-P1D") can invert the computed span; returns null when that happens, mirroringintervalIntersectionZoned’sstart > endrejection. overflow(“constrain” (default) | “reject”) controls out-of-range results, e.g. adding 1 month to Jan 31: “constrain” clamps to Feb 29/28, “reject” returns null.- Accepts a GMT calendar-annotated zoned string (as produced by
convertZonedToCalendar) as well as a bare ISO one — E7 (issue #152). Calendar units indurationresolve against that calendar, and both returned endpoints are re-derived in it viaformatZonedInCalendar. There is only ONE calendar-tagged input here, so no D5 pair policy applies — nothing can mismatch. - Returns null on invalid input (unparseable
value, invalidduration, or ananchorother than"start"/"end").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO 8601 zoned datetime string, optionally calendar-annotated |
duration |
string |
ISO 8601 duration string |
anchor |
"start" | "end" |
“start” | “end” — which endpoint value represents |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
disambiguation? |
Disambiguation |
— |
offset? |
Offset |
— |
overflow? |
Overflow |
— |
Returns
Section titled “Returns”{ start, end } with the constructed span, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”intervalFromDurationZoned("2024-01-01T00:00:00+00:00[UTC]", "P1D", "start") // { start: "2024-01-01T00:00:00+00:00[UTC]", end: "2024-01-02T00:00:00+00:00[UTC]" }intervalFromDurationZoned("2024-01-02T00:00:00+00:00[UTC]", "P1D", "end") // { start: "2024-01-01T00:00:00+00:00[UTC]", end: "2024-01-02T00:00:00+00:00[UTC]" }intervalFromDurationZoned("2024-11-02T01:30:00-04:00[America/New_York]", "P1D", "start", { disambiguation: "later" }) // { start: "2024-11-02T01:30:00-04:00[America/New_York]", end: "2024-11-03T01:30:00-05:00[America/New_York]" } (fall-back overlap resolved; default "compatible" would return the -04:00 instant instead)intervalFromDurationZoned("2024-01-31T12:00:00-05:00[America/New_York]", "P1M", "start", { overflow: "reject" }) // nullintervalFromDurationZoned("invalid", "P1D", "start") // null