intervalFromDurationTime
Signature
Section titled “Signature”intervalFromDurationTime(value: string, duration: string, anchor: "start" | "end", options?: { overflow?: Overflow; }): { start: string; end: string; }import { intervalFromDurationTime } from "@northguild/gmt/plain/interval";Construct a time 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.PlainTimehas no calendar, so adurationwith a nonzero years/months/weeks/days component cannot be resolved against a bare clock time — there is norelativeToto supply (mirrors A2/A3’s documentedrelativeTogap).Temporal.PlainTime.prototype.addsilently discards those fields rather than throwing, so this is checked explicitly and returns null.- A
durationthat wraps past midnight (e.g."23:00:00"+"PT2H") produces a span PlainTime can’t represent (no date component for the day rollover) and returns null, same as any other inverted span. overflow(“constrain” (default) | “reject”) is accepted for API consistency with siblingintervalFromDuration*functions, butPlainTimearithmetic always wraps around the clock rather than producing an out-of-range value, so it has no observable effect here (mirrorsaddTime’s own documented no-op).- Returns null on invalid input (unparseable
value, invalidduration, or ananchorother than"start"/"end").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO PlainTime string |
duration |
string |
ISO 8601 duration string |
anchor |
"start" | "end" |
“start” | “end” — which endpoint value represents |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
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”intervalFromDurationTime("12:00:00", "PT1H", "start") // { start: "12:00:00", end: "13:00:00" }intervalFromDurationTime("13:00:00", "PT1H", "end") // { start: "12:00:00", end: "13:00:00" }intervalFromDurationTime("12:00:00", "P1D", "start") // null (date units need relativeTo, unsupported)intervalFromDurationTime("23:00:00", "PT2H", "start") // null (wraps past midnight, inverted span)intervalFromDurationTime("invalid", "PT1H", "start") // null