timeToCutoff
Signature
Section titled “Signature”timeToCutoff(now: string, cutoff: string): stringMeasure the time left until a cut-off, negative once it has passed.
- Exact elapsed time as an ISO 8601 duration with hours as the largest unit, so the value never depends on a calendar: across a fall-back night, 17:00 to 17:00 the next day is
PT25H. It isPT0Sat the cut-off itself, whereisPastCutoffturnstrue. - Negative (
"-PT1H") oncenowis after the cut-off: how late it is. - Both arguments are exact: an instant (
Z/offset) or a zoned string, ascutoffAtreturns one. The zone each is written in does not matter. - The offset fixes the instant; a bracketed zone only resolves a rounded one. An offset written to the minute that is the bracketed zone’s sub-minute offset rounded (
-00:45[Africa/Monrovia], for −00:44:30) names the instant the zone gives, asTemporal.ZonedDateTime.fromreads it, so a cut-offcutoffAtwrote is the instant it computed, except a wall time repeated inside a sub-minute offset change, which reads as its first pass (seeisValidInstant). Otherwise the bracket is not checked: a zone that does not exist, or that disagrees with the offset, changes nothing. nowis the caller’s: GMT does not read the clock here.- Returns
""on invalid input, includingcutoffAt’s""sentinel.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
now | string | ISO 8601 instant or zoned datetime string of the moment asked about |
cutoff | string | ISO 8601 instant or zoned datetime string of the cut-off |
Returns
Section titled “Returns”ISO 8601 duration from now to the cut-off, negative after it, or "" on invalid input
Examples
Section titled “Examples”import { timeToCutoff } from "@northguild/gmt/transport/compare";
timeToCutoff("2024-06-10T15:00:00Z", "2024-06-12T17:00:00+02:00[Europe/Amsterdam]") // "PT48H"