formatDateToParts
Signature
Section titled “Signature”formatDateToParts(value: string, locale?: string | string[], options?: DateTimeFormatOptions): { type: string; value: string; }[]Return the locale-formatted parts of a PlainDate.
- Use the parts instead of a fixed field pattern. A pattern such as UTS #35’s
dd/MM/yyyyfixes one field order for every locale; ECMA-402’sIntl.DateTimeFormat.prototype.formatToParts(§11.3.6;FormatDateTimeToParts§11.5.7) returns the fields in the order of the locale’s CLDR date pattern, so the caller controls presentation and the locale keeps control of order. - Each part is
{ type, value }wheretypeis one of:"era","year","relatedYear","yearName","month","day","weekday","literal". - A lunisolar calendar adds two more:
zh-u-ca-chineseandko-u-ca-dangiemit"relatedYear"(the Gregorian year the cycle falls in) and"yearName"(the sexagenary cycle name) in place of, or beside,"year". Code that looks up a"year"part must handle their absence. This holds on a runtime that prints the observatory’s Chinese or Dangi dates (see the next item). - A
chineseordangidate follows the observatory the standard names: Purple Mountain Observatory forchinese, KASI fordangi. A runtime that prints a different date for one of them returns[]for any format with a year, month, day or era in that calendar. A runtime that prints the observatory’s date keeps its own parts. A format with only a weekday field always returns its parts. - The caller should iterate the array as returned; reassembling in a fixed order reintroduces exactly the bug
formatToPartsexists to avoid. - A PlainDate has no time or zone, so no
hour/minute/second/dayPeriod/timeZoneNamepart is ever returned, following Temporal’s ECMA-402 PlainDate format:timeStylewithoutdateStyle, or only time fields, yields[](asformatDateyields"");timeZoneNameis ignored. With bothdateStyleandtimeStylethe parts keep the date style and drop thetimeStyle(theIntl.DateTimeFormatentry point, requiredany), whereas the text siblingformatDatereturns""(PlainDate#toLocaleString, requireddate, is a TypeError). - The
formatZonedToPartsexample below writes the literal before the day period as"\u202f", U+202F NARROW NO-BREAK SPACE, which Node 22 and 24 return; Node 26 returns an ordinary space there (seeformatZonedToParts). - Returns
[]for invalid input. - Compatibility: before 1.16.0 time options leaked a UTC midnight and a
"UTC"zone name into the parts.formatZonedToPartson the date at midnight UTC returns those parts. 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”array of { type, value } parts, or [] on invalid input
Members of each item
| Member | Type | Description |
|---|---|---|
type | string | The kind of part, named as ECMA-402 Intl.DateTimeFormat.prototype.formatToParts names it: a field such as "year", "month" or "day", or "literal" for the separator text between fields. |
value | string | The text of the part in the requested locale, exactly as the formatter wrote it. Joining every value in array order gives the whole formatted text. |
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatDateToParts } from "@northguild/gmt/plain/format";
formatDateToParts("2024-03-15", "zh-CN") // [{ type: "year", value: "2024" }, { type: "literal", value: "/" }, { type: "month", value: "3" }, { type: "literal", value: "/" }, { type: "day", value: "15" }]Source
Section titled “Source”Accessibility
© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.