Skip to content

intervalFromDurationTime

intervalFromDurationTime(value: string, duration: string, anchor: "start" | "end"): { start: string; end: string; } | null

Construct a time interval from a single point plus an ISO 8601 duration, anchored at either end.

  • anchor: "start" treats value as the interval start and adds duration to get the end.
  • anchor: "end" treats value as the interval end and subtracts duration to get the start.
  • PlainTime has no calendar, so a duration with a nonzero years/months/weeks/days component cannot be resolved against a bare clock time — there is no relativeTo to supply (mirrors A2/A3’s documented relativeTo gap). Temporal.PlainTime.prototype.add silently 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 duration that crosses midnight (e.g. "23:00:00" + "PT2H"), any duration of 24 hours or more (e.g. "PT24H", even though the wrapped clock time looks valid), and any negative duration return 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): Temporal PlainTime#add/#subtract take no options.
  • Returns null on invalid input (unparseable value, invalid duration, or an anchor other than "start"/"end").
ParameterTypeDescription
valuestringISO PlainTime string
durationstringISO 8601 duration string
anchor"start" | "end"“start” | “end” — which endpoint value represents

{ start, end } with the constructed span, or null on invalid input

Members

MemberTypeDescription
startstringThe clock time the interval begins at, as an ISO 8601 time string with no date, offset or time zone.
endstringThe 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.
import { intervalFromDurationTime } from "@northguild/gmt/plain/interval";
intervalFromDurationTime("12:00:00", "PT1H", "start") // { start: "12:00:00", end: "13:00:00" }
output 

plain/interval/intervalFromDurationTime.ts