Skip to content

intervalIntersectionTime

intervalIntersectionTime(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; }
import { intervalIntersectionTime } from "@northguild/gmt/plain/interval";

Return the overlapping span of two time intervals, or null when they do not overlap.

  • Uses Temporal.PlainTime.compare for comparison.
  • Adjacent intervals (e.g. aEnd === bStart) share one instant and DO overlap.
  • Returns null if either interval is invalid (start > end).
  • Returns null on invalid input (wrong type, malformed strings).
Parameter Type Description
aStart string ISO 8601 time string for the first interval start
aEnd string ISO 8601 time string for the first interval end
bStart string ISO 8601 time string for the second interval start
bEnd string ISO 8601 time string for the second interval end

{ start, end } with the overlapping span, or null on invalid input / no overlap

intervalIntersectionTime("09:00:00", "17:00:00", "12:00:00", "18:00:00") // { start: "12:00:00", end: "17:00:00" }
intervalIntersectionTime("09:00:00", "17:00:00", "17:00:00", "18:00:00") // { start: "17:00:00", end: "17:00:00" }
intervalIntersectionTime("09:00:00", "17:00:00", "18:00:00", "20:00:00") // null
intervalIntersectionTime("09:00:00", "17:00:00", "10:00:00", "11:00:00") // { start: "10:00:00", end: "11:00:00" }
intervalIntersectionTime("invalid", "17:00:00", "12:00:00", "18:00:00") // null

plain/interval/intervalIntersectionTime.ts