Skip to content

formatRelativeZoned

formatRelativeZoned(value: string, locale?: string, options?: FormatRelativeZonedOptions): string
import { formatRelativeZoned } from "@northguild/gmt/zoned/format";

Format the relative time between a zoned date-time and a reference instant.

  • Auto-picks the display unit (second through year) based on the distance, unless largestUnit forces one.
  • roundingMethod controls how the distance rounds to the display unit.
Parameter Type Description
value string ZonedDateTime ISO string to format
locale string optional: BCP 47 locale tag

options

Option Type Default
style? "long" | "short" | "narrow"
numeric? "always" | "auto"
largestUnit? RelativeUnit
roundingMethod? RelativeRoundingMethod
reference? string | number

the formatted relative-time string, or “” on invalid input

formatRelativeZoned("2026-03-08T01:00:00-05:00[America/New_York]", "en-US") // "tomorrow"
formatRelativeZoned(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundary
formatRelativeZoned("not-a-date") // ""

zoned/format/formatRelativeZoned.ts