diffTime
Signature
Section titled “Signature”diffTime(time1: string, time2: string, units: any, options?: RoundingOptions<Temporal.TimeUnit>): number | Record<TimeDurationUnit, number>import { diffTime } from "@northguild/gmt/plain/calculate";Return the difference between two PlainTime values in the requested unit.
- Returns
nullfor invalid inputs. - Uses Temporal.PlainTime.until with
largestUnitand extracts the requested unit.smallestUnit,roundingIncrement, androundingModecontrol optional rounding of the result, per Temporal’s DifferenceOptions — e.g.{ smallestUnit: "minute", roundingMode: "halfExpand" }rounds the difference to the nearest minute before extracting the requested unit. - When
unitsis an array,smallestUnitmust not be coarser than the largest unit in the array (e.g.["minute", "second"]withsmallestUnit: "hour") — this combination is rejected by Temporal and returns null, same as other invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
time1 |
string |
ISO PlainTime string for the start |
time2 |
string |
ISO PlainTime string for the end |
units |
any |
TimeDurationUnit | TimeDurationUnit[] to measure the difference |
options |
RoundingOptions<Temporal.TimeUnit> |
optional: smallestUnit, roundingIncrement, roundingMode (Temporal.DifferenceOptions rounding controls) |
Returns
Section titled “Returns”numeric difference in the requested unit, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”diffTime("12:00:00", "14:30:00", "hour") // 2diffTime("invalid", "14:30:00", "hour") // null