Skip to content

intervalSplitAtDate

intervalSplitAtDate(start: string, end: string, points: string[]): { start: string; end: string; }[]

Split a date interval at arbitrary points, producing consecutive sub-intervals.

  • points need not be sorted — they are sorted internally before splitting.
  • Points before start or after end are dropped; they cannot introduce a boundary that isn’t inside the interval.
  • Points exactly on start or end are dropped too — they would only produce a zero-length sub-interval at the edge; intervalDivideEquallyDate’s zero-length case is the deliberate way to express one, not intervalSplitAtDate.
  • Duplicate points collapse to a single boundary.
  • Returns consecutive { start, end } records, each record’s end equal to the next record’s start.
  • Every piece is half-open [start, end): a boundary belongs only to the piece that starts there, so the pieces share no value and together cover the interval exactly once (the rule CORE-6’s splitIntervalAt uses).
  • Returns [{ start, end }] (the whole interval, unsplit) when no valid in-range point remains.
  • A piece’s end equals its start only when the interval itself is zero-length (start equal to end): the result is then that one empty piece, whatever the points.
  • Returns [] when points is not an array, when any element is not a valid ISO PlainDate string, or on invalid input (unparseable start/end, start > end).
  • Accepts RFC 9557 calendar-annotated PlainDate strings — E5 (issue #78). start, end, and every element of points must carry the same calendar tag (or all be bare ISO); any mismatch returns [] (E5 decision of record D4) — this also makes .equals()’s dedup of duplicate points safe, since same-calendar PlainDates compare equal correctly.
ParameterTypeDescription
startstringISO PlainDate string for the interval start, optionally calendar-annotated
endstringISO PlainDate string for the interval end, optionally calendar-annotated
pointsstring[]array of ISO PlainDate strings to split at, optionally calendar-annotated (must match start/end’s calendar)

array of { start, end } records, or [] on invalid input / mismatched calendars

Members of each item

MemberTypeDescription
startstringThe date the interval begins on, as an ISO 8601 date (YYYY-MM-DD). It keeps a calendar annotation such as [u-ca=hebrew] when the inputs carry one.
endstringThe first date 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 { intervalSplitAtDate } from "@northguild/gmt/plain/interval";
intervalSplitAtDate("2024-01-01", "2024-01-10", ["2024-01-05"]) // [{ start: "2024-01-01", end: "2024-01-05" }, { start: "2024-01-05", end: "2024-01-10" }]
points
output 

plain/interval/intervalSplitAtDate.ts