This proposal adds two options to Intl.DateTimeFormat
: dateStyle
and timeStyle
. These options give a compact way to request the appropriate, locale-specific way to ask for a date and time of given lengths. See the README for more context.
Several DateTimeFormat algorithms use values from the following table, which provides internal slots, property names and allowable values for the components of date and time formats:
Internal Slot | Property | Values |
---|---|---|
[[Weekday]] | "weekday" |
"narrow" , "short" , "long" |
[[Era]] | "era" |
"narrow" , "short" , "long" |
[[Year]] | "year" |
"2-digit" , "numeric" |
[[Month]] | "month" |
"2-digit" , "numeric" , "narrow" , "short" , "long" |
[[Day]] | "day" |
"2-digit" , "numeric" |
[[Hour]] | "hour" |
"2-digit" , "numeric" |
[[Minute]] | "minute" |
"2-digit" , "numeric" |
[[Second]] | "second" |
"2-digit" , "numeric" |
[[TimeZoneName]] | "timeZoneName" |
"short" , "long" |
The abstract operation InitializeDateTimeFormat accepts the arguments dateTimeFormat (which must be an object), locales, and options. It initializes dateTimeFormat as a DateTimeFormat object. This abstract operation functions as follows:
"any"
, "date"
)."localeMatcher"
, "string"
, « "lookup"
, "best fit"
», "best fit"
)."hour12"
, "boolean"
, "hourCycle"
, "string"
, « "h11"
, "h12"
, "h23"
, "h24"
», "timeZone"
)."string"
, « the strings given in the Values column of the row », "formatMatcher"
, "string"
, « "basic"
, "best fit"
», "best fit"
)."dateStyle"
, "string"
, « "full"
, "long"
, "medium"
, "short"
», "timeStyle"
, "string"
, « "full"
, "long"
, "medium"
, "short"
», "basic"
, then"h11"
or "h23"
, then"h11"
."h12"
."h11"
or "h23"
, then"h23"
."h24"
."h11"
or "h12"
, thenWhen the ToDateTimeOptions abstract operation is called with arguments options, required, and defaults, the following steps are taken:
The DateTimeStyleFormat abstract operation accepts arguments dateStyle and timeStyle, which are each either "full"
, "long"
, "medium"
, or "short"
, at least one of which is not
"full"
, "long"
, "medium"
, or "short"
."full"
, "long"
, "medium"
, or "short"
."{0}"
replaced with timeFormat.[[pattern]] and the substring "{1}"
replaced with dateFormat.[[pattern]]."{0}"
replaced with timeFormat.[[pattern12]] and the substring "{1}"
replaced with dateFormat.[[pattern]].
The Intl.DateTimeFormat
When the Intl.DateTimeFormat
function is called with optional arguments locales and options, the following steps are taken:
"%DateTimeFormatPrototype%"
, « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], [[DateStyle]], [[TimeStyle]], [[Pattern]], [[BoundFormat]] »).
The value of the [[AvailableLocales]] internal slot is implementation defined within the constraints described in
The value of the [[RelevantExtensionKeys]] internal slot is « "ca"
, "nu"
, "hc"
».
"ca"
for calendar, "tz"
for time zone, "hc"
for hour cycle, and implicitly "nu"
for the numbering system of the number format used for numbers within the date format. DateTimeFormat, however, requires that the time zone is specified through the timeZone property in the options objects.
The value of the [[LocaleData]] internal slot is implementation defined within the constraints described in
"nu"
field of any locale field of [[LocaleData]] must not include the values "native"
, "traditio"
, or "finance"
.
"h11"
, "h12"
, "h23"
, "h24"
» for all locale values.
"h11"
, "h12"
, "h23"
, or "h24"
for all locale values.
"{"
, followed by the name of the field, followed by "}"
. If the record has an hour field, it must also have a pattern12 field, whose value is a String value that, in addition to the substrings of the pattern field, contains a substring "{ampm}"
.
"{"
, followed by the name of the field, followed by "}"
. If the record has an hour field, it must also have a pattern12 field, whose value is a String value that, in addition to the substrings of the pattern field, contains a substring "{ampm}"
. For [[DateTimeFormat]], the field value must be a string pattern which contains the strings "{0}"
and "{1}"
.
EXAMPLE An implementation might include the following record as part of its English locale data: {[[Hour]]: "numeric"
, [[Minute]]: "2-digit"
, [[Second]]: "2-digit"
, [[Pattern]]: "{hour}:{minute}:{second}"
, [[Pattern12]]: "{hour}:{minute}:{second} {ampm}"
}.
This function provides access to the locale and formatting options computed during initialization of the object.
"hour12"
, then"h11"
or "h12"
, let v be "h23"
or "h24"
, let v be Internal Slot | Property |
---|---|
[[Locale]] | "locale" |
[[Calendar]] | "calendar" |
[[NumberingSystem]] | "numberingSystem" |
[[TimeZone]] | "timeZone" |
[[HourCycle]] | "hourCycle" |
"hour12" |
|
[[Weekday]] | "weekday" |
[[Era]] | "era" |
[[Year]] | "year" |
[[Month]] | "month" |
[[Day]] | "day" |
[[Hour]] | "hour" |
[[Minute]] | "minute" |
[[Second]] | "second" |
[[TimeZoneName]] | "timeZoneName" |
[[DateStyle]] | "dateStyle" |
[[TimeStyle]] | "timeStyle" |
For web compatibility reasons, if the property hourCycle is set, the hour12 property should be set to "h11"
or "h12"
, or to "h23"
or "h24"
.
"hour12"
property is set in addition to the "hourCycle"
property.
Intl.DateTimeFormat instances inherit properties from %DateTimeFormatPrototype%.
Intl.DateTimeFormat instances have an [[InitializedDateTimeFormat]] internal slot.
Intl.DateTimeFormat instances also have several internal slots that are computed by the
"type"
given in Unicode Technical Standard 35 for the calendar used for formatting."type"
given in Unicode Technical Standard 35 for the numbering system used for formatting."h11"
, "h12"
) or the 24-hour format ("h23"
, "h24"
) should be used. "h11"
and "h23"
start with hour 0 and go up to 11 and 23 respectively. "h12"
and "h24"
start with hour 1 and go up to 12 and 24. [[HourCycle]] is only used when [[Hour]] is not "full"
, "long"
, "medium"
, or "short"
.