intervalOverlappingDaysDate
Signature
Section titled “Signature”intervalOverlappingDaysDate(aStart: string, aEnd: string, bStart: string, bEnd: string): number | nullReturn how many distinct calendar dates two date intervals share.
- Half-open: an interval holds every date
dwithstart <= d < end. The count is the number of days in the intersection[max(aStart, bStart), min(aEnd, bEnd)), that ismin(aEnd, bEnd) - max(aStart, bStart)in days. - Touching intervals (
aEnd === bStart) share no day and count0; so does an empty interval. - Returns
0when the intervals share no day (a well-defined answer, not invalid input). - Returns
nullif either interval is invalid (start > end). - Returns
nullon invalid input (wrong type, malformed strings). - Accepts RFC 9557 calendar-annotated PlainDate strings — E5 (issue #78). All four arguments must name the same calendar (a bare ISO string names
iso8601); different calendars returnnull, as Temporal’suntilthrows whenCalendarEqualsis false. - Compatibility: before 1.16.0 arguments could name different calendars. Since 1.16.0 calendar strings are RFC 9557 (ISO digits,
[u-ca=<id>], canonical calendar ids); seeisValidCalendarDate.
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”number of shared calendar dates, 0 when disjoint, or null on invalid input
Examples
Section titled “Examples”import { intervalOverlappingDaysDate } from "@northguild/gmt/plain/interval";
intervalOverlappingDaysDate("2024-01-01", "2024-06-30", "2024-04-01", "2024-12-31") // 90 (04-01 up to, not including, 06-30)