intervalCountUnix
Signature
Section titled “Signature”intervalCountUnix(start: string | number, end: string | number, unit: string): numberimport { intervalCountUnix } from "@northguild/gmt/unix/interval";Count how many unit boundaries a Unix epoch interval crosses.
- Counts local calendar boundaries touched by the half-open interval
[start, end)— distinct fromdiffUnix, which measures exact elapsed duration. - The end boundary is excluded: midnight to midnight two days later counts 2 days.
- A zero-length interval counts 1 when it sits mid-unit and 0 when it sits exactly on a unit boundary.
- Uses the system timeZone for calendar-unit boundaries (consistent with
addUnixandsplitIntervalByUnitUnix), so day/week/month/year counts are host-dependent. - Weeks start on Monday (ISO 8601).
- Accepts singular or plural units (
"day"and"days"behave identically). - Returns
nullon invalid input (non-finite/non-integer start/end,start > end, unsupported unit, or invalid timeZone).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start |
string | number |
Unix epoch value (seconds or milliseconds) — interval start |
end |
string | number |
Unix epoch value (seconds or milliseconds) — interval end |
unit |
string |
unit string — any DateTimeUnit |
Returns
Section titled “Returns”number of unit boundaries touched, or null on invalid input
Examples
Section titled “Examples”intervalCountUnix(0, 86400000, "hour") // 24intervalCountUnix(1704153540000, 1704153660000, "day") // 2 (23:59 to 00:01 UTC)intervalCountUnix(0, 0, "hour") // 0 (zero-length, on the boundary)intervalCountUnix(1800000, 1800000, "hour") // 1 (zero-length, mid-hour)intervalCountUnix(86400000, 0, "hour") // nullintervalCountUnix(NaN, 86400000, "hour") // null