getZonedOffsetAs
Signature
Section titled “Signature”getZonedOffsetAs(value: string, unit: ZonedOffsetUnit): numberimport { getZonedOffsetAs } from "@northguild/gmt/zoned/parse";Read 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.
- Returns null on invalid
valueorunit.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
zoned ISO 8601 datetime string |
unit |
ZonedOffsetUnit |
“minutes” | “nanoseconds” |
Returns
Section titled “Returns”the offset in the requested unit, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”getZonedOffsetAs("2024-07-15T12:00:00-04:00[America/New_York]", "minutes") // -240getZonedOffsetAs("2024-05-15T12:00:00+05:45[Asia/Kathmandu]", "minutes") // 345getZonedOffsetAs("2024-02-29T12:00:00+00:00[UTC]", "nanoseconds") // 0getZonedOffsetAs("2024-07-15T12:00:00-04:00[America/New_York]", "nanoseconds") // -14400000000000getZonedOffsetAs("invalid", "minutes") // nullgetZonedOffsetAs("2024-02-29T12:00:00+00:00[UTC]", "fortnights" as never) // null