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]] | ||
[[Era]] | ||
[[Year]] | ||
[[Month]] | ||
[[Day]] | ||
[[DayPeriod]] | ||
[[Hour]] | ||
[[Minute]] | ||
[[Second]] | ||
[[FractionalSecondDigits]] | ||
[[TimeZoneName]] |
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:
The following algorithm refers to the type
nonterminal from UTS 35's Unicode Locale Identifier grammar.
type
nonterminal, throw a type
nonterminal, throw a When 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
When the BasicFormatMatcher abstract operation is called with two arguments options and formats, the following steps are taken:
When the BestFitFormatMatcher abstract operation is called with two arguments options and formats, it performs implementation dependent steps, which should return a set of component representations that a typical user of the selected locale would perceive as at least as good as the one returned by
A DateTime format function is an anonymous built-in function that has a [[DateTimeFormat]] internal slot.
When a DateTime format function F is called with optional argument date, the following steps are taken:
The
The FormatDateTimePattern abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat), patternParts (which is a list of Records as returned by PartitionPattern), x (which must be a Number value), and rangeFormatOptions (which is a range pattern
The PartitionDateTimePattern abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat) and x (which must be a Number value), interprets x as a
The FormatDateTime abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat) and x (which must be a Number value), and performs the following steps:
The FormatDateTimeToParts abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat) and x (which must be a Number value), and performs the following steps:
The PartitionDateTimeRangePattern abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat), x (which must be a Number value) and y (which must be a Number value), interprets x and y as time values as specified in ES2021,
The FormatDateTimeRange abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat), x (which must be a Number value) and y (which must be a Number value), and performs the following steps:
The FormatDateTimeRangeToParts abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat), x (which must be a Number value) and y (which must be a Number value), and performs the following steps:
When the ToLocalTime abstract operation is called with arguments t, calendar, and timeZone, the following steps are taken:
Field | Value Calculation for Gregorian Calendar |
---|---|
[[Weekday]] | WeekDay(tz) specified in ES2021's |
[[Era]] | Let year be YearFromTime(tz) specified in ES2021's year is less than 0, return 'BC', else, return 'AD'. |
[[Year]] | YearFromTime(tz) specified in ES2021's |
[[RelatedYear]] | |
[[YearName]] | |
[[Month]] | MonthFromTime(tz) specified in ES2021's |
[[Day]] | DateFromTime(tz) specified in ES2021's |
[[Hour]] | HourFromTime(tz) specified in ES2021's |
[[Minute]] | MinFromTime(tz) specified in ES2021's |
[[Second]] | SecFromTime(tz) specified in ES2021's |
[[Millisecond]] | msFromTime(tz) specified in ES2021's |
[[InDST]] | Calculate |
The UnwrapDateTimeFormat abstract operation gets the underlying DateTimeFormat operation for various methods which implement ECMA-402 v1 semantics for supporting initializing existing Intl objects.
The Intl.DateTimeFormat constructor is the %DateTimeFormat% intrinsic object and a standard built-in property of the Intl object. Behaviour common to all service constructor properties of the Intl object is specified in .
When the Intl.DateTimeFormat
function is called with optional arguments locales and options, the following steps are taken:
The Intl.DateTimeFormat constructor has the following properties:
The value of Intl.DateTimeFormat.prototype
is
This property has the attributes { [[Writable]]:
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
The value of the
The value of the [[AvailableLocales]] internal slot is implementation defined within the constraints described in .
The value of the [[RelevantExtensionKeys]] internal slot is «
The value of the [[LocaleData]] internal slot is implementation defined within the constraints described in and the following additional constraints, for all locale values locale:
Range Pattern Field | Pattern String Field |
---|---|
[[Era]] | |
[[Year]] | |
[[Month]] | |
[[Day]] | |
[[AmPm]] | |
[[Hour]] | |
[[Minute]] | |
[[Second]] | |
[[FractionalSecondDigits]] |
The Intl.DateTimeFormat prototype object is itself an ordinary object. %DateTimeFormat.prototype% is not an Intl.DateTimeFormat instance and does not have an [[InitializedDateTimeFormat]] internal slot or any of the other internal slots of Intl.DateTimeFormat instance objects.
The initial value of Intl.DateTimeFormat.prototype.constructor
is the intrinsic object
The initial value of the @@toStringTag property is the String value
This property has the attributes { [[Writable]]:
Intl.DateTimeFormat.prototype.format is an accessor property whose set accessor function is
Array.prototype.map
or other functions.
This is considered a historical artefact, as part of a convention which is no longer followed for new features, but is preserved to maintain compatibility with existing programs.
When the formatToParts
method is called with an argument date, the following steps are taken:
When the formatRange
method is called with an arguments startDate and endDate, the following steps are taken:
When the formatRangeToParts
method is called with an arguments startDate and endDate, the following steps are taken:
This function provides access to the locale and formatting options computed during initialization of the object.
Internal Slot | Property |
---|---|
[[Locale]] | |
[[Calendar]] | |
[[NumberingSystem]] | |
[[TimeZone]] | |
[[HourCycle]] | |
[[Weekday]] | |
[[Era]] | |
[[Year]] | |
[[Month]] | |
[[Day]] | |
[[DayPeriod]] | |
[[Hour]] | |
[[Minute]] | |
[[Second]] | |
[[FractionalSecondDigits]] | |
[[TimeZoneName]] | |
[[DateStyle]] | |
[[TimeStyle]] |
For web compatibility reasons, if the property
Intl.DateTimeFormat instances are ordinary objects that inherit properties from
Intl.DateTimeFormat instances have an [[InitializedDateTimeFormat]] internal slot.
Intl.DateTimeFormat instances also have several internal slots that are computed by the constructor:
Finally, Intl.DateTimeFormat instances have a [[BoundFormat]] internal slot that caches the function returned by the format accessor (
© 2021 Google, Ecma International
All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.