intervalLengthTime
Signature
Section titled “Signature”intervalLengthTime(start: string, end: string, unit: string): number | nullReturn the exact length of a time interval in unit, as a real (possibly fractional) number.
- Distinct from
intervalCountTime, which counts clockunitboundaries crossed rather than measuring exact duration — an interval from 12:59 to 13:01 touches 2 hour boundaries viaintervalCountTimebut has an exact length of ~0.033 hours viaintervalLengthTime. - Time units are fixed-length, so no
relativeTois needed for the total. - Returns
0for a zero-length interval (start === end). - Returns
nullon invalid input (unparseable start/end,start > end, unsupported unit, or a unit that has no effect onPlainTime, e.g."days").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start | string | ISO PlainTime string for the interval start |
end | string | ISO PlainTime string for the interval end |
unit | string | unit string — "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond" (calendar units return null) |
Returns
Section titled “Returns”exact length of the interval expressed in unit, or null on invalid input
Examples
Section titled “Examples”import { intervalLengthTime } from "@northguild/gmt/plain/interval";
intervalLengthTime("12:00:00", "14:30:00", "hour") // 2.5