Skip to content

intervalFromDurationTime

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" 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.
  • A duration that 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 sibling intervalFromDuration* functions, but PlainTime arithmetic always wraps around the clock rather than producing an out-of-range value, so it has no observable effect here (mirrors addTime’s own documented no-op).
  • Returns null on invalid input (unparseable value, invalid duration, or an anchor other than "start"/"end").
Parameter Type Description
value string ISO PlainTime string
duration string ISO 8601 duration string
anchor "start" | "end" “start” | “end” — which endpoint value represents

options

Option Type Default
overflow? Overflow

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

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

plain/interval/intervalFromDurationTime.ts