Skip to content

splitIntervalAt

splitIntervalAt(interval: Interval, boundaries: string[]): Interval[]

Split a half-open interval at instant boundaries into consecutive half-open pieces.

  • Each piece’s end is the next piece’s start; under [start, end) the pieces share no instant and together cover the interval exactly once.
  • boundaries may be unsorted. Boundaries at or outside the interval’s edges are dropped, so no piece is empty; duplicate instants keep their first occurrence’s spelling (GMT rule).
  • Endpoints are the caller’s own strings: the interval’s own start/end, and each boundary exactly as passed.
  • Splitting an empty interval returns it unchanged, as a single piece.
  • Never returns [] for valid input — that is the invalid-input sentinel alone.
  • To split at zone-aligned boundaries (local midnights), build them with floorToZone or bucketRange first.
  • Returns [] when interval is not a valid Interval, boundaries is not an array, or any boundary is not an ISO 8601 instant string — even one outside the interval.
ParameterTypeDescription
intervalInterval{ start, end } record of ISO 8601 instant strings to split
boundariesstring[]array of ISO 8601 instant strings to split at

consecutive { start, end } pieces covering interval, or [] on invalid input

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

interval/calculate/splitIntervalAt.ts