intervalLengthUnix
Signature
Section titled “Signature”intervalLengthUnix(start: string | number, end: string | number, unit: string): numberimport { intervalLengthUnix } from "@northguild/gmt/unix/interval";Return the exact length of a Unix epoch interval in unit, as a real (possibly fractional) number.
- Distinct from
intervalCountUnix, which counts local calendarunitboundaries crossed rather than measuring exact duration. - Uses the system timeZone for calendar-unit resolution (consistent with
intervalCountUnixandsplitIntervalByUnitUnix), so month/year lengths are host-dependent; fixed-length units (hour, minute, second, …) are timeZone-independent. - Returns
0for a zero-length interval (start === end). - 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”exact length of the interval expressed in unit, or null on invalid input
Examples
Section titled “Examples”intervalLengthUnix(0, 86400000, "hour") // 24intervalLengthUnix(0, 5400000, "hour") // 1.5intervalLengthUnix(0, 0, "hour") // 0intervalLengthUnix(86400000, 0, "hour") // nullintervalLengthUnix(NaN, 86400000, "hour") // null