Skip to content

formatDateTimeRange

formatDateTimeRange(start: string, end: string, locale?: string, options?: DateTimeFormatOptions): string
import { formatDateTimeRange } from "@northguild/gmt/plain/format";

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

  • Plain counterpart of formatZonedRange — same parameter order and option shape.
  • Uses Temporal.PlainDateTime.from for both endpoints; no timezone is involved.
  • Locale elides shared fields between start and end (e.g. same day/month/year).
  • Returns “” for invalid input on either endpoint.
Parameter Type Description
start string ISO PlainDateTime string (range start)
end string ISO PlainDateTime 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

formatDateTimeRange("2024-02-03T09:00:00", "2024-02-03T17:00:00", "en-US", { dateStyle: "long", timeStyle: "short" }) // "February 3, 2024, 9:00 AM – 5:00 PM"
formatDateTimeRange("2024-02-03T09:00:00", "2024-02-10T17:00:00", "en-US", { dateStyle: "long", timeStyle: "short" }) // "February 3, 2024 at 9:00 AM – February 10, 2024 at 5:00 PM"
formatDateTimeRange("invalid", "2024-02-03T17:00:00", "en-US") // "" (invalid input)

plain/format/formatDateTimeRange.ts