intervalOverlappingDaysUnix
Signature
Section titled “Signature”intervalOverlappingDaysUnix(aStart: string | number, aEnd: string | number, bStart: string | number, bEnd: string | number, options?: { epochUnit?: "seconds" | "milliseconds"; timeZone?: string; }): numberimport { intervalOverlappingDaysUnix } from "@northguild/gmt/unix/interval";Return how many distinct calendar dates two Unix epoch intervals share, in a given
- time zone.
- Counts the number of local dates touched by the closed intersection
[max(aStart, bStart), min(aEnd, bEnd)]— inclusive of both endpoints. - Uses the system timeZone by default (consistent with
addUnixandintervalCountUnix), so day counts are host-dependent unlesstimeZoneis given. - Adjacent intervals (e.g.
aEnd === bStart) share one date and count as1. - Returns
0when the intervals do not overlap at all (a well-defined answer, not invalid input). - Returns
nullif either interval is invalid (start > end). - Returns
nullon invalid input (non-finite/non-integer epoch values, invalid timeZone). - Diverges from date-fns’s
getOverlappingDaysInIntervals, which rounds up elapsed 24-hour periods instead of counting calendar dates. To reproduce date-fns’s number, composeintervalIntersectionUnixwithintervalCountUnix:const span = intervalIntersectionUnix(aStart, aEnd, bStart, bEnd); span ? intervalCountUnix(span.start, span.end, "day") : 0;
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
aStart |
string | number |
Unix epoch value (seconds or milliseconds) — first interval start |
aEnd |
string | number |
Unix epoch value (seconds or milliseconds) — first interval end |
bStart |
string | number |
Unix epoch value (seconds or milliseconds) — second interval start |
bEnd |
string | number |
Unix epoch value (seconds or milliseconds) — second interval end |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
epochUnit? |
"seconds" | "milliseconds" |
— |
timeZone? |
string |
— |
Returns
Section titled “Returns”number of shared calendar dates, 0 when disjoint, or null on invalid input
Examples
Section titled “Examples”intervalOverlappingDaysUnix(0, 172800000, 86400000, 259200000, { timeZone: "UTC" }) // 2intervalOverlappingDaysUnix(0, 86400000, 86400000, 172800000, { timeZone: "UTC" }) // 1 (adjacent)intervalOverlappingDaysUnix(0, 86400000, 172800000, 259200000, { timeZone: "UTC" }) // 0 (disjoint)intervalOverlappingDaysUnix(NaN, 172800000, 86400000, 259200000, { timeZone: "UTC" }) // null