Skip to content

getZonedOffsetAs

getZonedOffsetAs(value: string, unit: ZonedOffsetUnit): number | null

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’s getDurationUnit(value, unit) precedent (Decision 5).
  • “nanoseconds” reads Temporal’s offsetNanoseconds directly.
  • “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.
  • unit accepts the plural or singular name ("minutes" or "minute"), as Temporal does.
  • Returns null on invalid value or unit.
ParameterTypeDescription
valuestringzoned ISO 8601 datetime string
unitZonedOffsetUnit“minutes” | “nanoseconds” (or the singular “minute” | “nanosecond”)

the offset in the requested unit, or null on invalid input

Unit a zoned value’s UTC offset can be read as via getZonedOffsetAs.

import type { ZonedOffsetUnit } from "@northguild/gmt";
"minutes" | "nanoseconds" | "minute" | "nanosecond"
import { getZonedOffsetAs } from "@northguild/gmt/zoned/parse";
getZonedOffsetAs("2024-07-15T12:00:00-04:00[America/New_York]", "minutes") // -240
output 

zoned/parse/getZonedOffsetAs.ts