formatDate
Signature
Section titled “Signature”formatDate(value: string, locale?: string | string[], options?: DateTimeFormatOptions): stringReturn a localized string for a PlainDate ISO input using Intl options.
- Formats as Temporal’s ECMA-402 PlainDate format (
PlainDate#toLocaleString) does, through the runtime’sIntl.DateTimeFormat: the requested fields and widths are kept, andtimeZoneNameis ignored (a PlainDate has no zone). - Accepts optional BCP 47 locale and Intl.DateTimeFormatOptions.
- Returns "" for invalid input, for a
timeStyle(with or withoutdateStyle) and for only time fields, wherePlainDate#toLocaleStringthrows a TypeError. - Compatibility: before 1.16.0 some locales and calendars lost a requested width (ja-JP with the japanese calendar and
month: "long"gave"R6/2"),timeZoneNamealone returned"", and atimeStylebesidedateStylewas ignored. Pass the numeric fields to keep the numeric text, and pass onlydateStyleto keep the styled text. optionsnull returns"", as ECMA-402’s CoerceOptionsToObject rejects it. Any other non-object — a string, a number, a boolean — formats with the defaults, asIntl.DateTimeFormatdoes: CoerceOptionsToObject calls ToObject on it and the wrapper carries no recognised option. Onlynullandundefinedare special-cased.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainDate string |
locale | string | string[] | optional BCP 47 locale identifier (default: runtime default), or a preference list of tags (ECMA-402) |
Options
Section titled “Options”options
optional Intl.DateTimeFormatOptions
Type: DateTimeFormatOptions.
| Option | Type | Default | Description |
|---|---|---|---|
…Intl.DateTimeFormatOptions | — | — | Every field of DateTimeFormatOptions, as ECMA-402 defines it. |
Returns
Section titled “Returns”localized date string or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatDate } from "@northguild/gmt/plain/format";
formatDate("2024-03-15", "en-US", { year: "numeric", month: "long", day: "numeric" }) // "March 15, 2024"