intervalOverlappingDaysUnix
Signature
Section titled “Signature”intervalOverlappingDaysUnix(aStart: string | number, aEnd: string | number, bStart: string | number, bEnd: string | number, options?: { epochUnit?: UnixUnit; timeZone?: string; }): number | nullReturn how many distinct calendar dates two Unix epoch intervals share, in a given time zone.
- Counts the local dates that hold at least one instant of the half-open intersection
[max(aStart, bStart), min(aEnd, bEnd)). The end is excluded, so an intersection ending at local midnight does not touch the date that midnight starts. - Each instant in the intersection contributes its own local date in
timeZone, and each date counts once. A date the zone deleted is not counted (Pacific/Apiaskipped 2011-12-30), and a fall-back into the previous date does not lose that date (America/Goose_Bay, 2010-11-07). - Returns
nullwhen the intersection crosses more than 10,000 zone transitions (the same cap asintervalCountZoned). - Compatibility: before 1.16.0 the count was the calendar difference of the two endpoint dates plus one. To get that number for overlapping intervals, with
start/endthe intersection:diffDate(convertUnixToPlainDate(start, { timeZone }), convertUnixToPlainDate(end, { timeZone }), "days") + 1. - Returns
0when the intersection is empty (a well-defined answer, not invalid input): when the intervals are disjoint, when they touch (e.g.aEnd === bStart), or when either is empty. - Returns
nullif either interval is invalid (start > end). - Returns
nullon invalid input (epoch values that are not safe integers or numeric strings of one — fractions, empty strings and values beyond ±(2^53 − 1) are invalid — or an 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; - Limit at an offset with seconds. The instant is placed in the offset’s whole-minute zone, moved by its seconds, and the moved instant must be inside Temporal’s range. So within the offset’s seconds (under a minute) of the last instant Temporal supports (
+275760-09-13T00:00:00Z) for an offset east of UTC, or of the first (-271821-04-20T00:00:00Z) for one west, this returnsnull. An offset to the minute has no such limit.
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
optional: how the epochs are read and the zone the dates are counted in
| Option | Type | Default | Description |
|---|---|---|---|
epochUnit? | "seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit) | "milliseconds" | The unit the epoch values are counted in: "seconds" or "milliseconds", singular or plural. Any other value returns null. |
timeZone? | string | "UTC" | The time zone the calendar dates are counted in: an IANA name, a UTC offset (a time zone identifier such as +05:30, +0530 or -08, or a stored offset ±HH:MM[:SS], what getTimeZoneOffset returns), or "local" for the system time zone. An unknown zone returns null. |
Returns
Section titled “Returns”number of shared calendar dates, 0 when disjoint, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { intervalOverlappingDaysUnix } from "@northguild/gmt/unix/interval";
intervalOverlappingDaysUnix(0, 172800000, 86400000, 259200000, { timeZone: "UTC" }) // 1 (the intersection [86400000, 172800000) is 1970-01-02)