From d2eff6d9d2baa6c90488571b91e5cf8ba16b0e9b Mon Sep 17 00:00:00 2001
From: Luca Casonato
Intl.DateTimeFormat constructorIntl.DateTimeFormat.prototype.formatToParts methodUser agents that support JavaScript must also implement the Temporal proposal. The following terms are defined there, and used in this specification: JSTEMPORAL
@@ -3225,6 +3233,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attributeTemporal.PlainDate interfaceTemporal.PlainTime interfaceTemporal.PlainDateTime interfaceTemporal.PlainYearMonth interfaceTemporal.PlainMonthDay interfaceTemporal.Instant interface, and its toZonedDateTimeISO methodTemporal.ZonedDateTime interface, and its withTimeZone method and withCalendar methoddatetimeformatdatefieldsdatelengthtimeprecisiontimezonestylehour12calendartimezonedatetime.format, datefields, datelength, timeprecision, timezonestyle, hour12, calendar, timezone.
[Exposed=Window]
@@ -24922,6 +24951,14 @@ interface HTMLTimeElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions, Reflect] attribute DOMString dateTime;
+ [CEReactions] attribute DOMString format;
+ [CEReactions] attribute DOMString dateFields;
+ [CEReactions] attribute DOMString dateLength;
+ [CEReactions] attribute DOMString timePrecision;
+ [CEReactions] attribute DOMString timeZoneStyle;
+ [CEReactions] attribute DOMString hour12;
+ [CEReactions, Reflect] attribute DOMString calendar;
+ [CEReactions, Reflect] attribute DOMString timeZone;
};
HTMLTimeElement.By default, a time element represents the child text
+ content of the element verbatim. Because the author writing the markup does not in general
+ know the time zone, locale, or calendar preferences of the user who will read it, this means that
+ an absolute moment in time cannot be presented in the reader's own preferences without scripting.
+ To allow such presentation declaratively, a time element can opt in to having the user
+ agent format its machine-readable equivalent of the element's contents for display,
+ using the reader's preferences together with formatting options provided by the author.
When formatting is enabled and possible, the formatted value is rendered in place of the + element's child text content using a shadow tree, as described in the rendering section. The child text content continues + to serve as fallback content: it is what is shown by user agents that do not support this feature, + and what is shown when the datetime value cannot be formatted (for example, because it + is a duration or because a requested locale or calendar is + unavailable).
+ +In this example, the author marks up an absolute moment in time, requesting that it be shown to + each reader as a localized date and time in the reader's own time zone, while providing a + human-readable fallback for user agents that do not support formatting:
+ +<time datetime="2026-06-17T08:13:41.099Z" format="datetime">
+ 17 June 2026, 08:13 UTC
+</time>
+ The format attribute is
+ an enumerated attribute that enables formatting and controls which of the date and the
+ time are shown. It has the following keywords and states:
| Keyword + | State + | Brief description + |
|---|---|---|
date
+ | Date + | Format and show the date only. + |
time
+ | Time + | Format and show the time only. + |
datetime
+ | Date and time + | Format and show both the date and the time. + |
The attribute's missing value default is the Off state, in which the element's contents are not + formatted. The attribute has no invalid value default, so an + invalid value maps to no state; like the Off + state, this disables formatting.
+The datefields
+ attribute is an enumerated attribute that controls which fields of the date are shown
+ when the format attribute is in the Date or Date
+ and time state. It has the following keywords and states, where the fields column
+ gives the set of date fields shown:
| Keyword + | State + | Fields + |
|---|---|---|
weekday
+ | Weekday + | weekday + |
day-weekday
+ | Day and weekday + | day, weekday + |
month-day
+ | Month and day + | month, day + |
month-day-weekday
+ | Month, day, and weekday + | month, day, weekday + |
year-month
+ | Year and month + | year, month + |
year-month-day
+ | Year, month, and day + | year, month, day + |
year-month-day-weekday
+ | Year, month, day, and weekday + | year, month, day, weekday + |
The attribute's missing value default is the Year, month, and day state. The attribute + has no invalid value default, so an invalid value maps to no + state, which causes formatting to fail and the element's contents to be shown verbatim.
+The datelength
+ attribute is an enumerated attribute that controls how the shown date fields are
+ formatted. It has the following keywords and states:
| Keyword + | State + | Brief description + |
|---|---|---|
long
+ | Long + | For example, a month is shown as its full name. + |
medium
+ | Medium + | For example, a month is shown as an abbreviation. + |
short
+ | Short + | For example, a month is shown as a number. + |
The attribute's missing value default is the Long state. The attribute has no invalid value default, so an invalid value maps to no state, + which causes formatting to fail and the element's contents to be shown verbatim.
+The timeprecision
+ attribute is an enumerated attribute that controls the granularity to which the time
+ is shown when the format attribute is in the Time or Date
+ and time state. It has the following keywords and states:
| Keyword + | State + | Brief description + |
|---|---|---|
hour
+ | Hour + | Show the hour. + |
minute
+ | Minute + | Show the hour and minute. + |
second
+ | Second + | Show the hour, minute, and second. + |
The attribute's missing value default is the Second state. The attribute has no invalid value default, so an invalid value maps to no state, + which causes formatting to fail and the element's contents to be shown verbatim.
+The timezonestyle
+ attribute is an enumerated attribute that controls whether, and how, a time zone is
+ shown. It has the following keywords and states:
| Keyword + | State + | Brief description + |
|---|---|---|
long
+ | Long + | For example, "Pacific Standard Time". + |
short
+ | Short + | For example, "PST". + |
The attribute's missing value default and empty value default are both the None state, in which no time zone is shown. (So
+ both omitting the attribute and specifying timezonestyle="" result in the
+ None state.) The attribute has no invalid value default, so any other invalid value maps to no
+ state, which causes formatting to fail and the element's contents to be shown verbatim.
The hour12 attribute is
+ an enumerated attribute that controls whether the time is shown using a 12-hour clock
+ or a 24-hour clock. It has the following keywords and states:
| Keyword + | State + | Brief description + |
|---|---|---|
12
+ | 12-hour + | Use a 12-hour clock. + |
24
+ | 24-hour + | Use a 24-hour clock. + |
The attribute's missing value default is the Auto state, in which the clock used is the default for + the locale. The attribute has no invalid value default, so an + invalid value maps to no state, which causes formatting to fail and the element's contents to be + shown verbatim.
+The calendar
+ attribute, if present, gives the calendar in which the date is shown. Its value must be either a
+ calendar identifier supported by the user agent or the
+ string "input". The value "input", which is also the
+ default when the attribute is absent, indicates that the calendar of the parsed datetime is used. If the attribute is present but its value is
+ neither "input" nor a calendar identifier supported by the user agent,
+ formatting fails and the element's contents are shown verbatim.
The timezone
+ attribute, if present, gives the time zone into which the parsed datetime is converted for display. Its value must be either a
+ time zone identifier, the string "input", or the empty string. The string
+ "input" indicates that the time zone of the parsed datetime is used, and is only supported when that parsed value is
+ a Temporal.ZonedDateTime. The empty string, which is also the default when the
+ attribute is absent, indicates that the host's current time zone is used.
The host's current time zone is the time zone identifier returned by the DefaultTimeZone abstract operation. JSINTL
+ +The parsed datetime of a time element element is the result
+ of running these steps:
Let value be the machine-readable equivalent of the element's + contents for element.
If there is no such machine-readable equivalent, then return null.
Switch on the type of value:
+ +Return the Temporal.PlainYearMonth
+ in the ISO 8601 calendar representing value's year and month.
Return the Temporal.PlainDate in
+ the ISO 8601 calendar representing value.
Return the Temporal.PlainMonthDay
+ in the ISO 8601 calendar representing value's month and day.
Return the Temporal.PlainTime
+ representing value.
Return the Temporal.PlainDateTime
+ in the ISO 8601 calendar representing value.
Return the Temporal.Instant
+ representing value's moment in time.
Temporal.ZonedDateTimeReturn value.
Return null.
A week, a time-zone offset, a year on its own, and a duration have no parsed datetime; the element's
+ contents are therefore shown verbatim for these. The Temporal.ZonedDateTime case
+ supports a future extension of the machine-readable equivalent of the element's
+ contents algorithm to recognize RFC 9557 strings carrying a time zone or a
+ calendar annotation; no current datetime value syntax produces one.
The formatted datetime parts of a time element element are
+ obtained by running these steps. They return either a list of date-time format parts (each being a
+ tuple of a type, which is a string, and a value, which is a string) or null:
If element's format attribute is not in
+ the Date, Time, or Date and time state, then return null. (This is the
+ case when the attribute is absent, in the Off
+ state, or has an invalid value, in which last case it is in no state.)
If any of element's datefields, datelength, timeprecision, timezonestyle, or hour12 attributes is in no state, then return null. (These
+ attributes have a missing value default but no invalid value default, so they are in no state exactly when
+ they are present with an invalid value.)
Let parsedValue be element's parsed datetime.
If parsedValue is null, then return null.
Let locale be the language of element. If + locale is the empty string or is explicitly + unknown, then let locale be the user agent's default locale.
Let calendar be the value of element's calendar attribute, or "input" if the
+ attribute is absent. If calendar is not "input" and is not one
+ of the calendar identifiers returned by AvailableCalendars(), then return null.
Let timeZone be the value of element's timezone attribute, or the empty string if the attribute is
+ absent.
Let valueToFormat be the result of resolving the time zone and calendar of a parsed datetime given + parsedValue, timeZone, calendar, and element.
+If valueToFormat is null, then return null.
Let options be the result of computing the date-time formatting options for element.
Let formatter be the result of constructing an Intl.DateTimeFormat object given
+ locale and options. If this throws an exception, then return null.
Let parts be the result of calling formatToParts on + formatter with valueToFormat. If this throws an exception, then return + null.
Return parts.
To resolve the time zone and calendar of a parsed datetime, given a
+ Temporal value parsedValue, a string timeZone, a string
+ calendar, and a time element element:
If parsedValue is a Temporal.ZonedDateTime:
If timeZone is not "input":
If timeZone is the empty string, then set timeZone to the host's + current time zone.
If timeZone is not a valid time zone identifier supported by the user agent, + then return null.
Set parsedValue to the result of calling withTimeZone on parsedValue + with timeZone.
If calendar is not "input", then set
+ parsedValue to the result of calling withCalendar on parsedValue
+ with calendar.
Return parsedValue.
If parsedValue is a Temporal.Instant:
If timeZone is "input", then return null.
If timeZone is the empty string, then set timeZone to the host's + current time zone.
If timeZone is not a valid time zone identifier supported by the user agent, + then return null.
Let zoned be the result of calling toZonedDateTimeISO on + parsedValue with timeZone.
If calendar is not "input", then set zoned
+ to the result of calling withCalendar
+ on zoned with calendar.
Return zoned.
If element's timezonestyle
+ attribute is not in the None state, then
+ return null.
If timeZone is not the empty string, then return null.
If parsedValue is a Temporal.PlainTime or calendar is
+ "input", then return parsedValue.
Return parsedValue with its calendar set to calendar. (A Temporal.PlainTime
+ has no calendar, so it was already returned by the previous step.)
A month, date,
+ yearless date, time,
+ and local date and time carry no time-zone information,
+ so a timezonestyle other than the empty string, a
+ timezone of "input", or a timezone naming a specific zone, cannot be satisfied for them and
+ results in the element's contents being shown verbatim instead.
To compute the date-time formatting options for a time element
+ element, returning a set of options for the Intl.DateTimeFormat constructor:
Let options be a new ordered map.
Let length be element's datelength attribute state.
If element's format attribute is in the Date state or the Date and time state, then:
Let fields be the set of date fields given by element's datefields attribute state.
If fields contains year, then set
+ options["year"] to "numeric".
If fields contains month, then set
+ options["month"] to:
"long"
"numeric"
"short"
If fields contains day, then set
+ options["day"] to "numeric".
If fields contains weekday, then set
+ options["weekday"] to "long" if
+ length is the Long state, and
+ "short" otherwise.
If element's format attribute is in the Time state or the Date and time state, then switch on
+ element's timeprecision attribute
+ state:
Set options["hour"] to "numeric".
Set options["hour"] and options["minute"] to "numeric".
Set options["hour"], options["minute"], and options["second"] to "numeric".
Switch on element's timezonestyle
+ attribute state:
Set options["timeZoneName"] to "long".
Set options["timeZoneName"] to "short".
Do nothing.
Switch on element's hour12 attribute
+ state:
Set options["hour12"] to true.
Set options["hour12"] to false.
Do nothing.
Return options.
The calendar and time zone used for formatting are carried by the Temporal + value returned by resolving + the time zone and calendar of a parsed datetime, so they are not also placed in the + formatting options.
+ +The format IDL attribute must reflect the
+ format content attribute, limited to only known
+ values. The dateFields IDL attribute must
+ reflect the datefields content attribute,
+ limited to only known values. The dateLength
+ IDL attribute must reflect the datelength
+ content attribute, limited to only known values. The timePrecision IDL attribute must reflect the
+ timeprecision content attribute, limited to only
+ known values. The timeZoneStyle IDL attribute
+ must reflect the timezonestyle content
+ attribute, limited to only known values. The hour12 IDL attribute must reflect the hour12 content attribute, limited to only known
+ values.
time elementA time element whose formatted datetime parts are not null is
+ expected to render with a shadow tree that represents those
+ parts, in place of the element's child text content.
The shadow tree is expected to contain, for each part of the
+ element's formatted datetime parts, in tree order, a datetime part
+ box, which is a span element whose child text content is
+ part's value and which is appended to the time element's shadow
+ root. Each datetime part box is associated with part's type.
The element's formatted datetime parts depend on the element's content attributes, + its language, the host's current time zone, and the user's locale + preferences. Whenever any of these change such that the parts would differ, the shadow + tree is expected to be updated to reflect the new parts.
+ +When the parts are null — because formatting is not enabled, or because the + element's datetime value cannot be formatted with the requested options — the + element instead renders its child text content as usual, which therefore acts as + fallback content.
+ +Each datetime part box is expected to be rendered inline, as though it
+ were a span element in the time element's content. User agents are
+ expected to make each datetime part box selectable as part of the
+ document's text, and to include it in any Range that covers the time
+ element, as though it were ordinary text content of the element.
A future CSS feature is anticipated to provide pseudo-elements that select
+ datetime part boxes by their associated type (for example,
+ "weekday", "month", or "literal"), allowing individual parts of the formatted date or time to be styled.
+ This mirrors the way the select element's base appearance exposes parts of
+ its shadow tree through pseudo-elements such as the '::picker'
+ pseudo-element.
textarea element