getZonedOffsetAs
Signature
Section titled “Signature”getZonedOffsetAs(value: string, unit: ZonedOffsetUnit): number | nullRead a zoned value’s UTC offset as a number, in the given unit.
- Subsumes what would otherwise be
getZonedOffsetMinutes/getZonedOffsetNanoseconds— one differently-scaled reading of the same underlying quantity through a single parameterized call, following J8’sgetDurationUnit(value, unit)precedent (Decision 5). - “nanoseconds” reads Temporal’s
offsetNanosecondsdirectly. - “minutes” divides by 60e9 — every IANA offset is a whole number of minutes, so this never truncates a fraction.
- Negative offsets (west of UTC) return a negative number.
unitaccepts the plural or singular name ("minutes"or"minute"), as Temporal does.- Returns null on invalid
valueorunit.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | zoned ISO 8601 datetime string |
unit | ZonedOffsetUnit | “minutes” | “nanoseconds” (or the singular “minute” | “nanosecond”) |
Returns
Section titled “Returns”the offset in the requested unit, or null on invalid input
ZonedOffsetUnit
Section titled “ZonedOffsetUnit”Unit a zoned value’s UTC offset can be read as via getZonedOffsetAs.
import type { ZonedOffsetUnit } from "@northguild/gmt";"minutes" | "nanoseconds" | "minute" | "nanosecond"Examples
Section titled “Examples”import { getZonedOffsetAs } from "@northguild/gmt/zoned/parse";
getZonedOffsetAs("2024-07-15T12:00:00-04:00[America/New_York]", "minutes") // -240