Skip to content

intervalLengthTime

intervalLengthTime(start: string, end: string, unit: string): number | null

Return the exact length of a time interval in unit, as a real (possibly fractional) number.

  • Distinct from intervalCountTime, which counts clock unit boundaries crossed rather than measuring exact duration — an interval from 12:59 to 13:01 touches 2 hour boundaries via intervalCountTime but has an exact length of ~0.033 hours via intervalLengthTime.
  • Time units are fixed-length, so no relativeTo is needed for the total.
  • Returns 0 for a zero-length interval (start === end).
  • Returns null on invalid input (unparseable start/end, start > end, unsupported unit, or a unit that has no effect on PlainTime, e.g. "days").
ParameterTypeDescription
startstringISO PlainTime string for the interval start
endstringISO PlainTime string for the interval end
unitstringunit string — "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond" (calendar units return null)

exact length of the interval expressed in unit, or null on invalid input

import { intervalLengthTime } from "@northguild/gmt/plain/interval";
intervalLengthTime("12:00:00", "14:30:00", "hour") // 2.5
output 

plain/interval/intervalLengthTime.ts