getTimeZoneOffset
Signature
Section titled “Signature”getTimeZoneOffset(timeZone: string, instant: string): stringReturn a time zone’s UTC offset at a given instant.
- Unlike
getZonedOffset, this doesn’t need an existing zoned value in hand — pass any timeZone identifier and an instant to look up, which is why (likegetDstTransitions) it lives inget/despite taking two arguments: neither is a date value being described, both are coordinates for a zone-level lookup. - Returns "" for an invalid timeZone or instant, including a leap second in any spelling (
23:59:60,t/space separator, basic235960), which Temporal would read as:59. Compatibility: to look up the offset at the clamped:59instant as earlier releases did, pass that instant ("2016-12-31T23:59:59Z"), or callTemporal.Instant.from(instant).toZonedDateTimeISO(timeZone).offsetdirectly. - The instant is ISO 8601 extended format before any annotation (
<date>T<time>, thenZor±HH:MM[:SS[.fraction]]): basic format, ator space separator, a lower-casezand an hour-only offset return "". - Only the instant is read from
instant, asisValidInstantdescribes it: a bracketed zone in it is not validated, and an offset written to the minute that is that zone’s sub-minute offset rounded (-00:45[Africa/Monrovia], for −00:44:30) names the instant the zone gives. - The result is
±HH:MM, or±HH:MM:SSwhere the zone was not on a whole minute (Africa/Monroviastood at-00:44:30until 1972). It goes straight into the time zone position of any function whose result has no zone in it, and of this one: a UTC offset is its own answer at every instant, written without seconds when they are zero.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
timeZone | string | IANA name or UTC offset: a time zone identifier (+05:30, +0530, -08) or a stored offset (±HH:MM[:SS], what getTimeZoneOffset returns) |
instant | string | ISO 8601 instant string (e.g. “2024-07-15T12:00:00Z”) |
Returns
Section titled “Returns”offset string (e.g. “-04:00”), or "" on invalid input
Examples
Section titled “Examples”import { getTimeZoneOffset } from "@northguild/gmt/zoned/get";
getTimeZoneOffset("America/New_York", "2024-07-15T12:00:00Z") // "-04:00"