intervalCountDateTime
Signature
Section titled “Signature”intervalCountDateTime(start: string, end: string, unit: string): numberimport { intervalCountDateTime } from "@northguild/gmt/plain/interval";Count how many unit boundaries a date-time interval crosses.
- Counts calendar boundaries touched by the half-open interval
[start, end)— distinct fromdiffDateTime, which measures exact elapsed duration. An interval from 23:59 to 00:01 is two minutes long but touches 2 day boundaries. - The end boundary is excluded:
"2024-01-01T00:00:00"to"2024-01-03T00:00:00"counts 2 days. - A zero-length interval counts 1 when it sits mid-unit and 0 when it sits exactly on a unit boundary.
- Weeks start on Monday (ISO 8601).
- Accepts singular or plural units (
"day"and"days"behave identically). - 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”number of unit boundaries touched, or null on invalid input
Examples
Section titled “Examples”intervalCountDateTime("2024-01-01T23:59:00", "2024-01-02T00:01:00", "day") // 2intervalCountDateTime("2024-01-01T00:00:00", "2024-01-03T00:00:00", "day") // 2intervalCountDateTime("2024-01-01T10:30:00", "2024-01-01T12:00:00", "hour") // 2intervalCountDateTime("2024-01-01T05:00:00", "2024-01-01T05:00:00", "day") // 1 (zero-length, mid-day)intervalCountDateTime("2024-01-01T00:00:00", "2024-01-01T00:00:00", "day") // 0 (zero-length, on the boundary)intervalCountDateTime("invalid", "2024-01-02T00:00:00", "day") // null