intervalLengthDateTime
Signature
Section titled “Signature”intervalLengthDateTime(start: string, end: string, unit: string): numberimport { intervalLengthDateTime } from "@northguild/gmt/plain/interval";Return the exact length of a datetime interval in unit, as a real (possibly fractional) number.
- Distinct from
intervalCountDateTime, which counts calendar/clockunitboundaries crossed rather than measuring exact duration — an interval from 23:59 to 00:01 touches 2 day boundaries viaintervalCountDateTimebut has an exact length of ~0.0014 days viaintervalLengthDateTime. - Uses
Temporal.Duration.prototype.total, which resolves calendar units (month, year) against the interval’s own start so a partial month is expressed as a true fraction rather than truncated. - Returns
0for a zero-length interval (start === end). - Returns
nullon invalid input (unparseable start/end,start > end, unsupported unit).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start |
string |
ISO PlainDateTime string for the interval start |
end |
string |
ISO PlainDateTime string for the 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”intervalLengthDateTime("2024-01-01T23:59:00", "2024-01-02T00:01:00", "day") // 0.001388888888888889intervalLengthDateTime("2024-01-01T23:59:00", "2024-01-02T00:01:00", "minute") // 2intervalLengthDateTime("2024-01-01T00:00:00", "2024-01-01T00:00:00", "day") // 0intervalLengthDateTime("invalid", "2024-01-02T00:00:00", "day") // null