Skip to content

clampInterval

clampInterval(interval: Interval, bounds: Interval): Interval | null

Return the part of interval that lies inside bounds, or null when none of it does.

  • Exactly intersectIntervals(interval, bounds): half-open, so an interval that only touches bounds clamps to null, as does an empty interval at an edge of bounds.
  • Endpoints are the caller’s own strings. Where an endpoint of interval and of bounds are the same instant, interval’s spelling is used (GMT rule: the first argument wins ties).
  • For zone-aligned bounds (a local business day), build them with floorToZone first.
  • Returns null on invalid input — either argument not an Interval, or inverted.
ParameterTypeDescription
intervalInterval{ start, end } record of ISO 8601 instant strings to clamp; its strings win ties
boundsInterval{ start, end } record of ISO 8601 instant strings to clamp into

{ start, end } inside bounds, or null when nothing remains or on invalid input

import { clampInterval } from "@northguild/gmt/interval/calculate";
clampInterval({ start: "2024-01-01T08:00:00Z", end: "2024-01-01T12:00:00Z" }, { start: "2024-01-01T09:00:00Z", end: "2024-01-01T17:00:00Z" }) // { start: "2024-01-01T09:00:00Z", end: "2024-01-01T12:00:00Z" }
output 

interval/calculate/clampInterval.ts