formatDateRange
Signature
Section titled “Signature”formatDateRange(start: string, end: string, locale?: string, options?: DateTimeFormatOptions): stringimport { formatDateRange } from "@northguild/gmt/plain/format";Format a plain date range using the Temporal Intl.DateTimeFormat formatRange API.
- Plain counterpart of
formatZonedRange— same parameter order and option shape. - Uses Temporal.PlainDate.from for both endpoints; no timezone is involved.
- Locale elides shared fields between
startandend(e.g. same month/year). - Returns “” for invalid input on either endpoint.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start |
string |
ISO PlainDate string (range start) |
end |
string |
ISO PlainDate string (range end) |
locale |
string |
optional locale tag |
Options
Section titled “Options”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 |
— |
Returns
Section titled “Returns”localized range string or “” when invalid
Examples
Section titled “Examples”formatDateRange("2024-02-03", "2024-02-05", "en-US", { dateStyle: "long" }) // "February 3 – 5, 2024"formatDateRange("2024-02-03", "2024-06-10", "en-US", { dateStyle: "long" }) // "February 3 – June 10, 2024"formatDateRange("invalid", "2024-02-05", "en-US") // "" (invalid input)