Skip to main content

Module datefmt

Module datefmt 

Source
Expand description

Date.prototype.toLocaleString / toLocaleDateString / toLocaleTimeString with their options argument, in the en-US shape.

Node formats these through ICU: ECMA-402’s CreateDateTimeFormat turns the options bag into a SKELETON ("yMMMMEEEEd", "hm", …), and ICU’s DateTimePatternGenerator turns the skeleton into a PATTERN ("EEEE, MMMM d, y") by a distance search over the locale’s availableFormats, adjusting field widths, appending fields no pattern carries and gluing a date half to a time half. That is what this module is: a port of dtptngen.cpp’s getBestPattern / getBestRaw / getBestAppending / adjustFieldTypes over the en data ICU 77 ships, so every option combination resolves to the pattern node’s does — including the odd ones, like {day: '2-digit', hour: '2-digit', second: 'numeric'} printing 09, 9 (hour: 13).

The locales argument is still ignored: every locale formats as en-US, as numfmt does for numbers (see BUGS.md).

Structs§

Format
A resolved format: the ICU pattern and the zone it renders in.

Enums§

Required
Which toLocale*String is asking: what it requires and defaults to (ECMA-402 ToDateTimeOptions).

Functions§

date_to_locale
Date.prototype.toLocale{,Date,Time}String(locales, options).
resolve
CreateDateTimeFormat for the toLocale*String family: read and validate the options bag in the order V8 does, apply ToDateTimeOptions, and resolve the pattern.