intervalIntersectionDate
Signature
Section titled “Signature”intervalIntersectionDate(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; }import { intervalIntersectionDate } from "@northguild/gmt/plain/interval";Return the overlapping span of two date intervals, or null when they do not overlap.
- Uses
Temporal.PlainDate.comparefor comparison. - Adjacent intervals (e.g.
aEnd === bStart) share one instant and DO overlap. - Returns
nullif either interval is invalid (start > end). - Returns
nullon invalid input (wrong type, malformed strings). - Accepts GMT calendar-annotated PlainDate strings — E5 (issue #78). Since the result is a date value, all four arguments must carry the same calendar tag (or all be bare ISO); a mismatch returns
null(E5 decision of record D4). The output’s tag is re-derived from the intersection span, never copied from an input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
aStart |
string |
ISO 8601 date string for the first interval start, optionally calendar-annotated |
aEnd |
string |
ISO 8601 date string for the first interval end, optionally calendar-annotated |
bStart |
string |
ISO 8601 date string for the second interval start, optionally calendar-annotated |
bEnd |
string |
ISO 8601 date string for the second interval end, optionally calendar-annotated |
Returns
Section titled “Returns”{ start, end } with the overlapping span, or null on invalid input / no overlap / mismatched calendars
Examples
Section titled “Examples”intervalIntersectionDate("2024-01-01", "2024-06-30", "2024-04-01", "2024-12-31") // { start: "2024-04-01", end: "2024-06-30" }intervalIntersectionDate("2024-01-01", "2024-06-30", "2024-06-30", "2024-12-31") // { start: "2024-06-30", end: "2024-06-30" }intervalIntersectionDate("2024-01-01", "2024-06-30", "2024-07-01", "2024-12-31") // nullintervalIntersectionDate("2024-01-01", "2024-06-30", "2024-02-01", "2024-03-01") // { start: "2024-02-01", end: "2024-03-01" }intervalIntersectionDate("invalid", "2024-06-30", "2024-04-01", "2024-12-31") // null