Skip to content

formatZonedRange

formatZonedRange(from: string, to: string, locale?: string, options?: DateTimeFormatOptions): string
import { formatZonedRange } from "@northguild/gmt/zoned/format";

Format a zoned datetime range using the Temporal Intl.DateTimeFormat formatRange API.

  • Both datetimes must have the same timezone.
  • Uses Temporal.ZonedDateTime.toInstant for formatting.
  • Returns “” for invalid input or mismatched timezones.
Parameter Type Description
from string zoned ISO 8601 datetime string (range start)
to string zoned ISO 8601 datetime string (range end)
locale string optional locale tag

options

Option Type Default
localeMatcher? "best fit" | "lookup"
weekday? "long" | "short" | "narrow"
era? "long" | "short" | "narrow"
year? "numeric" | "2-digit"
month? "long" | "short" | "narrow" | "numeric" | "2-digit"
day? "numeric" | "2-digit"
hour? "numeric" | "2-digit"
minute? "numeric" | "2-digit"
second? "numeric" | "2-digit"
timeZoneName? "long" | "short" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"
formatMatcher? "best fit" | "basic"
hour12? boolean
timeZone? string
calendar? string
dayPeriod? "long" | "short" | "narrow"
numberingSystem? string
dateStyle? "long" | "short" | "medium" | "full"
timeStyle? "long" | "short" | "medium" | "full"
hourCycle? "h11" | "h12" | "h23" | "h24"
fractionalSecondDigits? 1 | 2 | 3

localized range string or “” when invalid

formatZonedRange("2024-02-29T12:00:00.000+00:00[UTC]", "2024-02-29T14:00:00.000+00:00[UTC]", "en-US", { dateStyle: "long", timeStyle: "short" }) // "February 29, 2024 at 12:00 PM – 2:00 PM Coordinated Universal Time"
formatZonedRange("2024-02-29T12:00:00.000+00:00[UTC]", "2024-02-29T14:00:00.000+00:00[UTC]", "en-GB", { dateStyle: "short", timeStyle: "short" }) // "29/02/2024, 12:00 – 14:00"
formatZonedRange("invalid", "2024-02-29T14:00:00.000+00:00[UTC]", "en-US") // "" (invalid input)

zoned/format/formatZonedRange.ts