intervalFromDurationTime
Signature
Section titled “Signature”intervalFromDurationTime(value: string, duration: string, anchor: "start" | "end"): { start: string; end: string; } | nullConstruct 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.- The span must fit inside one day in the anchored direction. A
durationthat crosses midnight (e.g."23:00:00"+"PT2H"), anydurationof 24 hours or more (e.g."PT24H", even though the wrapped clock time looks valid), and any negativedurationreturn null — PlainTime has no date component for the day rollover. The span is measured exactly in nanoseconds, not by comparing wrapped clock times. - There is no options argument (its only member,
overflow, was removed in 1.16.0): TemporalPlainTime#add/#subtracttake no options. - 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 |
Returns
Section titled “Returns”{ start, end } with the constructed span, or null on invalid input
Members
| Member | Type | Description |
|---|---|---|
start | string | The clock time the interval begins at, as an ISO 8601 time string with no date, offset or time zone. |
end | string | The first clock time after the interval, in the same format as start. It is exclusive: the interval holds everything from start up to but not including this value. It can equal start, which makes the interval empty. |
Examples
Section titled “Examples”import { intervalFromDurationTime } from "@northguild/gmt/plain/interval";
intervalFromDurationTime("12:00:00", "PT1H", "start") // { start: "12:00:00", end: "13:00:00" }