CARVIEW |
- Toggle shortcuts help
?
- Toggle "can call user code" annotations
u
- Jump to search box
/
- Toggle pinning of the current clause
p
- Jump to nth pin
1-9
- Introduction
- 1 Scope
- 2 Conformance
- 3 Normative References
- +4 Overview
- +5 Notational Conventions
- +6 Identification of Locales, Currencies, Time Zones, Measurement Units, Numbering Systems, Collations, and Calendars
- 7 Requirements for Standard Built-in ECMAScript Objects
- +8 The Intl Object
- +8.1 Value Properties of the Intl Object
- +8.2 Constructor Properties of the Intl Object
- 8.2.1 Intl.Collator ( . . . )
- 8.2.2 Intl.DateTimeFormat ( . . . )
- 8.2.3 Intl.DisplayNames ( . . . )
- 8.2.4 Intl.DurationFormat ( . . . )
- 8.2.5 Intl.ListFormat ( . . . )
- 8.2.6 Intl.Locale ( . . . )
- 8.2.7 Intl.NumberFormat ( . . . )
- 8.2.8 Intl.PluralRules ( . . . )
- 8.2.9 Intl.RelativeTimeFormat ( . . . )
- 8.2.10 Intl.Segmenter ( . . . )
- +8.3 Function Properties of the Intl Object
- +9 Locale and Parameter Negotiation
- 9.1 Internal slots of Service Constructors
- +9.2 Abstract Operations
- 9.2.1 CanonicalizeLocaleList ( locales )
- 9.2.2 CanonicalizeUValue ( ukey, uvalue )
- 9.2.3 LookupMatchingLocaleByPrefix ( availableLocales, requestedLocales )
- 9.2.4 LookupMatchingLocaleByBestFit ( availableLocales, requestedLocales )
- 9.2.5 UnicodeExtensionComponents ( extension )
- 9.2.6 InsertUnicodeExtensionAndCanonicalize ( locale, attributes, keywords )
- 9.2.7 ResolveLocale ( availableLocales, requestedLocales, options, relevantExtensionKeys, localeData )
- 9.2.8 ResolveOptions ( constructor, localeData, locales, options [ , specialBehaviours [ , modifyResolutionOptions ] ] )
- 9.2.9 FilterLocales ( availableLocales, requestedLocales, options )
- 9.2.10 GetOptionsObject ( options )
- 9.2.11 CoerceOptionsToObject ( options )
- 9.2.12 GetOption ( options, property, type, values, default )
- 9.2.13 GetBooleanOrStringNumberFormatOption ( options, property, stringValues, fallback )
- 9.2.14 DefaultNumberOption ( value, minimum, maximum, fallback )
- 9.2.15 GetNumberOption ( options, property, minimum, maximum, fallback )
- 9.2.16 PartitionPattern ( pattern )
- +10 Collator Objects
- +11 DateTimeFormat Objects
- +11.1 The Intl.DateTimeFormat Constructor
- +11.2 Properties of the Intl.DateTimeFormat Constructor
- 11.2.1 Intl.DateTimeFormat.prototype
- 11.2.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] )
- +11.2.3 Internal slots
- 11.2.3.1 DateTime Format Records
- 11.2.3.2 DateTime Range Pattern Records
- 11.2.3.3 DateTime Range Pattern Format Records
- 11.2.3.4 DateTime Range Pattern Part Records
- 11.2.3.5 DateTime Styles Records
- 11.2.3.6 DateTime Style Records
- 11.2.3.7 DateTime Connector Records
- 11.2.3.8 DateTime Date Range Records
- 11.2.3.9 DateTime Time Range Records
- 11.2.3.10 DateTime Style Range Records
- +11.3 Properties of the Intl.DateTimeFormat Prototype Object
- 11.3.1 Intl.DateTimeFormat.prototype.constructor
- 11.3.2 Intl.DateTimeFormat.prototype.resolvedOptions ( )
- 11.3.3 get Intl.DateTimeFormat.prototype.format
- 11.3.4 Intl.DateTimeFormat.prototype.formatRange ( startDate, endDate )
- 11.3.5 Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate, endDate )
- 11.3.6 Intl.DateTimeFormat.prototype.formatToParts ( date )
- 11.3.7 Intl.DateTimeFormat.prototype [ %Symbol.toStringTag% ]
- 11.4 Properties of Intl.DateTimeFormat Instances
- +11.5 Abstract Operations for DateTimeFormat Objects
- 11.5.1 DateTimeStyleFormat ( dateStyle, timeStyle, styles )
- 11.5.2 BasicFormatMatcher ( options, formats )
- 11.5.3 BestFitFormatMatcher ( options, formats )
- 11.5.4 DateTime Format Functions
- 11.5.5 FormatDateTimePattern ( dateTimeFormat, format, pattern, epochNanoseconds )
- 11.5.6 PartitionDateTimePattern ( dateTimeFormat, x )
- 11.5.7 FormatDateTime ( dateTimeFormat, x )
- 11.5.8 FormatDateTimeToParts ( dateTimeFormat, x )
- 11.5.9 PartitionDateTimeRangePattern ( dateTimeFormat, x, y )
- 11.5.10 FormatDateTimeRange ( dateTimeFormat, x, y )
- 11.5.11 FormatDateTimeRangeToParts ( dateTimeFormat, x, y )
- 11.5.12 ToLocalTime ( epochNs, calendar, timeZoneIdentifier )
- 11.5.13 ToLocalTime Records
- 11.5.14 UnwrapDateTimeFormat ( dtf )
- +12 DisplayNames Objects
- +13 DurationFormat Objects
- +13.1 The Intl.DurationFormat Constructor
- +13.2 Properties of the Intl.DurationFormat Constructor
- +13.3 Properties of the Intl.DurationFormat Prototype Object
- 13.4 Properties of Intl.DurationFormat Instances
- +13.5 Abstract Operations for DurationFormat Objects
- 13.5.1 Duration Records
- 13.5.2 ToIntegerIfIntegral ( argument )
- 13.5.3 ToDurationRecord ( input )
- 13.5.4 DurationSign ( duration )
- 13.5.5 IsValidDuration ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds )
- +13.5.6 GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle, twoDigitHours )
- 13.5.7 ComputeFractionalDigits ( durationFormat, duration )
- 13.5.8 NextUnitFractional ( durationFormat, unit )
- 13.5.9 FormatNumericHours ( durationFormat, hoursValue, signDisplayed )
- 13.5.10 FormatNumericMinutes ( durationFormat, minutesValue, hoursDisplayed, signDisplayed )
- 13.5.11 FormatNumericSeconds ( durationFormat, secondsValue, minutesDisplayed, signDisplayed )
- 13.5.12 FormatNumericUnits ( durationFormat, duration, firstNumericUnit, signDisplayed )
- 13.5.13 IsFractionalSecondUnitName ( unit )
- 13.5.14 ListFormatParts ( durationFormat, partitionedPartsList )
- 13.5.15 PartitionDurationFormatPattern ( durationFormat, duration )
- +14 ListFormat Objects
- +15 Locale Objects
- +15.1 The Intl.Locale Constructor
- +15.2 Properties of the Intl.Locale Constructor
- +15.3 Properties of the Intl.Locale Prototype Object
- 15.3.1 Intl.Locale.prototype.constructor
- 15.3.2 get Intl.Locale.prototype.baseName
- 15.3.3 get Intl.Locale.prototype.calendar
- 15.3.4 get Intl.Locale.prototype.caseFirst
- 15.3.5 get Intl.Locale.prototype.collation
- 15.3.6 get Intl.Locale.prototype.hourCycle
- 15.3.7 get Intl.Locale.prototype.language
- 15.3.8 Intl.Locale.prototype.maximize ( )
- 15.3.9 Intl.Locale.prototype.minimize ( )
- 15.3.10 get Intl.Locale.prototype.numberingSystem
- 15.3.11 get Intl.Locale.prototype.numeric
- 15.3.12 get Intl.Locale.prototype.region
- 15.3.13 get Intl.Locale.prototype.script
- 15.3.14 Intl.Locale.prototype.toString ( )
- 15.3.15 get Intl.Locale.prototype.variants
- 15.3.16 Intl.Locale.prototype [ %Symbol.toStringTag% ]
- 15.4 Properties of Intl.Locale Instances
- +15.5 Abstract Operations for Locale Objects
- +16 NumberFormat Objects
- +16.1 The Intl.NumberFormat Constructor
- +16.2 Properties of the Intl.NumberFormat Constructor
- +16.3 Properties of the Intl.NumberFormat Prototype Object
- 16.3.1 Intl.NumberFormat.prototype.constructor
- 16.3.2 Intl.NumberFormat.prototype.resolvedOptions ( )
- 16.3.3 get Intl.NumberFormat.prototype.format
- 16.3.4 Intl.NumberFormat.prototype.formatRange ( start, end )
- 16.3.5 Intl.NumberFormat.prototype.formatRangeToParts ( start, end )
- 16.3.6 Intl.NumberFormat.prototype.formatToParts ( value )
- 16.3.7 Intl.NumberFormat.prototype [ %Symbol.toStringTag% ]
- 16.4 Properties of Intl.NumberFormat Instances
- +16.5 Abstract Operations for NumberFormat Objects
- 16.5.1 CurrencyDigits ( currency )
- 16.5.2 Number Format Functions
- 16.5.3 FormatNumericToString ( intlObject, x )
- 16.5.4 PartitionNumberPattern ( numberFormat, x )
- 16.5.5 PartitionNotationSubPattern ( numberFormat, x, n, exponent )
- 16.5.6 FormatNumeric ( numberFormat, x )
- 16.5.7 FormatNumericToParts ( numberFormat, x )
- 16.5.8 ToRawPrecision ( x, minPrecision, maxPrecision, unsignedRoundingMode )
- 16.5.9 ToRawFixed ( x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode )
- 16.5.10 UnwrapNumberFormat ( nf )
- 16.5.11 GetNumberFormatPattern ( numberFormat, x )
- 16.5.12 GetNotationSubPattern ( numberFormat, exponent )
- 16.5.13 ComputeExponent ( numberFormat, x )
- 16.5.14 ComputeExponentForMagnitude ( numberFormat, magnitude )
- 16.5.15 RS: StringIntlMV
- 16.5.16 ToIntlMathematicalValue ( value )
- 16.5.17 GetUnsignedRoundingMode ( roundingMode, sign )
- 16.5.18 ApplyUnsignedRoundingMode ( x, r1, r2, unsignedRoundingMode )
- 16.5.19 PartitionNumberRangePattern ( numberFormat, x, y )
- 16.5.20 FormatApproximately ( numberFormat, result )
- 16.5.21 CollapseNumberRange ( numberFormat, result )
- 16.5.22 FormatNumericRange ( numberFormat, x, y )
- 16.5.23 FormatNumericRangeToParts ( numberFormat, x, y )
- +17 PluralRules Objects
- +18 RelativeTimeFormat Objects
- +18.1 The Intl.RelativeTimeFormat Constructor
- +18.2 Properties of the Intl.RelativeTimeFormat Constructor
- +18.3 Properties of the Intl.RelativeTimeFormat Prototype Object
- 18.3.1 Intl.RelativeTimeFormat.prototype.constructor
- 18.3.2 Intl.RelativeTimeFormat.prototype.resolvedOptions ( )
- 18.3.3 Intl.RelativeTimeFormat.prototype.format ( value, unit )
- 18.3.4 Intl.RelativeTimeFormat.prototype.formatToParts ( value, unit )
- 18.3.5 Intl.RelativeTimeFormat.prototype [ %Symbol.toStringTag% ]
- 18.4 Properties of Intl.RelativeTimeFormat Instances
- +18.5 Abstract Operations for RelativeTimeFormat Objects
- +19 Segmenter Objects
- +19.1 The Intl.Segmenter Constructor
- +19.2 Properties of the Intl.Segmenter Constructor
- +19.3 Properties of the Intl.Segmenter Prototype Object
- 19.4 Properties of Intl.Segmenter Instances
- +19.5 Segments Objects
- +19.6 Segment Iterator Objects
- +19.7 Segment Data Objects
- +19.8 Abstract Operations for Segmenter Objects
- +20 Locale Sensitive Functions of the ECMAScript Language Specification
- Annex A (informative) Implementation Dependent Behaviour
- Annex B (informative) Additions and Changes That Introduce Incompatibilities with Prior Editions
- Annex C (informative) Colophon
- Copyright & Software License
Draft ECMA-402 / September 11, 2025
ECMAScript® 2026 Internationalization API Specification
Contributing to this Specification
This specification is developed on GitHub with the help of the ECMAScript community. There are a number of ways to contribute to the development of this specification:
- GitHub Repository: https://github.com/tc39/ecma402
- Issues: All Issues, File a New Issue
- Pull Requests: All Pull Requests, Create a New Pull Request
- Test Suite: Test262
- TC39-TG2:
- Convener: Shane F. Carr (@sffc)
- Admin group: contact by email
- Editors:
-
Community:
- Matrix: #tc39:matrix.org
- Matrix: #tc39-ecma402:matrix.org
Refer to the
Introduction
This specification's source can be found at https://github.com/tc39/ecma402.
The ECMAScript 2026 Internationalization API Specification (ECMA-402 13th Edition), provides key language sensitive functionality as a complement to
The 1st Edition API was developed by an ad-hoc group established by Ecma TC39 in September 2010 based on a proposal by Nebojša Ćirić and Jungshik Shin.
The 2nd Edition API was adopted by the General Assembly of June 2015, as a complement to the ECMAScript 6th Edition.
The 3rd Edition API was the first edition released under Ecma TC39's new yearly release cadence and open development process. A plain-text source document was built from the ECMA-402 source document to serve as the base for further development entirely on GitHub. Over the year of this standard's development, dozens of pull requests and issues were filed representing several of bug fixes, editorial fixes and other improvements. Additionally, numerous software tools were developed to aid in this effort including Ecmarkup, Ecmarkdown, and Grammarkdown.
Dozens of individuals representing many organizations have made very significant contributions within Ecma TC39 to the development of this edition and to the prior editions. In addition, a vibrant community has emerged supporting TC39's ECMAScript efforts. This community has reviewed numerous drafts, filed dozens of bug reports, performed implementation experiments, contributed test suites, and educated the world-wide developer community about ECMAScript Internationalization. Unfortunately, it is impossible to identify and acknowledge every person and organization who has contributed to this effort.
Norbert Lindenberg
ECMA-402, 1st Edition Project Editor
Rick Waldron
ECMA-402, 2nd Edition Project Editor
Caridy Patiño
ECMA-402, 3rd, 4th and 5th Editions Project Editor
Caridy Patiño, Daniel Ehrenberg, Leo Balter
ECMA-402, 6th Edition Project Editors
Leo Balter, Valerie Young, Isaac Durazo
ECMA-402, 7th Edition Project Editors
Leo Balter, Richard Gibson
ECMA-402, 8th Edition Project Editors
Leo Balter, Richard Gibson, Ujjwal Sharma
ECMA-402, 9th Edition Project Editors
Richard Gibson, Ujjwal Sharma
ECMA-402, 10th Edition Project Editors
Richard Gibson, Ujjwal Sharma
ECMA-402, 11th Edition Project Editors
Ben Allen, Richard Gibson, Ujjwal Sharma
ECMA-402, 12th Edition Project Editors
Ben Allen, Richard Gibson, Ujjwal Sharma
ECMA-402, 13th Edition Project Editors
1 Scope
This Standard defines the application programming interface for ECMAScript objects that support programs that need to adapt to the linguistic and cultural conventions used by different human languages and countries.
2 Conformance
A conforming implementation of this specification must conform to
A conforming implementation is permitted to provide additional objects, properties, and functions beyond those described in this specification. In particular, a conforming implementation is permitted to provide properties not described in this specification, and values for those properties, for objects that are described herein. A conforming implementation is not permitted to add optional arguments to the functions defined in this specification.
A conforming implementation is permitted to accept additional values, and then have
- The options property
"localeMatcher" in allconstructors andsupportedLocalesOf
methods. - The options properties
"usage" and"sensitivity" in the Collatorconstructor . - The options properties
"style" ,"currencyDisplay" ,"notation" ,"compactDisplay" ,"signDisplay" ,"currencySign" , and"unitDisplay" in the NumberFormatconstructor . - The options properties
"minimumIntegerDigits" ,"minimumFractionDigits" ,"maximumFractionDigits" ,"minimumSignificantDigits" , and"maximumSignificantDigits" in the NumberFormatconstructor , provided that the additional values are interpreted asinteger values higher than the specified limits. - The options properties listed in
Table 16 in the DateTimeFormatconstructor . - The options property
"formatMatcher" in the DateTimeFormatconstructor . - The options properties
"minimumIntegerDigits" ,"minimumFractionDigits" ,"maximumFractionDigits" , and"minimumSignificantDigits" in the PluralRulesconstructor , provided that the additional values are interpreted asinteger values higher than the specified limits. - The options property
"type" in the PluralRulesconstructor . - The options property
"style" and"numeric" in the RelativeTimeFormatconstructor . - The options property
"style" and"type" in the DisplayNamesconstructor .
3 Normative References
The following referenced documents are required for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.
ECMAScript 2026 Language Specification (ECMA-262 17th Edition, or successor).
https://www.ecma-international.org/publications/standards/Ecma-262.htm
- ISO/IEC 10646:2014: Information Technology – Universal Multiple-Octet Coded Character Set (UCS) plus Amendment 1:2015 and Amendment 2, plus additional amendments and corrigenda, or successor
- ISO 4217:2015, Codes for the representation of currencies and funds, or successor
- IETF RFC 4647, Matching of Language Tags, or successor
- IANA Time Zone Database
- The Unicode Standard
- Unicode Standard Annex #29: Unicode Text Segmentation
- Unicode Technical Standard #10: Unicode Collation Algorithm
- Unicode Technical Standard #35: Unicode Locale Data Markup Language (LDML)
4 Overview
This section is non-normative.
4.1 Internationalization, Localization, and Globalization
Internationalization of software means designing it such that it supports or can be easily adapted to support the needs of users speaking different languages and having different cultural expectations, and enables worldwide communication between them. Localization then is the actual adaptation to a specific language and culture. Globalization of software is commonly understood to be the combination of internationalization and localization. Globalization starts at the lowest level by using a text representation that supports all languages in the world, and using standard identifiers to identify languages, countries, time zones, and other relevant parameters. It continues with using a user interface language and data presentation that the user understands, and finally often requires product-specific adaptations to the user's language, culture, and environment.
4.2 API Overview
This specification is designed to complement
This specification provides several key pieces of language-sensitive functionality that are required in most applications: locale selection and inspection, string comparison (collation) and case conversion, pluralization rules, text segmentation, and formatting of numbers, absolute and relative dates and times, durations, and lists. While toLocaleString
; on localeCompare
, toLocaleLowerCase
, toLocaleUpperCase
; on toLocaleString
; on toLocaleString
, toLocaleDateString
, and toLocaleTimeString
), their actual behaviour is left largely implemenation-defined. This specification provides additional functionality, control over the language and over details of the behaviour to be used, and a more complete specification of required functionality.
Applications can use the API in two ways:
-
Directly, by using a
service constructor to construct an object, specifying a list of preferred languages and options to configure its behaviour. The object provides a main function (compare
,select
,format
, etc.), which can be called repeatedly. It also provides aresolvedOptions
function, which the application can use to find out the exact configuration of the object. -
Indirectly, by using the functions of
ECMA-262 mentioned above. The collation and formatting functions are respecified in this specification to accept the same arguments as the Collator, NumberFormat, and DateTimeFormatconstructors and produce the same results as their compare or format methods. The case conversion functions are respecified to accept a list of preferred languages.
The
4.3 API Conventions
Every
4.4 Implementation Dependencies
Due to the nature of internationalization, this specification has to leave several details implementation dependent:
-
The set of locales that an implementation supports with adequate localizations: Linguists have described thousands of human languages, with the IANA Language
Subtag Registry containing over 7000 primary languagesubtags (used as the base for locale identifiers). Even large locale data collections, such as the Common Locale Data Repository, cover only a tiny subset of all languages and their regional or dialectical variations. Implementations targeting resource-constrained devices may have to further reduce the subset. - The exact form of localizations such as format patterns: In many cases locale-dependent conventions are not standardized, so different forms may exist side by side, or they vary over time. Different internationalization libraries may have implemented different forms, without any of them being actually wrong. In order to allow this API to be implemented on top of existing libraries, such variations have to be permitted.
- Subsets of Unicode: Some operations, such as collation, operate on strings that can include characters from the entire Unicode character set. However, both the Unicode Standard and the ECMAScript standard allow implementations to limit their functionality to subsets of the Unicode character set. In addition, locale conventions typically don't specify the desired behaviour for the entire Unicode character set, but only for those characters that are relevant for the locale. While the Unicode Collation Algorithm combines a default collation order for the entire Unicode character set with the ability to tailor for local conventions, subsets and tailorings still result in differences in behaviour.
In browser implementations the initial set of locales, currencies, calendars, numbering systems, and other enumerable items visible to a particular origin must be the same for all users sharing the same user
Throughout this specification, implementation- and locale-dependent behaviour is referred to as ILD, and implementation-, locale-, and numbering system-dependent behaviour is referred to as ILND.
4.4.1 Compatibility across implementations
ECMA 402 describes the schema of the data used by its functions. The data contained inside is implementation-dependent, and expected to change over time and vary between implementations. The variation is visible by programmers, and it is possible to construct programs which will depend on a particular output. However, this specification attempts to describe reasonable constraints which will allow well-written programs to function across implementations. Implementations are encouraged to continue their efforts to harmonize linguistic data.
5 Notational Conventions
This standard uses a subset of the notational conventions of
- Object Internal Methods and Internal Slots, as described in
Object Internal Methods and Internal Slots . - Algorithm conventions, as described in
Algorithm Conventions , and the use ofabstract operations as described inType Conversion ,Testing and Comparison Operations ,Operations on Objects , andOperations on Iterator Objects . - Internal Slots, as described in
Ordinary Object Internal Methods and Internal Slots . - The
List andRecord Specification Type, as described inThe List and Record Specification Types .
As an extension to the
This specification uses blocks demarcated as
5.1 Well-Known Intrinsic Objects
The following table extends the Well-Known Intrinsic Objects table defined in
Intrinsic Name | Global Name | ECMAScript Language Association |
---|---|---|
Intl |
The Intl object ( |
|
Intl.Collator |
The Intl.Collator |
|
Intl.DateTimeFormat |
The Intl.DateTimeFormat |
|
Intl.DisplayNames |
The Intl.DisplayNames |
|
Intl.DurationFormat |
The Intl.DurationFormat |
|
Intl.ListFormat |
The Intl.ListFormat |
|
Intl.Locale |
The Intl.Locale |
|
Intl.NumberFormat |
The Intl.NumberFormat |
|
Intl.PluralRules |
The Intl.PluralRules |
|
Intl.RelativeTimeFormat |
The Intl.RelativeTimeFormat |
|
Intl.Segmenter |
The Intl.Segmenter |
|
The prototype of |
||
The prototype of Segments objects ( |
6 Identification of Locales, Currencies, Time Zones, Measurement Units, Numbering Systems, Collations, and Calendars
This clause describes the String values used in this specification to identify locales, currencies, time zones, measurement units, numbering systems, collations, calendars, and pattern strings.
6.1 Case Sensitivity and Case Mapping
The String values used to identify locales, currencies, scripts, and time zones are interpreted in an ASCII-case-insensitive manner, treating the code units 0x0041 through 0x005A (corresponding to Unicode characters LATIN CAPITAL LETTER A through LATIN CAPITAL LETTER Z) as equivalent to the corresponding code units 0x0061 through 0x007A (corresponding to Unicode characters LATIN SMALL LETTER A through LATIN SMALL LETTER Z), both inclusive. No other case folding equivalences are applied.
The ASCII-uppercase of a String value S is the String value derived from S by replacing each occurrence of an ASCII lowercase letter code unit (0x0061 through 0x007A, inclusive) with the corresponding ASCII uppercase letter code unit (0x0041 through 0x005A, inclusive) while preserving all other code units.
The ASCII-lowercase of a String value S is the String value derived from S by replacing each occurrence of an ASCII uppercase letter code unit (0x0041 through 0x005A, inclusive) with the corresponding ASCII lowercase letter code unit (0x0061 through 0x007A, inclusive) while preserving all other code units.
A String value A is an ASCII-case-insensitive match for String value B if the ASCII-uppercase of A is exactly the same sequence of code units as the ASCII-uppercase of B. A sequence of Unicode code points A is an ASCII-case-insensitive match for B if B is an ASCII-case-insensitive match for
6.2 Language Tags
This specification identifies locales using Unicode BCP 47 locale identifiers as defined by Unicode Technical Standard #35 Part 1 Core, Section 3.3 BCP 47 Conformance, and its algorithms refer to Unicode locale nonterminals defined in the grammars of Section 3 Unicode Language and Locale Identifiers. Each such identifier can also be referred to as a language tag, and is in fact a valid language tag as that term is used in BCP 47. A locale identifier in canonical form as specified in Unicode Technical Standard #35 Part 1 Core, Section 3.2.1 Canonical Unicode Locale Identifiers is referred to as a "Unicode canonicalized locale identifier".
Locale identifiers consist of case-insensitive Unicode Basic Latin alphanumeric subtags separated by unicode_locale_extensions
Unicode locale nonterminal and is not part of a
All
6.2.1 IsStructurallyValidLanguageTag ( locale )
The abstract operation IsStructurallyValidLanguageTag takes argument locale (a String) and returns a Boolean. It determines whether locale is a syntactically well-formed
- Let lowerLocale be the
ASCII-lowercase of locale. - If lowerLocale cannot be matched by the
unicode_locale_id
Unicode locale nonterminal , returnfalse . - If lowerLocale uses any of the backwards compatibility syntax described in Unicode Technical Standard #35 Part 1 Core, Section 3.3 BCP 47 Conformance, return
false . - Let baseName be
GetLocaleBaseName (lowerLocale). - Let variants be
GetLocaleVariants (baseName). - If variants is not
undefined , then- If variants contains any duplicate
subtags , returnfalse .
- If variants contains any duplicate
- Let extensions be the suffix of lowerLocale following baseName.
- NOTE: A
"-x-…" private usesubtag sequence matched by thepu_extensions
Unicode locale nonterminal must be ignored, but an isolated final"x" subtag with no following content does not affect any of the below checks. - Let puIndex be
StringIndexOf (extensions,"-x-" , 0). - If puIndex is not
not-found , set extensions to thesubstring of extensions from 0 to puIndex. - If extensions is not the empty String, then
- If extensions contains any duplicate
singleton subtags , returnfalse . - Let transformExtension be the longest
substring of extensions matched by thetransformed_extensions
Unicode locale nonterminal . If there is no suchsubstring , returntrue . Assert : Thesubstring of transformExtension from 0 to 3 is"-t-" .- Let tPrefix be the
substring of transformExtension from 3. - Let tlang be the longest prefix of tPrefix matched by the
tlang
Unicode locale nonterminal . If there is no such prefix, returntrue . - Let tlangVariants be
GetLocaleVariants (tlang). - If tlangVariants contains any duplicate
subtags , returnfalse .
- If extensions contains any duplicate
- Return
true .
6.2.2 CanonicalizeUnicodeLocaleId ( locale )
The abstract operation CanonicalizeUnicodeLocaleId takes argument locale (a
- Let localeId be the String value resulting from performing the algorithm to transform locale to canonical form per Unicode Technical Standard #35 Part 1 Core, Annex C LocaleId Canonicalization (note that the algorithm begins with canonicalizing syntax only).
- If localeId contains a
substring that is aUnicode locale extension sequence , then- Let extension be the String value consisting of the
substring of theUnicode locale extension sequence within localeId. - Let newExtension be
"-u" . - Let components be
UnicodeExtensionComponents (extension). - For each element attr of components.[[Attributes]], do
- Set newExtension to the
string-concatenation of newExtension,"-" , and attr.
- Set newExtension to the
- For each
Record { [[Key]], [[Value]] } keyword of components.[[Keywords]], do- Set newExtension to the
string-concatenation of newExtension,"-" , and keyword.[[Key]]. - If keyword.[[Value]] is not the empty String, then
- Set newExtension to the
string-concatenation of newExtension,"-" , and keyword.[[Value]].
- Set newExtension to the
- Set newExtension to the
Assert : newExtension is not"-u" .- Set localeId to a copy of localeId in which the first appearance of
substring extension has been replaced with newExtension.
- Let extension be the String value consisting of the
- Return localeId.
- only the first instance of any attribute duplicated in the input, and
- only the first
keyword for a given key in the input.
6.2.3 DefaultLocale ( )
The
navigator.language
to avoid providing any additional distinguishing information.
6.3 Currency Codes
This specification identifies currencies using 3-letter currency codes as defined by ISO 4217. Their canonical form is uppercase.
All well-formed 3-letter ISO 4217 currency codes are allowed. However, the set of combinations of currency code and
6.3.1 IsWellFormedCurrencyCode ( currency )
The abstract operation IsWellFormedCurrencyCode takes argument currency (a String) and returns a Boolean. It verifies that the currency argument represents a well-formed 3-letter ISO 4217 currency code. It performs the following steps when called:
- If the length of currency is not 3, return
false . - Let normalized be the
ASCII-uppercase of currency. - If normalized contains any code unit outside of 0x0041 through 0x005A (corresponding to Unicode characters LATIN CAPITAL LETTER A through LATIN CAPITAL LETTER Z), return
false . - Return
true .
6.4 AvailableCanonicalCurrencies ( )
The
6.5 Use of the IANA Time Zone Database
Implementations that adopt this specification must be
Each Zone in the IANA Time Zone Database must be a
-
For historical reasons,
"UTC" must be aprimary time zone identifier ."Etc/UTC" ,"Etc/GMT" , and"GMT" , as well as all Link names that resolve to any of them, must be non-primary time identifiers that resolve to"UTC" . -
Any Link name that is present in the “TZ” column of file
zone.tab
must be aprimary time zone identifier . For example, both"Europe/Prague" and"Europe/Bratislava" must beprimary time zone identifiers . This requirement guarantees at least oneprimary time zone identifier for each ISO 3166-1 Alpha-2 country code, and ensures that future changes to time zone rules of one country will not affect ECMAScript programs that use another country's time zone(s), unless those countries' territorial boundaries have also changed. -
Any Link name that is not listed in the “TZ” column of file
zone.tab
and that represents a geographical area entirely contained within the territory of a single ISO 3166-1 Alpha-2 country code must resolve to a primary identifier that also represents a geographical area entirely contained within the territory of the same country code. For example,"Atlantic/Jan_Mayen" must resolve to"Arctic/Longyearbyen" .
The IANA Time Zone Database offers build options that affect which
The Unicode Common Locale Data Repository (CLDR) implements most of the exceptions above when determining which timezone.xml
.
Implementations may also build the IANA Time Zone Database directly, for example by using build options such as PACKRATDATA=backzone PACKRATLIST=zone.tab
and performing any post-processing needed to ensure compliance with the requirements above.
The IANA Time Zone Database is typically updated between five and ten times per year.
These updates may add new Zone or Link names, may change Zones to Links, and may change the UTC offsets and transitions associated with any Zone.
Implementations are recommended to include updates to the IANA Time Zone Database as soon as possible.
Such prompt action ensures that ECMAScript programs can accurately perform time-zone-sensitive calculations and can use newly-added
Although the IANA Time Zone Database maintainers strive for stability, in rare cases (averaging less than once per year) a Zone may be replaced by a new Zone.
For example, in 2022 "
To reduce disruption from these infrequent changes, implementations should initially add each replacement time zone identifier as a
A waiting period should only apply when a new Zone is added to replace an existing Zone. If an existing Zone and Link are swapped, then no renaming has happened and no waiting period is necessary.
If implementations revise time zone information during the lifetime of an
This section complements but does not supersede
6.5.1 AvailableNamedTimeZoneIdentifiers ( )
The
This definition supersedes the definition provided in
- Let identifiers be a
List containing the String value of each Zone or Link name in the IANA Time Zone Database. Assert : No element of identifiers is anASCII-case-insensitive match for any other element.- Sort identifiers according to
lexicographic code unit order . - Let result be a new empty
List . - For each element identifier of identifiers, do
- Let primary be identifier.
- If identifier is a Link name in the IANA Time Zone Database and identifier is not present in the “TZ” column of
zone.tab
of the IANA Time Zone Database, then- Let zone be the Zone name that identifier resolves to, according to the rules for resolving Link names in the IANA Time Zone Database.
- If zone starts with
"Etc/" , then- Set primary to zone.
- Else,
- Let identifierCountryCode be the ISO 3166-1 Alpha-2 country code whose territory contains the geographical area corresponding to identifier.
- Let zoneCountryCode be the ISO 3166-1 Alpha-2 country code whose territory contains the geographical area corresponding to zone.
- If identifierCountryCode is zoneCountryCode, then
- Set primary to zone.
- Else,
- Let countryCodeLineCount be the number of lines in file
zone.tab
of the IANA Time Zone Database where the “country-code” column is identifierCountryCode. - If countryCodeLineCount is 1, then
- Let countryCodeLine be the line in file
zone.tab
of the IANA Time Zone Database where the “country-code” column is identifierCountryCode. - Set primary to the contents of the “TZ” column of countryCodeLine.
- Let countryCodeLine be the line in file
- Else,
- Let backzone be
undefined . - Let backzoneLinkLines be the
List of lines in the filebackzone
of the IANA Time Zone Database that start with either"Link " or"#PACKRATLIST zone.tab Link " . - For each element line of backzoneLinkLines, do
- Let i be
StringIndexOf (line,"Link " , 0). - Set line to the
substring of line from i + 5. - Let backzoneAndLink be
StringSplitToList (line," " ). Assert : backzoneAndLink has at least two elements, and both backzoneAndLink[0] and backzoneAndLink[1] areavailable named time zone identifiers .- If backzoneAndLink[1] is identifier, then
Assert : backzone isundefined .- Set backzone to backzoneAndLink[0].
- Let i be
Assert : backzone is notundefined .- Set primary to backzone.
- Let backzone be
- Let countryCodeLineCount be the number of lines in file
- If primary is one of
"Etc/UTC" ,"Etc/GMT" , or"GMT" , set primary to"UTC" . - If primary is a
replacement time zone identifier and itsrename waiting period has not concluded, then- Let renamedIdentifier be the
renamed time zone identifier that primary replaced. - Set primary to renamedIdentifier.
- Let renamedIdentifier be the
- Let record be the
Time Zone Identifier Record { [[Identifier]]: identifier, [[PrimaryIdentifier]]: primary }. - Append record to result.
Assert : result contains aTime Zone Identifier Record r such that r.[[Identifier]] is"UTC" and r.[[PrimaryIdentifier]] is"UTC" .- Return result.
The algorithm above for resolving Links to icu::TimeZone::getIanaID()
in the International Components for Unicode (ICU) and the processes for maintaining
This algorithm resolves Links to zone.tab
and backzone
of the IANA Time Zone Database.
If the country code of a Link has only one line in zone.tab
, then that line will determine the zone.tab
, then historical mappings in backzone
must be used to identify the correct
For example, to resolve "Pacific/Truk" (in country code "FM") if the default build options of the IANA Time Zone Database identify it as a Link to "Pacific/Port_Moresby" (in country code "PG"), then the “country-code” column of zone.tab
must be checked for lines corresponding with "FM".
If there were only one such line, then the “TZ” column of that line would determine the zone.tab
, then backzone
must be inspected and a line such as "Link Pacific/Chuuk Pacific/Truk" would result in using "Pacific/Chuuk" as the
Note that zone.tab
is the preferred source of mapping data because backzone
mappings may, in rare cases, cross the boundaries of ISO 3166-1 Alpha-2 country codes.
For example, "Atlantic/Jan_Mayen" (in country code "SJ") is mapped in backzone
to "Europe/Oslo" (in country code "NO").
As of the 2024a release of the IANA Time Zone Database, "Atlantic/Jan_Mayen" is the only case where this happens.
6.5.2 GetAvailableNamedTimeZoneIdentifier ( timeZoneIdentifier )
The abstract operation GetAvailableNamedTimeZoneIdentifier takes argument timeZoneIdentifier (a String) and returns either a
- For each element record of
AvailableNamedTimeZoneIdentifiers (), do- If record.[[Identifier]] is an
ASCII-case-insensitive match for timeZoneIdentifier, return record.
- If record.[[Identifier]] is an
- Return
empty .
6.5.3 AvailablePrimaryTimeZoneIdentifiers ( )
The abstract operation AvailablePrimaryTimeZoneIdentifiers takes no arguments and returns a
- Let records be
AvailableNamedTimeZoneIdentifiers (). - Let result be a new empty
List . - For each element timeZoneIdentifierRecord of records, do
- If timeZoneIdentifierRecord.[[Identifier]] is timeZoneIdentifierRecord.[[PrimaryIdentifier]], then
- Append timeZoneIdentifierRecord.[[Identifier]] to result.
- If timeZoneIdentifierRecord.[[Identifier]] is timeZoneIdentifierRecord.[[PrimaryIdentifier]], then
- Return result.
6.5.4 StringSplitToList ( S, separator )
The abstract operation StringSplitToList takes arguments S (a String) and separator (a String) and returns a
Assert : S is not the empty String.Assert : separator is not the empty String.- Let separatorLength be the length of separator.
- Let substrings be a new empty
List . - Let i be 0.
- Let j be
StringIndexOf (S, separator, 0). - Repeat, while j is not
not-found ,- Let T be the
substring of S from i to j. - Append T to substrings.
- Set i to j + separatorLength.
- Set j to
StringIndexOf (S, separator, i).
- Let T be the
- Let T be the
substring of S from i. - Append T to substrings.
- Return substrings.
6.6 Measurement Unit Identifiers
This specification identifies measurement units using a core unit identifier (or equivalently core unit ID) as defined by Unicode Technical Standard #35 Part 2 General, Section 6.2 Unit Identifiers. Their canonical form is a string containing only Unicode Basic Latin lowercase letters (U+0061 LATIN SMALL LETTER A through U+007A LATIN SMALL LETTER Z) with zero or more medial hyphens (U+002D HYPHEN-MINUS).
Only a limited set of core unit identifiers are sanctioned.
Attempting to use an unsanctioned core unit identifier results in a
6.6.1 IsWellFormedUnitIdentifier ( unitIdentifier )
The abstract operation IsWellFormedUnitIdentifier takes argument unitIdentifier (a String) and returns a Boolean. It verifies that the unitIdentifier argument represents a well-formed
- If
IsSanctionedSingleUnitIdentifier (unitIdentifier) istrue , then- Return
true .
- Return
- Let i be
StringIndexOf (unitIdentifier,"-per-" , 0). - If i is
not-found orStringIndexOf (unitIdentifier,"-per-" , i + 1) is notnot-found , then- Return
false .
- Return
Assert : The five-charactersubstring "-per-" occurs exactly once in unitIdentifier, at index i.- Let numerator be the
substring of unitIdentifier from 0 to i. - Let denominator be the
substring of unitIdentifier from i + 5. - If
IsSanctionedSingleUnitIdentifier (numerator) andIsSanctionedSingleUnitIdentifier (denominator) are bothtrue , then- Return
true .
- Return
- Return
false .
6.6.2 IsSanctionedSingleUnitIdentifier ( unitIdentifier )
The abstract operation IsSanctionedSingleUnitIdentifier takes argument unitIdentifier (a String) and returns a Boolean. It verifies that the unitIdentifier argument is among the single unit identifiers sanctioned in the current version of this specification, which are a subset of the Common Locale Data Repository release 38 unit validity data; the list may grow over time. As discussed in Unicode Technical Standard #35 Part 2 General, Section 6.2 Unit Identifiers, a single unit identifier is a
- If unitIdentifier is listed in
Table 2 below, returntrue . - Else, return
false .
Single Unit Identifier |
---|
acre |
bit |
byte |
celsius |
centimeter |
day |
degree |
fahrenheit |
fluid-ounce |
foot |
gallon |
gigabit |
gigabyte |
gram |
hectare |
hour |
inch |
kilobit |
kilobyte |
kilogram |
kilometer |
liter |
megabit |
megabyte |
meter |
microsecond |
mile |
mile-scandinavian |
milliliter |
millimeter |
millisecond |
minute |
month |
nanosecond |
ounce |
percent |
petabyte |
pound |
second |
stone |
terabit |
terabyte |
week |
yard |
year |
6.6.3 AvailableCanonicalUnits ( )
The abstract operation AvailableCanonicalUnits takes no arguments and returns a
6.7 Numbering System Identifiers
This specification identifies numbering systems using a numbering system identifier corresponding with the name referenced by Unicode Technical Standard #35 Part 3 Numbers, Section 1 Numbering Systems. Their canonical form is a string containing only Unicode Basic Latin lowercase letters (U+0061 LATIN SMALL LETTER A through U+007A LATIN SMALL LETTER Z).
6.7.1 AvailableCanonicalNumberingSystems ( )
The
6.8 Collation Types
This specification identifies collations using a collation type as defined by Unicode Technical Standard #35 Part 5 Collation, Section 3.1 Collation Types. Their canonical form is a string containing only Unicode Basic Latin lowercase letters (U+0061 LATIN SMALL LETTER A through U+007A LATIN SMALL LETTER Z) with zero or more medial hyphens (U+002D HYPHEN-MINUS).
6.8.1 AvailableCanonicalCollations ( )
The
6.9 Calendar Types
This specification identifies calendars using a calendar type as defined by Unicode Technical Standard #35 Part 4 Dates, Section 2 Calendar Elements. Their canonical form is a string containing only Unicode Basic Latin lowercase letters (U+0061 LATIN SMALL LETTER A through U+007A LATIN SMALL LETTER Z) with zero or more medial hyphens (U+002D HYPHEN-MINUS).
6.9.1 AvailableCalendars ( )
The
6.10 Pattern String Types
Pattern String
7 Requirements for Standard Built-in ECMAScript Objects
Unless specified otherwise in this document, the objects, functions, and
8 The Intl Object
The Intl object:
- is %Intl%.
- is the initial value of the
"Intl" property of theglobal object . - is an
ordinary object . - has a [[Prototype]] internal slot whose value is
%Object.prototype% . - is not a
function object . - does not have a [[Construct]] internal method; it cannot be used as a
constructor with thenew
operator. - does not have a [[Call]] internal method; it cannot be invoked as a function.
- has a [[FallbackSymbol]] internal slot, which is a new
%Symbol% in the currentrealm with the [[Description]]"IntlLegacyConstructedSymbol" .
8.1 Value Properties of the Intl Object
8.1.1 Intl [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
8.2 Constructor Properties of the Intl Object
With the exception of Intl.Locale, each of the following
8.2.1 Intl.Collator ( . . . )
See
8.2.2 Intl.DateTimeFormat ( . . . )
See
8.2.3 Intl.DisplayNames ( . . . )
See
8.2.4 Intl.DurationFormat ( . . . )
See
8.2.5 Intl.ListFormat ( . . . )
See
8.2.6 Intl.Locale ( . . . )
See
8.2.7 Intl.NumberFormat ( . . . )
See
8.2.8 Intl.PluralRules ( . . . )
See
8.2.9 Intl.RelativeTimeFormat ( . . . )
See
8.2.10 Intl.Segmenter ( . . . )
See
8.3 Function Properties of the Intl Object
8.3.1 Intl.getCanonicalLocales ( locales )
When the getCanonicalLocales
method is called with argument locales, the following steps are taken:
- Let ll be ?
CanonicalizeLocaleList (locales). - Return
CreateArrayFromList (ll).
8.3.2 Intl.supportedValuesOf ( key )
When the supportedValuesOf
method is called with argument key , the following steps are taken:
- Let key be ?
ToString (key). - If key is
"calendar" , then- Let list be a new empty
List . - For each element identifier of
AvailableCalendars (), do- Let canonical be
CanonicalizeUValue ("ca" , identifier). - If identifier is canonical, then
- Append identifier to list.
- Let canonical be
- Let list be a new empty
- Else if key is
"collation" , then- Let list be
AvailableCanonicalCollations ( ).
- Let list be
- Else if key is
"currency" , then- Let list be
AvailableCanonicalCurrencies ( ).
- Let list be
- Else if key is
"numberingSystem" , then- Let list be
AvailableCanonicalNumberingSystems ( ).
- Let list be
- Else if key is
"timeZone" , then- Let list be
AvailablePrimaryTimeZoneIdentifiers ( ).
- Let list be
- Else if key is
"unit" , then- Let list be
AvailableCanonicalUnits ( ).
- Let list be
- Else,
- Throw a
RangeError exception.
- Throw a
- Return
CreateArrayFromList ( list ).
9 Locale and Parameter Negotiation
An Available Locales List is an arbitrarily-ordered duplicate-free
A Language Priority List is a
A Resolution Option Descriptor is a
9.1 Internal slots of Service Constructors
Each
- [[AvailableLocales]] is an
Available Locales List . It must include the value returned byDefaultLocale . Additionally, for each element with more than onesubtag , it must also include a less narrowlanguage tag with the same languagesubtag and a strict subset of the same followingsubtags (i.e., omitting one or more) to serve as a potential fallback fromResolveLocale . In particular, each element with a languagesubtag and a scriptsubtag and a regionsubtag must be accompanied by another element consisting of only the same languagesubtag and regionsubtag but missing the scriptsubtag . For example,- If [[AvailableLocales]] contains
"de-DE" , then it must also contain"de" (which might be selected to satisfy requested locales such as"de-AT" and"de-CH" ). - If [[AvailableLocales]] contains
"az-Latn-AZ" , then it must also contain"az-AZ" (which might be selected to satisfy requested locales such as"az-Cyrl-AZ" if"az-Cyrl" is unavailable).
- If [[AvailableLocales]] contains
- [[RelevantExtensionKeys]] is a
List ofUnicode locale extension sequence keys defined in Unicode Technical Standard #35 Part 1 Core, Section 3.6.1 Key and Type Definitions that are relevant for the functionality of the constructed objects. - [[ResolutionOptionDescriptors]] is a
List ofResolution Option Descriptors used for reading options during object construction. - [[SortLocaleData]] and [[SearchLocaleData]] (for Intl.Collator) and [[LocaleData]] (for every other
service constructor ) areRecords . In addition to fields specific to itsservice constructor , each suchRecord has a field for each locale contained in [[AvailableLocales]]. The value of each such locale-named field is aRecord in which each element of [[RelevantExtensionKeys]] identifies the name of a field whose value is a non-emptyList of Strings representing the type values that are supported by the implementation in the relevant locale for the correspondingUnicode locale extension sequence key, with the first element providing the default value for that key in the locale.
9.2 Abstract Operations
9.2.1 CanonicalizeLocaleList ( locales )
The abstract operation CanonicalizeLocaleList takes argument locales (an
- If locales is
undefined , then- Return a new empty
List .
- Return a new empty
- Let seen be a new empty
List . - If locales
is a String or localesis an Object and locales has an [[InitializedLocale]] internal slot, then- Let O be
CreateArrayFromList (« locales »).
- Let O be
- Else,
- Let O be ?
ToObject (locales).
- Let O be ?
- Let len be ?
LengthOfArrayLike (O). - Let k be 0.
- Repeat, while k < len,
- Let Pk be !
ToString (𝔽 (k)). - Let kPresent be ?
HasProperty (O, Pk). - If kPresent is
true , then- Let kValue be ?
Get (O, Pk). - If kValue
is not a String and kValueis not an Object , throw aTypeError exception. - If kValue
is an Object and kValue has an [[InitializedLocale]] internal slot, then- Let tag be kValue.[[Locale]].
- Else,
- Let tag be ?
ToString (kValue).
- Let tag be ?
- If
IsStructurallyValidLanguageTag (tag) isfalse , throw aRangeError exception. - Let canonicalizedTag be
CanonicalizeUnicodeLocaleId (tag). - If seen does not contain canonicalizedTag, append canonicalizedTag to seen.
- Let kValue be ?
- Set k to k + 1.
- Let Pk be !
- Return seen.
9.2.2 CanonicalizeUValue ( ukey, uvalue )
The abstract operation CanonicalizeUValue takes arguments ukey (a
- Let lowerValue be the
ASCII-lowercase of uvalue. - Let canonicalized be the String value resulting from canonicalizing lowerValue as a value of key ukey per Unicode Technical Standard #35 Part 1 Core, Annex C LocaleId Canonicalization Section 5 Canonicalizing Syntax, Processing LocaleIds.
- NOTE: It is recommended that implementations use the 'u' extension data in
common/bcp47
provided by the Common Locale Data Repository (available at https://cldr.unicode.org/). - Return canonicalized.
9.2.3 LookupMatchingLocaleByPrefix ( availableLocales, requestedLocales )
The abstract operation LookupMatchingLocaleByPrefix takes arguments availableLocales (an
- For each element locale of requestedLocales, do
- Let extension be
empty . - If locale contains a
Unicode locale extension sequence , then- Set extension to the
Unicode locale extension sequence of locale. - Set locale to the String value that is locale with any
Unicode locale extension sequences removed.
- Set extension to the
- Let prefix be locale.
- Repeat, while prefix is not the empty String,
- If availableLocales contains prefix, return the
Record { [[locale]]: prefix, [[extension]]: extension }. - If prefix contains
"-" (code unit 0x002D HYPHEN-MINUS), let pos be the index into prefix of the last occurrence of"-" ; else let pos be 0. - Repeat, while pos ≥ 2 and the
substring of prefix from pos - 2 to pos - 1 is"-" ,- Set pos to pos - 2.
- Set prefix to the
substring of prefix from 0 to pos.
- If availableLocales contains prefix, return the
- Let extension be
- Return
undefined .
9.2.4 LookupMatchingLocaleByBestFit ( availableLocales, requestedLocales )
The
9.2.5 UnicodeExtensionComponents ( extension )
The abstract operation UnicodeExtensionComponents takes argument extension (a
Assert : TheASCII-lowercase of extension is extension.Assert : Thesubstring of extension from 0 to 3 is"-u-" .- Let attributes be a new empty
List . - Let keywords be a new empty
List . - Let keyword be
undefined . - Let size be the length of extension.
- Let k be 3.
- Repeat, while k < size,
- Let e be
StringIndexOf (extension,"-" , k). - If e is
not-found , let len be size - k; else let len be e - k. - Let subtag be the
substring of extension from k to k + len. - NOTE: A
keyword is a sequence ofsubtags in which the first is a key of length 2 and any subsequent ones (if present) have length in theinclusive interval from 3 to 8, collectively constituting a value along with their medial"-" separators. An attribute is a singlesubtag with length in theinclusive interval from 3 to 8 that precedes allkeywords . Assert : len ≥ 2.- If keyword is
undefined and len ≠ 2, then- If subtag is not an element of attributes, append subtag to attributes.
- Else if len = 2, then
- Set keyword to the
Record { [[Key]]: subtag, [[Value]]:"" }. - If keywords does not contain an element whose [[Key]] is keyword.[[Key]], append keyword to keywords.
- Set keyword to the
- Else if keyword.[[Value]] is the empty String, then
- Set keyword.[[Value]] to subtag.
- Else,
- Set keyword.[[Value]] to the
string-concatenation of keyword.[[Value]],"-" , and subtag.
- Set keyword.[[Value]] to the
- Set k to k + len + 1.
- Let e be
- Return the
Record { [[Attributes]]: attributes, [[Keywords]]: keywords }.
9.2.6 InsertUnicodeExtensionAndCanonicalize ( locale, attributes, keywords )
The abstract operation InsertUnicodeExtensionAndCanonicalize takes arguments locale (a
Assert : locale does not contain aUnicode locale extension sequence .- Let extension be
"-u" . - For each element attr of attributes, do
- Set extension to the
string-concatenation of extension,"-" , and attr.
- Set extension to the
- For each
Record { [[Key]], [[Value]] } keyword of keywords, do- Set extension to the
string-concatenation of extension,"-" , and keyword.[[Key]]. - If keyword.[[Value]] is not the empty String, set extension to the
string-concatenation of extension,"-" , and keyword.[[Value]].
- Set extension to the
- If extension is
"-u" , returnCanonicalizeUnicodeLocaleId (locale). - Let privateIndex be
StringIndexOf (locale,"-x-" , 0). - If privateIndex is
not-found , then- Let newLocale be the
string-concatenation of locale and extension.
- Let newLocale be the
- Else,
- Let preExtension be the
substring of locale from 0 to privateIndex. - Let postExtension be the
substring of locale from privateIndex. - Let newLocale be the
string-concatenation of preExtension, extension, and postExtension.
- Let preExtension be the
Assert :IsStructurallyValidLanguageTag (newLocale) istrue .- Return
CanonicalizeUnicodeLocaleId (newLocale).
9.2.7 ResolveLocale ( availableLocales, requestedLocales, options, relevantExtensionKeys, localeData )
The abstract operation ResolveLocale takes arguments availableLocales (an keyword
key
value is not contained within relevantExtensionKeys or type
value is superseded by a different value from options. It performs the following steps when called:
- Let matcher be options.[[localeMatcher]].
- If matcher is
"lookup" , then- Let r be
LookupMatchingLocaleByPrefix (availableLocales, requestedLocales).
- Let r be
- Else,
- Let r be
LookupMatchingLocaleByBestFit (availableLocales, requestedLocales).
- Let r be
- If r is
undefined , set r to theRecord { [[locale]]:DefaultLocale (), [[extension]]:empty }. - Let foundLocale be r.[[locale]].
- Let foundLocaleData be localeData.[[<foundLocale>]].
Assert : foundLocaleData is aRecord .- Let result be a new
Record . - Set result.[[LocaleData]] to foundLocaleData.
- If r.[[extension]] is not
empty , then- Let components be
UnicodeExtensionComponents (r.[[extension]]). - Let keywords be components.[[Keywords]].
- Let components be
- Else,
- Let keywords be a new empty
List .
- Let keywords be a new empty
- Let supportedKeywords be a new empty
List . - For each element key of relevantExtensionKeys, do
- Let keyLocaleData be foundLocaleData.[[<key>]].
Assert : keyLocaleData is aList .- Let value be keyLocaleData[0].
Assert : valueis a String or value isnull .- Let supportedKeyword be
empty . - If keywords contains an element whose [[Key]] is key, then
- Let entry be the element of keywords whose [[Key]] is key.
- Let requestedValue be entry.[[Value]].
- If requestedValue is not the empty String, then
- If keyLocaleData contains requestedValue, then
- Set value to requestedValue.
- Set supportedKeyword to the
Record { [[Key]]: key, [[Value]]: value }.
- If keyLocaleData contains requestedValue, then
- Else if keyLocaleData contains
"true" , then- Set value to
"true" . - Set supportedKeyword to the
Record { [[Key]]: key, [[Value]]:"" }.
- Set value to
Assert : options has a field [[<key>]].- Let optionsValue be options.[[<key>]].
Assert : optionsValueis a String , or optionsValue is eitherundefined ornull .- If optionsValue
is a String , then- Let ukey be the
ASCII-lowercase of key. - Set optionsValue to
CanonicalizeUValue (ukey, optionsValue). - If optionsValue is the empty String, then
- Set optionsValue to
"true" .
- Set optionsValue to
- Let ukey be the
- If
SameValue (optionsValue, value) isfalse and keyLocaleData contains optionsValue, then- Set value to optionsValue.
- Set supportedKeyword to
empty .
- If supportedKeyword is not
empty , append supportedKeyword to supportedKeywords. - Set result.[[<key>]] to value.
- If supportedKeywords is not empty, then
- Let supportedAttributes be a new empty
List . - Set foundLocale to
InsertUnicodeExtensionAndCanonicalize (foundLocale, supportedAttributes, supportedKeywords).
- Let supportedAttributes be a new empty
- Set result.[[Locale]] to foundLocale.
- Return result.
9.2.8 ResolveOptions ( constructor, localeData, locales, options [ , specialBehaviours [ , modifyResolutionOptions ] ] )
The abstract operation ResolveOptions takes arguments constructor (a
- Let requestedLocales be ?
CanonicalizeLocaleList (locales). - If specialBehaviours is present and contains
require-options and options isundefined , throw aTypeError exception. - If specialBehaviours is present and contains
coerce-options , set options to ?CoerceOptionsToObject (options). Otherwise, set options to ?GetOptionsObject (options). - Let matcher be ?
GetOption (options,"localeMatcher" ,string , «"lookup" ,"best fit" »,"best fit" ). - Let opt be the
Record { [[localeMatcher]]: matcher }. - For each
Resolution Option Descriptor desc of constructor.[[ResolutionOptionDescriptors]], do- If desc has a [[Type]] field, let type be desc.[[Type]]. Otherwise, let type be
string . - If desc has a [[Values]] field, let values be desc.[[Values]]. Otherwise, let values be
empty . - Let value be ?
GetOption (options, desc.[[Property]], type, values,undefined ). - If value is not
undefined , then- Set value to !
ToString (value). - If value cannot be matched by the
type
Unicode locale nonterminal , throw aRangeError exception.
- Set value to !
- Let key be desc.[[Key]].
- Set opt.[[<key>]] to value.
- If desc has a [[Type]] field, let type be desc.[[Type]]. Otherwise, let type be
- If modifyResolutionOptions is present, perform ! modifyResolutionOptions(opt).
- Let resolution be
ResolveLocale (constructor.[[AvailableLocales]], requestedLocales, opt, constructor.[[RelevantExtensionKeys]], localeData). - Return the
Record { [[Options]]: options, [[ResolvedLocale]]: resolution, [[ResolutionOptions]]: opt }.
9.2.9 FilterLocales ( availableLocales, requestedLocales, options )
The abstract operation FilterLocales takes arguments availableLocales (an
- Set options to ?
CoerceOptionsToObject (options). - Let matcher be ?
GetOption (options,"localeMatcher" ,string , «"lookup" ,"best fit" »,"best fit" ). - Let subset be a new empty
List . - For each element locale of requestedLocales, do
- If matcher is
"lookup" , then- Let match be
LookupMatchingLocaleByPrefix (availableLocales, « locale »).
- Let match be
- Else,
- Let match be
LookupMatchingLocaleByBestFit (availableLocales, « locale »).
- Let match be
- If match is not
undefined , append locale to subset.
- If matcher is
- Return
CreateArrayFromList (subset).
9.2.10 GetOptionsObject ( options )
The abstract operation GetOptionsObject takes argument options (an
- If options is
undefined , then- Return
OrdinaryObjectCreate (null ).
- Return
- If options
is an Object , then- Return options.
- Throw a
TypeError exception.
9.2.11 CoerceOptionsToObject ( options )
The abstract operation CoerceOptionsToObject takes argument options (an
- If options is
undefined , then- Return
OrdinaryObjectCreate (null ).
- Return
- Return ?
ToObject (options).
9.2.12 GetOption ( options, property, type, values, default )
The abstract operation GetOption takes arguments options (an Object), property (a
9.2.13 GetBooleanOrStringNumberFormatOption ( options, property, stringValues, fallback )
The abstract operation GetBooleanOrStringNumberFormatOption takes arguments options (an Object), property (a
9.2.14 DefaultNumberOption ( value, minimum, maximum, fallback )
The abstract operation DefaultNumberOption takes arguments value (an
9.2.15 GetNumberOption ( options, property, minimum, maximum, fallback )
The abstract operation GetNumberOption takes arguments options (an Object), property (a String), minimum (an
- Let value be ?
Get (options, property). - Return ?
DefaultNumberOption (value, minimum, maximum, fallback).
9.2.16 PartitionPattern ( pattern )
The abstract operation PartitionPattern takes argument pattern (a
- Let result be a new empty
List . - Let placeholderEnd be -1.
- Let placeholderStart be
StringIndexOf (pattern,"{" , 0). - Repeat, while placeholderStart is not
not-found ,- Let literal be the
substring of pattern from placeholderEnd + 1 to placeholderStart. - If literal is not the empty String, then
- Append the
Record { [[Type]]:"literal" , [[Value]]: literal } to result.
- Append the
- Set placeholderEnd to
StringIndexOf (pattern,"}" , placeholderStart). Assert : placeholderEnd is notnot-found and placeholderStart < placeholderEnd.- Let placeholderName be the
substring of pattern from placeholderStart + 1 to placeholderEnd. - Append the
Record { [[Type]]: placeholderName, [[Value]]:undefined } to result. - Set placeholderStart to
StringIndexOf (pattern,"{" , placeholderEnd).
- Let literal be the
- Let tail be the
substring of pattern from placeholderEnd + 1. - If tail is not the empty String, then
- Append the
Record { [[Type]]:"literal" , [[Value]]: tail } to result.
- Append the
- Return result.
10 Collator Objects
10.1 The Intl.Collator Constructor
The Intl.Collator
- is %Intl.Collator%.
- is the initial value of the
"Collator" property of theIntl object .
Behaviour common to all
10.1.1 Intl.Collator ( [ locales [ , options ] ] )
When the Intl.Collator
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , let newTarget be theactive function object , else let newTarget be NewTarget. - Let internalSlotsList be « [[InitializedCollator]], [[Locale]], [[Usage]], [[Collation]], [[Numeric]], [[CaseFirst]], [[Sensitivity]], [[IgnorePunctuation]], [[BoundCompare]] ».
- Let collator be ?
OrdinaryCreateFromConstructor (newTarget,"%Intl.Collator.prototype%" , internalSlotsList). - NOTE: The source of locale data for
ResolveOptions depends upon the"usage" property of options, but the following two steps must observably precede that lookup (and must not observably repeat insideResolveOptions ). - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Set options to ?
CoerceOptionsToObject (options). - Let usage be ?
GetOption (options,"usage" ,string , «"sort" ,"search" »,"sort" ). - Set collator.[[Usage]] to usage.
- If usage is
"sort" , then- Let localeData be
%Intl.Collator% .[[SortLocaleData]].
- Let localeData be
- Else,
- Let localeData be
%Intl.Collator% .[[SearchLocaleData]].
- Let localeData be
- Let optionsResolution be ?
ResolveOptions (%Intl.Collator% , localeData,CreateArrayFromList (requestedLocales), options). - Let r be optionsResolution.[[ResolvedLocale]].
- Set collator.[[Locale]] to r.[[Locale]].
- If r.[[co]] is
null , let collation be"default" . Otherwise, let collation be r.[[co]]. - Set collator.[[Collation]] to collation.
- Set collator.[[Numeric]] to
SameValue (r.[[kn]],"true" ). - Set collator.[[CaseFirst]] to r.[[kf]].
- Let resolvedLocaleData be r.[[LocaleData]].
- If usage is
"sort" , let defaultSensitivity be"variant" . Otherwise, let defaultSensitivity be resolvedLocaleData.[[sensitivity]]. - Set collator.[[Sensitivity]] to ?
GetOption (options,"sensitivity" ,string , «"base" ,"accent" ,"case" ,"variant" », defaultSensitivity). - Let defaultIgnorePunctuation be resolvedLocaleData.[[ignorePunctuation]].
- Set collator.[[IgnorePunctuation]] to ?
GetOption (options,"ignorePunctuation" ,boolean ,empty , defaultIgnorePunctuation). - Return collator.
10.2 Properties of the Intl.Collator Constructor
The Intl.Collator
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
10.2.1 Intl.Collator.prototype
The value of Intl.Collator.prototype
is
This property has the attributes { [[Writable]]:
10.2.2 Intl.Collator.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.Collator% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
10.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[ResolutionOptionDescriptors]] internal slot is « { [[Key]]:
The values of the [[SortLocaleData]] and [[SearchLocaleData]] internal slots are
- The first element of [[SortLocaleData]].[[<locale>]].[[co]] and [[SearchLocaleData]].[[<locale>]].[[co]] must be
null . - The values
"standard" and"search" must not be used as elements in any [[SortLocaleData]].[[<locale>]].[[co]] and [[SearchLocaleData]].[[<locale>]].[[co]]List . - [[SearchLocaleData]].[[<locale>]] must have a [[sensitivity]] field with one of the String values
"base" ,"accent" ,"case" , or"variant" . - [[SearchLocaleData]].[[<locale>]] and [[SortLocaleData]].[[<locale>]] must have an [[ignorePunctuation]] field with a Boolean value.
10.3 Properties of the Intl.Collator Prototype Object
The Intl.Collator prototype object:
- is %Intl.Collator.prototype%.
- is an
ordinary object . - is not an Intl.Collator instance and does not have an [[InitializedCollator]] internal slot or any of the other internal slots of Intl.Collator instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
10.3.1 Intl.Collator.prototype.constructor
The initial value of Intl.Collator.prototype.constructor
is
10.3.2 Intl.Collator.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let collator be the
this value. - Perform ?
RequireInternalSlot (collator, [[InitializedCollator]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 3 , except the header row, in table order, do- Let p be the Property value of the current row.
- Let v be the value of collator's internal slot whose name is the Internal Slot value of the current row.
- If the current row has an Extension Key value, then
- Let extensionKey be the Extension Key value of the current row.
- If
%Intl.Collator% .[[RelevantExtensionKeys]] does not contain extensionKey, then- Set v to
undefined .
- Set v to
- If v is not
undefined , then- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Perform !
- Return options.
Internal Slot | Property | Extension Key |
---|---|---|
[[Locale]] | ||
[[Usage]] | ||
[[Sensitivity]] | ||
[[IgnorePunctuation]] | ||
[[Collation]] | ||
[[Numeric]] | ||
[[CaseFirst]] |
10.3.3 get Intl.Collator.prototype.compare
This named
Intl.Collator.prototype.compare is an
- Let collator be the
this value. - Perform ?
RequireInternalSlot (collator, [[InitializedCollator]]). - If collator.[[BoundCompare]] is
undefined , then- Let F be a new built-in
function object as defined in10.3.3.1 . - Set F.[[Collator]] to collator.
- Set collator.[[BoundCompare]] to F.
- Let F be a new built-in
- Return collator.[[BoundCompare]].
Array.prototype.sort
or other functions.
10.3.3.1 Collator Compare Functions
A Collator compare function is an anonymous built-in function that has a [[Collator]] internal slot.
When a Collator compare function F is called with arguments x and y, the following steps are taken:
- Let collator be F.[[Collator]].
Assert : collatoris an Object and collator has an [[InitializedCollator]] internal slot.- If x is not provided, let x be
undefined . - If y is not provided, let y be
undefined . - Let X be ?
ToString (x). - Let Y be ?
ToString (y). - Return
CompareStrings (collator, X, Y).
The
10.3.3.2 CompareStrings ( collator, x, y )
The
Behaviour as described below depends upon locale-sensitive identification of the sequence of collation elements for a string, in particular "base letters", and different base letters always compare as unequal (causing the strings containing them to also compare as unequal). Results of comparing variations of the same base letter with different case, diacritic marks, or potentially other aspects further depends upon collator.[[Sensitivity]] as follows:
[[Sensitivity]] | Description | ||
---|---|---|---|
Characters with the same base letter do not compare as unequal, regardless of differences in case and/or diacritic marks. | equal | equal | |
Characters with the same base letter compare as unequal only if they differ in accents and/or other diacritic marks, regardless of differences in case. | not equal | equal | |
Characters with the same base letter compare as unequal only if they differ in case, regardless of differences in accents and/or other diacritic marks. | equal | not equal | |
Characters with the same base letter compare as unequal if they differ in case, diacritic marks, and/or potentially other differences. | not equal | not equal |
If collator.[[IgnorePunctuation]] is
For the interpretation of options settable through locale extension keys, see Unicode Technical Standard #35 Part 1 Core, Section 3.6.1 Key and Type Definitions.
The actual return values are
10.3.4 Intl.Collator.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
10.4 Properties of Intl.Collator Instances
Intl.Collator instances are
Intl.Collator instances have an [[InitializedCollator]] internal slot.
Intl.Collator instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for collation. - [[Usage]] is one of the String values
"sort" or"search" , identifying the collator usage. - [[Sensitivity]] is one of the String values
"base" ,"accent" ,"case" , or"variant" , identifying the collator's sensitivity. - [[IgnorePunctuation]]
is a Boolean value, specifying whether punctuation should be ignored in comparisons. - [[Collation]]
is a String value representing the Unicode Collation Identifier used for collation, except that the values"standard" and"search" are not allowed, while the value"default" is allowed.
Intl.Collator instances also have the following internal slots if the key corresponding to the name of the internal slot in
- [[Numeric]]
is a Boolean value, specifying whether numeric sorting is used. - [[CaseFirst]] is one of the String values
"upper" ,"lower" , or"false" .
Finally, Intl.Collator instances have a [[BoundCompare]] internal slot that caches the function returned by the compare accessor (
11 DateTimeFormat Objects
11.1 The Intl.DateTimeFormat Constructor
The Intl.DateTimeFormat
- is %Intl.DateTimeFormat%.
- is the initial value of the
"DateTimeFormat" property of theIntl object .
Behaviour common to all
11.1.1 Intl.DateTimeFormat ( [ locales [ , options ] ] )
When the Intl.DateTimeFormat
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , let newTarget be theactive function object , else let newTarget be NewTarget. - Let dateTimeFormat be ?
CreateDateTimeFormat (newTarget, locales, options,any ,date ). - If the implementation supports the normative optional
constructor mode of4.3 Note 1 , then- Let this be the
this value. - Return ?
ChainDateTimeFormat (dateTimeFormat, NewTarget, this).
- Let this be the
- Return dateTimeFormat.
11.1.1.1 ChainDateTimeFormat ( dateTimeFormat, newTarget, this )
The abstract operation ChainDateTimeFormat takes arguments dateTimeFormat (an Intl.DateTimeFormat), newTarget (an
- If newTarget is
undefined and ?OrdinaryHasInstance (%Intl.DateTimeFormat% , this) istrue , then- Perform ?
DefinePropertyOrThrow (this,%Intl% .[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: dateTimeFormat, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:false }). - Return this.
- Perform ?
- Return dateTimeFormat.
11.1.2 CreateDateTimeFormat ( newTarget, locales, options, required, defaults )
The abstract operation CreateDateTimeFormat takes arguments newTarget (a
- Let dateTimeFormat be ?
OrdinaryCreateFromConstructor (newTarget,"%Intl.DateTimeFormat.prototype%" , « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[HourCycle]], [[DateStyle]], [[TimeStyle]], [[DateTimeFormat]], [[BoundFormat]] »). - Let hour12 be
undefined . - Let modifyResolutionOptions be a new
Abstract Closure with parameters (options) that captures hour12 and performs the following steps when called:- Set hour12 to options.[[hour12]].
- Remove field [[hour12]] from options.
- If hour12 is not
undefined , set options.[[hc]] tonull .
- Let optionsResolution be ?
ResolveOptions (%Intl.DateTimeFormat% ,%Intl.DateTimeFormat% .[[LocaleData]], locales, options, «coerce-options », modifyResolutionOptions). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Set dateTimeFormat.[[Locale]] to r.[[Locale]].
- Let resolvedCalendar be r.[[ca]].
- Set dateTimeFormat.[[Calendar]] to resolvedCalendar.
- Set dateTimeFormat.[[NumberingSystem]] to r.[[nu]].
- Let resolvedLocaleData be r.[[LocaleData]].
- If hour12 is
true , then- Let hc be resolvedLocaleData.[[hourCycle12]].
- Else if hour12 is
false , then- Let hc be resolvedLocaleData.[[hourCycle24]].
- Else,
Assert : hour12 isundefined .- Let hc be r.[[hc]].
- If hc is
null , set hc to resolvedLocaleData.[[hourCycle]].
- Let timeZone be ?
Get (options,"timeZone" ). - If timeZone is
undefined , then- Set timeZone to
SystemTimeZoneIdentifier ().
- Set timeZone to
- Else,
- Set timeZone to ?
ToString (timeZone).
- Set timeZone to ?
- If
IsTimeZoneOffsetString (timeZone) istrue , then- Let parseResult be
ParseText (StringToCodePoints (timeZone),UTCOffset ). Assert : parseResult is aParse Node .- If parseResult contains more than one
MinuteSecond Parse Node , throw aRangeError exception. - Let offsetNanoseconds be
ParseTimeZoneOffsetString (timeZone). - Let offsetMinutes be offsetNanoseconds / (6 × 1010).
Assert : offsetMinutes is aninteger .- Set timeZone to
FormatOffsetTimeZoneIdentifier (offsetMinutes).
- Let parseResult be
- Else,
- Let timeZoneIdentifierRecord be
GetAvailableNamedTimeZoneIdentifier (timeZone). - If timeZoneIdentifierRecord is
empty , throw aRangeError exception. - Set timeZone to timeZoneIdentifierRecord.[[PrimaryIdentifier]].
- Let timeZoneIdentifierRecord be
- Set dateTimeFormat.[[TimeZone]] to timeZone.
- Let formatOptions be a new
Record . - Set formatOptions.[[hourCycle]] to hc.
- Let hasExplicitFormatComponents be
false . - For each row of
Table 16 , except the header row, in table order, do- Let prop be the name given in the Property column of the current row.
- If prop is
"fractionalSecondDigits" , then- Let value be ?
GetNumberOption (options,"fractionalSecondDigits" , 1, 3,undefined ).
- Let value be ?
- Else,
- Set formatOptions.[[<prop>]] to value.
- If value is not
undefined , then- Set hasExplicitFormatComponents to
true .
- Set hasExplicitFormatComponents to
- Let formatMatcher be ?
GetOption (options,"formatMatcher" ,string , «"basic" ,"best fit" »,"best fit" ). - Let dateStyle be ?
GetOption (options,"dateStyle" ,string , «"full" ,"long" ,"medium" ,"short" »,undefined ). - Set dateTimeFormat.[[DateStyle]] to dateStyle.
- Let timeStyle be ?
GetOption (options,"timeStyle" ,string , «"full" ,"long" ,"medium" ,"short" »,undefined ). - Set dateTimeFormat.[[TimeStyle]] to timeStyle.
- If dateStyle is not
undefined or timeStyle is notundefined , then- If hasExplicitFormatComponents is
true , then- Throw a
TypeError exception.
- Throw a
- If required is
date and timeStyle is notundefined , then- Throw a
TypeError exception.
- Throw a
- If required is
time and dateStyle is notundefined , then- Throw a
TypeError exception.
- Throw a
- Let styles be resolvedLocaleData.[[styles]].[[<resolvedCalendar>]].
- Let bestFormat be
DateTimeStyleFormat (dateStyle, timeStyle, styles).
- If hasExplicitFormatComponents is
- Else,
- Let needDefaults be
true . - If required is
date orany , then- For each
property name prop of «"weekday" ,"year" ,"month" ,"day" », do- Let value be formatOptions.[[<prop>]].
- If value is not
undefined , set needDefaults tofalse .
- For each
- If required is
time orany , then- For each
property name prop of «"dayPeriod" ,"hour" ,"minute" ,"second" ,"fractionalSecondDigits" », do- Let value be formatOptions.[[<prop>]].
- If value is not
undefined , set needDefaults tofalse .
- For each
- If needDefaults is
true and defaults is eitherdate orall , then- For each
property name prop of «"year" ,"month" ,"day" », do- Set formatOptions.[[<prop>]] to
"numeric" .
- Set formatOptions.[[<prop>]] to
- For each
- If needDefaults is
true and defaults is eithertime orall , then- For each
property name prop of «"hour" ,"minute" ,"second" », do- Set formatOptions.[[<prop>]] to
"numeric" .
- Set formatOptions.[[<prop>]] to
- For each
- Let formats be resolvedLocaleData.[[formats]].[[<resolvedCalendar>]].
- If formatMatcher is
"basic" , then- Let bestFormat be
BasicFormatMatcher (formatOptions, formats).
- Let bestFormat be
- Else,
- Let bestFormat be
BestFitFormatMatcher (formatOptions, formats).
- Let bestFormat be
- Let needDefaults be
- Set dateTimeFormat.[[DateTimeFormat]] to bestFormat.
- If bestFormat has a field [[hour]], then
- Set dateTimeFormat.[[HourCycle]] to hc.
- Return dateTimeFormat.
11.1.3 FormatOffsetTimeZoneIdentifier ( offsetMinutes )
The abstract operation FormatOffsetTimeZoneIdentifier takes argument offsetMinutes (an
- If offsetMinutes ≥ 0, let sign be the code unit 0x002B (PLUS SIGN); otherwise, let sign be the code unit 0x002D (HYPHEN-MINUS).
- Let absoluteMinutes be
abs (offsetMinutes). - Let hours be
floor (absoluteMinutes / 60). - Let minutes be absoluteMinutes
modulo 60. - Return the
string-concatenation of sign,ToZeroPaddedDecimalString (hours, 2), the code unit 0x003A (COLON), andToZeroPaddedDecimalString (minutes, 2).
11.2 Properties of the Intl.DateTimeFormat Constructor
The Intl.DateTimeFormat
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
11.2.1 Intl.DateTimeFormat.prototype
The value of Intl.DateTimeFormat.prototype
is
This property has the attributes { [[Writable]]:
11.2.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.DateTimeFormat% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
11.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[RelevantExtensionKeys]] internal slot is «
The value of the [[ResolutionOptionDescriptors]] internal slot is « { [[Key]]:
The value of the [[LocaleData]] internal slot is
-
[[LocaleData]].[[<locale>]].[[nu]] must be a
List that does not include the values"native" ,"traditio" , or"finance" . -
[[LocaleData]].[[<locale>]].[[hc]] must be «
null ,"h11" ,"h12" ,"h23" ,"h24" ». -
[[LocaleData]].[[<locale>]].[[hourCycle]] must be one of the String values
"h11" ,"h12" ,"h23" , or"h24" . -
[[LocaleData]].[[<locale>]].[[hourCycle12]] must be one of the String values
"h11" or"h12" . -
[[LocaleData]].[[<locale>]].[[hourCycle24]] must be one of the String values
"h23" or"h24" . -
[[LocaleData]].[[<locale>]] must have a [[formats]] field. The value of this [[formats]] field must be a
Record with a [[<calendar>]] field for each calendar value calendar. The value of each [[<calendar>]] field must be aList ofDateTime Format Records . MultipleRecords in such aList may use the same subset of the fields as long as the corresponding values differ for at least one field. The following subsets must be available for each locale:- weekday, year, month, day, hour, minute, second, fractionalSecondDigits
- weekday, year, month, day, hour, minute, second
- weekday, year, month, day
- year, month, day
- year, month
- month, day
- month
- hour, minute, second, fractionalSecondDigits
- hour, minute, second
- hour, minute
- dayPeriod, hour, minute, second, fractionalSecondDigits
- dayPeriod, hour, minute, second
- dayPeriod, hour, minute
- dayPeriod, hour
-
[[LocaleData]].[[<locale>]] must have a [[styles]] field. The value of this [[styles]] field must be a
Record with a [[<calendar>]] field for each calendar value calendar. The value of each [[<calendar>]] field must be aDateTime Styles Record .
11.2.3.1 DateTime Format Records
Each DateTime Format Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[weekday]] | [[Weekday]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[era]] | [[Era]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[year]] | [[Year]] values in the Values column of |
Optional field. Present if [[pattern]] contains at least one of the substrings |
[[month]] | [[Month]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[day]] | [[Day]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[dayPeriod]] | [[DayPeriod]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[hour]] | [[Hour]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[minute]] | [[Minute]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[second]] | [[Second]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[fractionalSecondDigits]] | [[FractionalSecondDigits]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[timeZoneName]] | [[TimeZoneName]] values in the Values column of |
Optional field. Present if [[pattern]] contains the |
[[pattern]] | a |
|
[[pattern12]] | a |
Optional field. Present if the [[hour]] field is present. In addition to the substrings of the [[pattern]] field, contains at least one of the substrings |
[[rangePatterns]] | a |
Pattern strings in this field are similar to [[pattern]]. |
[[rangePatterns12]] | a |
Optional field. Present if the [[hour]] field is present. Pattern strings in this field are similar to [[pattern12]]. |
11.2.3.2 DateTime Range Pattern Records
Each DateTime Range Pattern Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[Default]] | a |
It contains the default range pattern used when a more specific range pattern is not available. |
[[Era]] | a |
Optional field. Used when era is the largest calendar element that is different between the start and end dates. |
[[Year]] | a |
Optional field. Used when year is the largest calendar element that is different between the start and end dates. |
[[Month]] | a |
Optional field. Used when month is the largest calendar element that is different between the start and end dates. |
[[Day]] | a |
Optional field. Used when day is the largest calendar element that is different between the start and end dates. |
[[AmPm]] | a |
Optional field. Used when ante or post meridiem is the largest calendar element that is different between the start and end dates. |
[[DayPeriod]] | a |
Optional field. Used when day period is the largest calendar element that is different between the start and end dates. |
[[Hour]] | a |
Optional field. Used when hour is the largest calendar element that is different between the start and end dates. |
[[Minute]] | a |
Optional field. Used when minute is the largest calendar element that is different between the start and end dates. |
[[Second]] | a |
Optional field. Used when second is the largest calendar element that is different between the start and end dates. |
[[FractionalSecondDigits]] | a |
Optional field. Used when fractional seconds are the largest calendar element that is different between the start and end dates. |
11.2.3.3 DateTime Range Pattern Format Records
Each DateTime Range Pattern Format Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[weekday]] | [[Weekday]] values in the Values column of |
Optional field. Present if a |
[[era]] | [[Era]] values in the Values column of |
Optional field. Present if a |
[[year]] | [[Year]] values in the Values column of |
Optional field. Present if a |
[[month]] | [[Month]] values in the Values column of |
Optional field. Present if a |
[[day]] | [[Day]] values in the Values column of |
Optional field. Present if a |
[[dayPeriod]] | [[DayPeriod]] values in the Values column of |
Optional field. Present if a |
[[hour]] | [[Hour]] values in the Values column of |
Optional field. Present if a |
[[minute]] | [[Minute]] values in the Values column of |
Optional field. Present if a |
[[second]] | [[Second]] values in the Values column of |
Optional field. Present if a |
[[fractionalSecondDigits]] | [[FractionalSecondDigits]] values in the Values column of |
Optional field. Present if a |
[[timeZoneName]] | [[TimeZoneName]] values in the Values column of |
Optional field. Present if a |
[[PatternParts]] | a |
Each record represents a part of the range pattern. |
11.2.3.4 DateTime Range Pattern Part Records
Each DateTime Range Pattern Part Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[Source]] | It indicates which of the range's dates should be formatted using the value of the [[Pattern]] field. | |
[[Pattern]] | a |
A String of the same format as the regular date pattern String. |
11.2.3.5 DateTime Styles Records
Each DateTime Styles Record has the fields defined in
Field Name | Value Type |
---|---|
[[Date]] | a |
[[Time]] | a |
[[Connector]] | a |
[[DateTimeRangeFormat]] | a |
11.2.3.6 DateTime Style Records
Each DateTime Style Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[full]] | a |
Format record for the |
[[long]] | a |
Format record for the |
[[medium]] | a |
Format record for the |
[[short]] | a |
Format record for the |
11.2.3.7 DateTime Connector Records
Each DateTime Connector Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[full]] | a |
Connector pattern when the date style is |
[[long]] | a |
Connector pattern when the date style is |
[[medium]] | a |
Connector pattern when the date style is |
[[short]] | a |
Connector pattern when the date style is |
11.2.3.8 DateTime Date Range Records
Each DateTime Date Range Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[full]] | a |
Used when date style is |
[[long]] | a |
Used when date style is |
[[medium]] | a |
Used when date style is |
[[short]] | a |
Used when date style is |
11.2.3.9 DateTime Time Range Records
Each DateTime Time Range Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[full]] | a |
Used when time style is |
[[long]] | a |
Used when time style is |
[[medium]] | a |
Used when time style is |
[[short]] | a |
Used when time style is |
11.2.3.10 DateTime Style Range Records
Each DateTime Style Range Record has the fields defined in
Field Name | Value Type | Description |
---|---|---|
[[rangePatterns]] | a |
Range patterns to combine date and time styles. |
[[rangePatterns12]] | a |
Optional Field. Range patterns to combine date and time styles for 12-hour formats. |
- [[hour]]:
"numeric" - [[minute]]:
"numeric" - [[pattern]]:
"{hour}:{minute}" - [[pattern12]]:
"{hour}:{minute} {ampm}" - [[rangePatterns]]:
- [[Hour]]:
- [[hour]]:
"numeric" - [[minute]]:
"numeric" - [[PatternParts]]:
- {[[Source]]:
"startRange" , [[Pattern]]:"{hour}:{minute}" } - {[[Source]]:
"shared" , [[Pattern]]:" – " } - {[[Source]]:
"endRange" , [[Pattern]]:"{hour}:{minute}" }
- {[[Source]]:
- [[hour]]:
- [[Minute]]:
- [[hour]]:
"numeric" - [[minute]]:
"numeric" - [[PatternParts]]:
- {[[Source]]:
"startRange" , [[Pattern]]:"{hour}:{minute}" } - {[[Source]]:
"shared" , [[Pattern]]:" – " } - {[[Source]]:
"endRange" , [[Pattern]]:"{hour}:{minute}" }
- {[[Source]]:
- [[hour]]:
- [[Default]]:
- [[year]]:
"2-digit" - [[month]]:
"numeric" - [[day]]:
"numeric" - [[hour]]:
"numeric" - [[minute]]:
"numeric" - [[PatternParts]]:
- {[[Source]]:
"startRange" , [[Pattern]]:"{day}/{month}/{year}, {hour}:{minute}" } - {[[Source]]:
"shared" , [[Pattern]]:" – " } - {[[Source]]:
"endRange" , [[Pattern]]:"{day}/{month}/{year}, {hour}:{minute}" }
- {[[Source]]:
- [[year]]:
- [[Hour]]:
- [[rangePatterns12]]:
- [[Hour]]:
- [[hour]]:
"numeric" - [[minute]]:
"numeric" - [[PatternParts]]:
- {[[Source]]:
"startRange" , [[Pattern]]:"{hour}:{minute}" } - {[[Source]]:
"shared" , [[Pattern]]:" – " } - {[[Source]]:
"endRange" , [[Pattern]]:"{hour}:{minute}" } - {[[Source]]:
"shared" , [[Pattern]]:" {ampm}" }
- {[[Source]]:
- [[hour]]:
- [[Minute]]:
- [[hour]]:
"numeric" - [[minute]]:
"numeric" - [[PatternParts]]:
- {[[Source]]:
"startRange" , [[Pattern]]:"{hour}:{minute}" } - {[[Source]]:
"shared" , [[Pattern]]:" – " } - {[[Source]]:
"endRange" , [[Pattern]]:"{hour}:{minute}" } - {[[Source]]:
"shared" , [[Pattern]]:" {ampm}" }
- {[[Source]]:
- [[hour]]:
- [[Default]]:
- [[year]]:
"2-digit" - [[month]]:
"numeric" - [[day]]:
"numeric" - [[hour]]:
"numeric" - [[minute]]:
"numeric" - [[PatternParts]]:
- {[[Source]]:
"startRange" , [[Pattern]]:"{day}/{month}/{year}, {hour}:{minute} {ampm}" } - {[[Source]]:
"shared" , [[Pattern]]:" – " } - {[[Source]]:
"endRange" , [[Pattern]]:"{day}/{month}/{year}, {hour}:{minute} {ampm}" }
- {[[Source]]:
- [[year]]:
- [[Hour]]:
11.3 Properties of the Intl.DateTimeFormat Prototype Object
The Intl.DateTimeFormat prototype object:
- is %Intl.DateTimeFormat.prototype%.
- is an
ordinary object . - 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.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
11.3.1 Intl.DateTimeFormat.prototype.constructor
The initial value of Intl.DateTimeFormat.prototype.constructor
is
11.3.2 Intl.DateTimeFormat.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let dtf be the
this value. - If the implementation supports the normative optional
constructor mode of4.3 Note 1 , then- Set dtf to ?
UnwrapDateTimeFormat (dtf).
- Set dtf to ?
- Perform ?
RequireInternalSlot (dtf, [[InitializedDateTimeFormat]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 15 , except the header row, in table order, do- Let p be the Property value of the current row.
- If there is an Internal Slot value in the current row, then
- Let v be the value of dtf's internal slot whose name is the Internal Slot value of the current row.
- Else,
- Let format be dtf.[[DateTimeFormat]].
- If format has a field [[<p>]] and dtf.[[DateStyle]] is
undefined and dtf.[[TimeStyle]] isundefined , then- Let v be format.[[<p>]].
- Else,
- Let v be
undefined .
- Let v be
- If v is not
undefined , then- If there is a Conversion value in the current row, then
- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Return options.
Internal Slot | Property | Conversion |
---|---|---|
[[Locale]] | ||
[[Calendar]] | ||
[[NumberingSystem]] | ||
[[TimeZone]] | ||
[[HourCycle]] | ||
[[HourCycle]] | ||
[[DateStyle]] | ||
[[TimeStyle]] |
For web compatibility reasons, if the property
11.3.3 get Intl.DateTimeFormat.prototype.format
Intl.DateTimeFormat.prototype.format is an
- Let dtf be the
this value. - If the implementation supports the normative optional
constructor mode of4.3 Note 1 , then- Set dtf to ?
UnwrapDateTimeFormat (dtf).
- Set dtf to ?
- Perform ?
RequireInternalSlot (dtf, [[InitializedDateTimeFormat]]). - If dtf.[[BoundFormat]] is
undefined , then- Let F be a new built-in
function object as defined in DateTime Format Functions (11.5.4 ). - Set F.[[DateTimeFormat]] to dtf.
- Set dtf.[[BoundFormat]] to F.
- Let F be a new built-in
- Return dtf.[[BoundFormat]].
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.
11.3.4 Intl.DateTimeFormat.prototype.formatRange ( startDate, endDate )
When the formatRange
method is called with arguments startDate and endDate, the following steps are taken:
- Let dtf be
this value. - Perform ?
RequireInternalSlot (dtf, [[InitializedDateTimeFormat]]). - If startDate is
undefined or endDate isundefined , throw aTypeError exception. - Let x be ?
ToNumber (startDate). - Let y be ?
ToNumber (endDate). - Return ?
FormatDateTimeRange (dtf, x, y).
11.3.5 Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate, endDate )
When the formatRangeToParts
method is called with arguments startDate and endDate, the following steps are taken:
- Let dtf be
this value. - Perform ?
RequireInternalSlot (dtf, [[InitializedDateTimeFormat]]). - If startDate is
undefined or endDate isundefined , throw aTypeError exception. - Let x be ?
ToNumber (startDate). - Let y be ?
ToNumber (endDate). - Return ?
FormatDateTimeRangeToParts (dtf, x, y).
11.3.6 Intl.DateTimeFormat.prototype.formatToParts ( date )
When the formatToParts
method is called with an argument date, the following steps are taken:
- Let dtf be the
this value. - Perform ?
RequireInternalSlot (dtf, [[InitializedDateTimeFormat]]). - If date is
undefined , then- Let x be !
Call (%Date.now%,undefined ).
- Let x be !
- Else,
- Let x be ?
ToNumber (date).
- Let x be ?
- Return ?
FormatDateTimeToParts (dtf, x).
11.3.7 Intl.DateTimeFormat.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
11.4 Properties of Intl.DateTimeFormat Instances
Intl.DateTimeFormat instances are
Intl.DateTimeFormat instances have an [[InitializedDateTimeFormat]] internal slot.
Intl.DateTimeFormat instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for formatting. - [[Calendar]]
is a String value representing the Unicode Calendar Identifier used for formatting. - [[NumberingSystem]]
is a String value representing the Unicode Number System Identifier used for formatting. - [[TimeZone]]
is a String value used for formatting that is either anavailable named time zone identifier or anoffset time zone identifier. - [[HourCycle]]
is a String value indicating whether the 12-hour format ("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 [[DateTimeFormat]] has an [[hour]] field. - [[DateStyle]], [[TimeStyle]] are each either
undefined , or a String value with values"full" ,"long" ,"medium" , or"short" . - [[DateTimeFormat]] is a
DateTime Format Record .
Finally, Intl.DateTimeFormat instances have a [[BoundFormat]] internal slot that caches the function returned by the format accessor (
11.5 Abstract Operations for DateTimeFormat Objects
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:
Field Name | Property | Values |
---|---|---|
[[Weekday]] | ||
[[Era]] | ||
[[Year]] | ||
[[Month]] | ||
[[Day]] | ||
[[DayPeriod]] | ||
[[Hour]] | ||
[[Minute]] | ||
[[Second]] | ||
[[FractionalSecondDigits]] | 1, 2, 3 | |
[[TimeZoneName]] |
11.5.1 DateTimeStyleFormat ( dateStyle, timeStyle, styles )
The abstract operation DateTimeStyleFormat takes arguments dateStyle (
Assert : dateStyle is notundefined or timeStyle is notundefined .- If timeStyle is not
undefined , thenAssert : timeStyle is one of"full" ,"long" ,"medium" , or"short" .- Let timeFormat be styles.[[Time]].[[<timeStyle>]].
- If dateStyle is not
undefined , thenAssert : dateStyle is one of"full" ,"long" ,"medium" , or"short" .- Let dateFormat be styles.[[Date]].[[<dateStyle>]].
- If dateStyle is not
undefined and timeStyle is notundefined , then- Let format be a new
DateTime Format Record . - Add to format all fields from dateFormat except [[pattern]] and [[rangePatterns]].
- Add to format all fields from timeFormat except [[pattern]], [[rangePatterns]], [[pattern12]], and [[rangePatterns12]], if present.
- Let connector be styles.[[Connector]].[[<dateStyle>]].
- Let pattern be the string connector with the
substring "{0}" replaced with timeFormat.[[pattern]] and thesubstring "{1}" replaced with dateFormat.[[pattern]]. - Set format.[[pattern]] to pattern.
- If timeFormat has a [[pattern12]] field, then
- Let dateTimeRangeFormat be styles.[[DateTimeRangeFormat]].[[<dateStyle>]].[[<timeStyle>]].
- Set format.[[rangePatterns]] to dateTimeRangeFormat.[[rangePatterns]].
- If dateTimeRangeFormat has a [[rangePatterns12]] field, then
- Set format.[[rangePatterns12]] to dateTimeRangeFormat.[[rangePatterns12]].
- Return format.
- Let format be a new
- If timeStyle is not
undefined , then- Return timeFormat.
Assert : dateStyle is notundefined .- Return dateFormat.
11.5.2 BasicFormatMatcher ( options, formats )
The abstract operation BasicFormatMatcher takes arguments options (a
- Let removalPenalty be 120.
- Let additionPenalty be 20.
- Let longLessPenalty be 8.
- Let longMorePenalty be 6.
- Let shortLessPenalty be 6.
- Let shortMorePenalty be 3.
- Let offsetPenalty be 1.
- Let bestScore be -∞.
- Let bestFormat be
undefined . - For each element format of formats, do
- Let score be 0.
- For each row of
Table 16 , except the header row, in table order, do- Let property be the name given in the Property column of the current row.
- If options has a field [[<property>]], let optionsProp be options.[[<property>]]; else let optionsProp be
undefined . - If format has a field [[<property>]], let formatProp be format.[[<property>]]; else let formatProp be
undefined . - If optionsProp is
undefined and formatProp is notundefined , then- Set score to score - additionPenalty.
- Else if optionsProp is not
undefined and formatProp isundefined , then- Set score to score - removalPenalty.
- Else if property is
"timeZoneName" , then- If optionsProp is
"short" or"shortGeneric" , then- If formatProp is
"shortOffset" , set score to score - offsetPenalty. - Else if formatProp is
"longOffset" , set score to score - (offsetPenalty + shortMorePenalty). - Else if optionsProp is
"short" and formatProp is"long" , set score to score - shortMorePenalty. - Else if optionsProp is
"shortGeneric" and formatProp is"longGeneric" , set score to score - shortMorePenalty. - Else if optionsProp ≠ formatProp, set score to score - removalPenalty.
- If formatProp is
- Else if optionsProp is
"shortOffset" and formatProp is"longOffset" , then- Set score to score - shortMorePenalty.
- Else if optionsProp is
"long" or"longGeneric" , then- If formatProp is
"longOffset" , set score to score - offsetPenalty. - Else if formatProp is
"shortOffset" , set score to score - (offsetPenalty + longLessPenalty). - Else if optionsProp is
"long" and formatProp is"short" , set score to score - longLessPenalty. - Else if optionsProp is
"longGeneric" and formatProp is"shortGeneric" , set score to score - longLessPenalty. - Else if optionsProp ≠ formatProp, set score to score - removalPenalty.
- If formatProp is
- Else if optionsProp is
"longOffset" and formatProp is"shortOffset" , then- Set score to score - longLessPenalty.
- Else if optionsProp ≠ formatProp, then
- Set score to score - removalPenalty.
- If optionsProp is
- Else if optionsProp ≠ formatProp, then
- If property is
"fractionalSecondDigits" , then- Let values be « 1, 2, 3 ».
- Else,
- Let values be «
"2-digit" ,"numeric" ,"narrow" ,"short" ,"long" ».
- Let values be «
- Let optionsPropIndex be the index of optionsProp within values.
- Let formatPropIndex be the index of formatProp within values.
- Let delta be
max (min (formatPropIndex - optionsPropIndex, 2), -2). - If delta = 2, set score to score - longMorePenalty.
- Else if delta = 1, set score to score - shortMorePenalty.
- Else if delta = -1, set score to score - shortLessPenalty.
- Else if delta = -2, set score to score - longLessPenalty.
- If property is
- If score > bestScore, then
- Set bestScore to score.
- Set bestFormat to format.
- Return bestFormat.
11.5.3 BestFitFormatMatcher ( options, formats )
The
11.5.4 DateTime Format Functions
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:
- Let dtf be F.[[DateTimeFormat]].
Assert : dtfis an Object and dtf has an [[InitializedDateTimeFormat]] internal slot.- If date is not provided or is
undefined , then- Let x be !
Call (%Date.now%,undefined ).
- Let x be !
- Else,
- Let x be ?
ToNumber (date).
- Let x be ?
- Return ?
FormatDateTime (dtf, x).
The
11.5.5 FormatDateTimePattern ( dateTimeFormat, format, pattern, epochNanoseconds )
The abstract operation FormatDateTimePattern takes arguments dateTimeFormat (an Intl.DateTimeFormat), format (a
- Let locale be dateTimeFormat.[[Locale]].
- Let nfOptions be
OrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (nfOptions,"numberingSystem" , dateTimeFormat.[[NumberingSystem]]). - Perform !
CreateDataPropertyOrThrow (nfOptions,"useGrouping" ,false ). - Let nf be !
Construct (%Intl.NumberFormat% , « locale, nfOptions »). - Let nf2Options be
OrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (nf2Options,"minimumIntegerDigits" ,2 𝔽). - Perform !
CreateDataPropertyOrThrow (nf2Options,"numberingSystem" , dateTimeFormat.[[NumberingSystem]]). - Perform !
CreateDataPropertyOrThrow (nf2Options,"useGrouping" ,false ). - Let nf2 be !
Construct (%Intl.NumberFormat% , « locale, nf2Options »). - If format has a field [[fractionalSecondDigits]], then
- Let fractionalSecondDigits be format.[[fractionalSecondDigits]].
- Let nf3Options be
OrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (nf3Options,"minimumIntegerDigits" ,𝔽 (fractionalSecondDigits)). - Perform !
CreateDataPropertyOrThrow (nf3Options,"numberingSystem" , dateTimeFormat.[[NumberingSystem]]). - Perform !
CreateDataPropertyOrThrow (nf3Options,"useGrouping" ,false ). - Let nf3 be !
Construct (%Intl.NumberFormat% , « locale, nf3Options »).
- Let tm be
ToLocalTime (epochNanoseconds, dateTimeFormat.[[Calendar]], dateTimeFormat.[[TimeZone]]). - Let patternParts be
PartitionPattern (pattern). - Let result be a new empty
List . - For each
Record { [[Type]], [[Value]] } patternPart of patternParts, do- Let p be patternPart.[[Type]].
- If p is
"literal" , then- Append the
Record { [[Type]]:"literal" , [[Value]]: patternPart.[[Value]] } to result.
- Append the
- Else if p is
"fractionalSecondDigits" , thenAssert : format has a field [[fractionalSecondDigits]].- Let v be tm.[[Millisecond]].
- Set v to
floor (v × 10( fractionalSecondDigits - 3 )). - Let fv be
FormatNumeric (nf3, v). - Append the
Record { [[Type]]:"fractionalSecond" , [[Value]]: fv } to result.
- Else if p is
"dayPeriod" , thenAssert : format has a field [[dayPeriod]].- Let f be format.[[dayPeriod]].
- Let fv be a String value representing the day period of tm in the form given by f; the String value depends upon the implementation and the effective locale of dateTimeFormat.
- Append the
Record { [[Type]]: p, [[Value]]: fv } to result.
- Else if p is
"timeZoneName" , thenAssert : format has a field [[timeZoneName]].- Let f be format.[[timeZoneName]].
- Let v be dateTimeFormat.[[TimeZone]].
- Let fv be a String value representing v in the form given by f; the String value depends upon the implementation and the effective locale of dateTimeFormat. The String value may also depend on the value of the [[InDST]] field of tm if f is
"short" ,"long" ,"shortOffset" , or"longOffset" . If the implementation does not have such a localized representation of f, then use the String value of v itself. - Append the
Record { [[Type]]: p, [[Value]]: fv } to result.
- Else if p matches a Property column of the row in
Table 16 , thenAssert : format has a field [[<p>]].- Let f be format.[[<p>]].
- Let v be the value of tm's field whose name is the Internal Slot column of the matching row.
- If p is
"year" and v ≤ 0, set v to 1 - v. - If p is
"month" , set v to v + 1. - If p is
"hour" and dateTimeFormat.[[HourCycle]] is"h11" or"h12" , then- Set v to v
modulo 12. - If v is 0 and dateTimeFormat.[[HourCycle]] is
"h12" , set v to 12.
- Set v to v
- If p is
"hour" and dateTimeFormat.[[HourCycle]] is"h24" , then- If v is 0, set v to 24.
- If f is
"numeric" , then- Let fv be
FormatNumeric (nf, v).
- Let fv be
- Else if f is
"2-digit" , then- Let fv be
FormatNumeric (nf2, v). - Let codePoints be
StringToCodePoints (fv). - Let count be the number of elements in codePoints.
- If count > 2, then
- Let tens be codePoints[count - 2].
- Let ones be codePoints[count - 1].
- Set fv to
CodePointsToString (« tens, ones »).
- Let fv be
- Else if f is
"narrow" ,"short" , or"long" , then- Let fv be a String value representing v in the form given by f; the String value depends upon the implementation and the effective locale and calendar of dateTimeFormat. If p is
"month" , then the String value may also depend on whether format.[[day]] is present. If the implementation does not have a localized representation of f, then use the String value of v itself.
- Let fv be a String value representing v in the form given by f; the String value depends upon the implementation and the effective locale and calendar of dateTimeFormat. If p is
- Append the
Record { [[Type]]: p, [[Value]]: fv } to result.
- Else if p is
"ampm" , then - Else if p is
"relatedYear" , then- Let v be tm.[[RelatedYear]].
- Let fv be
FormatNumeric (nf, v). - Append the
Record { [[Type]]:"relatedYear" , [[Value]]: fv } to result.
- Else if p is
"yearName" , then - Else,
- Let unknown be an implementation-, locale-, and numbering system-dependent String based on epochNanoseconds and p.
- Append the
Record { [[Type]]:"unknown" , [[Value]]: unknown } to result.
- Return result.
11.5.6 PartitionDateTimePattern ( dateTimeFormat, x )
The abstract operation PartitionDateTimePattern takes arguments dateTimeFormat (an Intl.DateTimeFormat) and x (a Number) and returns either a
- Let x be
TimeClip (x). - If x is
NaN , throw aRangeError exception. - Let epochNanoseconds be
ℤ (ℝ (x) × 106). - Let format be dateTimeFormat.[[DateTimeFormat]].
- If dateTimeFormat.[[HourCycle]] is
"h11" or"h12" , then- Let pattern be format.[[pattern12]].
- Else,
- Let pattern be format.[[pattern]].
- Let result be
FormatDateTimePattern (dateTimeFormat, format, pattern, epochNanoseconds). - Return result.
11.5.7 FormatDateTime ( dateTimeFormat, x )
The abstract operation FormatDateTime takes arguments dateTimeFormat (an Intl.DateTimeFormat) and x (a Number) and returns either a
- Let parts be ?
PartitionDateTimePattern (dateTimeFormat, x). - Let result be the empty String.
- For each
Record { [[Type]], [[Value]] } part of parts, do- Set result to the
string-concatenation of result and part.[[Value]].
- Set result to the
- Return result.
11.5.8 FormatDateTimeToParts ( dateTimeFormat, x )
The abstract operation FormatDateTimeToParts takes arguments dateTimeFormat (an Intl.DateTimeFormat) and x (a Number) and returns either a
- Let parts be ?
PartitionDateTimePattern (dateTimeFormat, x). - Let result be !
ArrayCreate (0). - Let n be 0.
- For each
Record { [[Type]], [[Value]] } part of parts, do- Let O be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (O,"type" , part.[[Type]]). - Perform !
CreateDataPropertyOrThrow (O,"value" , part.[[Value]]). - Perform !
CreateDataPropertyOrThrow (result, !ToString (𝔽 (n)), O). - Increment n by 1.
- Let O be
- Return result.
11.5.9 PartitionDateTimeRangePattern ( dateTimeFormat, x, y )
The abstract operation PartitionDateTimeRangePattern takes arguments dateTimeFormat (an Intl.DateTimeFormat), x (a Number), and y (a Number) and returns either a
- Set x to
TimeClip (x). - If x is
NaN , throw aRangeError exception. - Set y to
TimeClip (y). - If y is
NaN , throw aRangeError exception. - Let xEpochNanoseconds be
ℤ (ℝ (x) × 106). - Let yEpochNanoseconds be
ℤ (ℝ (y) × 106). - Let tm1 be
ToLocalTime (xEpochNanoseconds, dateTimeFormat.[[Calendar]], dateTimeFormat.[[TimeZone]]). - Let tm2 be
ToLocalTime (yEpochNanoseconds, dateTimeFormat.[[Calendar]], dateTimeFormat.[[TimeZone]]). - Let format be dateTimeFormat.[[DateTimeFormat]].
- If dateTimeFormat.[[HourCycle]] is
"h11" or"h12" , then- Let pattern be format.[[pattern12]].
- Let rangePatterns be format.[[rangePatterns12]].
- Else,
- Let pattern be format.[[pattern]].
- Let rangePatterns be format.[[rangePatterns]].
- Let selectedRangePattern be
undefined . - Let relevantFieldsEqual be
true . - Let checkMoreFields be
true . - For each row of
Table 6 , except the header row, in table order, do- Let fieldName be the name given in the Field Name column of the row.
- If rangePatterns has a field whose name is fieldName, let rangePattern be rangePatterns' field whose name is fieldName; else let rangePattern be
undefined . - If selectedRangePattern is not
undefined and rangePattern isundefined , then- NOTE: Because there is no range pattern for differences at or below this field, no further checks will be performed.
- Set checkMoreFields to
false .
- If fieldName is not equal to [[Default]] and relevantFieldsEqual is
true and checkMoreFields istrue , then- Set selectedRangePattern to rangePattern.
- If fieldName is [[AmPm]], then
- If tm1.[[Hour]] is less than 12, let v1 be
"am" ; else let v1 be"pm" . - If tm2.[[Hour]] is less than 12, let v2 be
"am" ; else let v2 be"pm" .
- If tm1.[[Hour]] is less than 12, let v1 be
- Else if fieldName is [[DayPeriod]], then
- Let v1 be a String value representing the day period of tm1; the String value depends upon the implementation and the effective locale of dateTimeFormat.
- Let v2 be a String value representing the day period of tm2; the String value depends upon the implementation and the effective locale of dateTimeFormat.
- Else if fieldName is [[FractionalSecondDigits]], then
- Else,
- Let v1 be tm1's field whose name is fieldName.
- Let v2 be tm2's field whose name is fieldName.
- If v1 is not equal to v2, then
- Set relevantFieldsEqual to
false .
- Set relevantFieldsEqual to
- If relevantFieldsEqual is
true , then- Let collapsedResult be a new empty
List . - Let resultParts be
FormatDateTimePattern (dateTimeFormat, format, pattern, xEpochNanoseconds). - For each
Record { [[Type]], [[Value]] } r of resultParts, do- Append the
Record { [[Type]]: r.[[Type]], [[Value]]: r.[[Value]], [[Source]]:"shared" } to collapsedResult.
- Append the
- Return collapsedResult.
- Let collapsedResult be a new empty
- Let rangeResult be a new empty
List . - If selectedRangePattern is
undefined , then- Set selectedRangePattern to rangePatterns.[[Default]].
- For each
Record { [[Pattern]], [[Source]] } rangePatternPart of selectedRangePattern.[[PatternParts]], do- Let pattern be rangePatternPart.[[Pattern]].
- Let source be rangePatternPart.[[Source]].
- If source is
"startRange" or"shared" , then- Let z be xEpochNanoseconds.
- Else,
- Let z be yEpochNanoseconds.
- Let resultParts be
FormatDateTimePattern (dateTimeFormat, selectedRangePattern, pattern, z). - For each
Record { [[Type]], [[Value]] } r of resultParts, do- Append the
Record { [[Type]]: r.[[Type]], [[Value]]: r.[[Value]], [[Source]]: source } to rangeResult.
- Append the
- Return rangeResult.
11.5.10 FormatDateTimeRange ( dateTimeFormat, x, y )
The abstract operation FormatDateTimeRange takes arguments dateTimeFormat (an Intl.DateTimeFormat), x (a Number), and y (a Number) and returns either a
- Let parts be ?
PartitionDateTimeRangePattern (dateTimeFormat, x, y). - Let result be the empty String.
- For each
Record { [[Type]], [[Value]], [[Source]] } part of parts, do- Set result to the
string-concatenation of result and part.[[Value]].
- Set result to the
- Return result.
11.5.11 FormatDateTimeRangeToParts ( dateTimeFormat, x, y )
The abstract operation FormatDateTimeRangeToParts takes arguments dateTimeFormat (an Intl.DateTimeFormat), x (a Number), and y (a Number) and returns either a
- Let parts be ?
PartitionDateTimeRangePattern (dateTimeFormat, x, y). - Let result be !
ArrayCreate (0). - Let n be 0.
- For each
Record { [[Type]], [[Value]], [[Source]] } part of parts, do- Let O be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (O,"type" , part.[[Type]]). - Perform !
CreateDataPropertyOrThrow (O,"value" , part.[[Value]]). - Perform !
CreateDataPropertyOrThrow (O,"source" , part.[[Source]]). - Perform !
CreateDataPropertyOrThrow (result, !ToString (𝔽 (n)), O). - Increment n by 1.
- Let O be
- Return result.
11.5.12 ToLocalTime ( epochNs, calendar, timeZoneIdentifier )
The
- If
IsTimeZoneOffsetString (timeZoneIdentifier) istrue , then- Let offsetNs be
ParseTimeZoneOffsetString (timeZoneIdentifier).
- Let offsetNs be
- Else,
Assert :GetAvailableNamedTimeZoneIdentifier (timeZoneIdentifier) is notempty .- Let offsetNs be
GetNamedTimeZoneOffsetNanoseconds (timeZoneIdentifier, epochNs).
- Let tz be
ℝ (epochNs) + offsetNs. - If calendar is
"gregory" , then- Return a
ToLocalTime Record with fields calculated from tz according toTable 17 .
- Return a
- Else,
- Return a
ToLocalTime Record with the fields calculated from tz for the given calendar. The calculations should use best available information about the specified calendar.
- Return a
11.5.13 ToLocalTime Records
Each ToLocalTime Record has the fields defined in
Field Name | Value Type | Value Calculation for Gregorian Calendar |
---|---|---|
[[Weekday]] | an |
|
[[Era]] | a String | Let year be |
[[Year]] | an |
|
[[RelatedYear]] | an |
|
[[YearName]] | a String or |
|
[[Month]] | an |
|
[[Day]] | an |
|
[[Hour]] | an |
|
[[Minute]] | an |
|
[[Second]] | an |
|
[[Millisecond]] | an |
|
[[InDST]] | a Boolean | Calculate |
11.5.14 UnwrapDateTimeFormat ( dtf )
The abstract operation UnwrapDateTimeFormat takes argument dtf (an
- If dtf
is not an Object , throw aTypeError exception. - If dtf does not have an [[InitializedDateTimeFormat]] internal slot and ?
OrdinaryHasInstance (%Intl.DateTimeFormat% , dtf) istrue , then - Return dtf.
12 DisplayNames Objects
12.1 The Intl.DisplayNames Constructor
The Intl.DisplayNames
- is %Intl.DisplayNames%.
- is the initial value of the
"DisplayNames" property of theIntl object .
Behaviour common to all
12.1.1 Intl.DisplayNames ( locales, options )
When the Intl.DisplayNames
function is called with arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - Let displayNames be ?
OrdinaryCreateFromConstructor (NewTarget,"%Intl.DisplayNames.prototype%" , « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[LanguageDisplay]], [[Fields]] »). - Let optionsResolution be ?
ResolveOptions (%Intl.DisplayNames% ,%Intl.DisplayNames% .[[LocaleData]], locales, options, «require-options »). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Let style be ?
GetOption (options,"style" ,string , «"narrow" ,"short" ,"long" »,"long" ). - Set displayNames.[[Style]] to style.
- Let type be ?
GetOption (options,"type" ,string , «"language" ,"region" ,"script" ,"currency" ,"calendar" ,"dateTimeField" »,undefined ). - If type is
undefined , throw aTypeError exception. - Set displayNames.[[Type]] to type.
- Let fallback be ?
GetOption (options,"fallback" ,string , «"code" ,"none" »,"code" ). - Set displayNames.[[Fallback]] to fallback.
- Set displayNames.[[Locale]] to r.[[Locale]].
- Let resolvedLocaleData be r.[[LocaleData]].
- Let types be resolvedLocaleData.[[types]].
Assert : types is aRecord (see12.2.3 ).- Let languageDisplay be ?
GetOption (options,"languageDisplay" ,string , «"dialect" ,"standard" »,"dialect" ). - Let typeFields be types.[[<type>]].
Assert : typeFields is aRecord (see12.2.3 ).- If type is
"language" , then - Let styleFields be typeFields.[[<style>]].
Assert : styleFields is aRecord (see12.2.3 ).- Set displayNames.[[Fields]] to styleFields.
- Return displayNames.
12.2 Properties of the Intl.DisplayNames Constructor
The Intl.DisplayNames
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
12.2.1 Intl.DisplayNames.prototype
The value of Intl.DisplayNames.prototype
is
This property has the attributes { [[Writable]]:
12.2.2 Intl.DisplayNames.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.DisplayNames% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
12.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[RelevantExtensionKeys]] internal slot is « ».
The value of the [[ResolutionOptionDescriptors]] internal slot is « ».
The value of the [[LocaleData]] internal slot is
- [[LocaleData]].[[<locale>]] must have a [[types]] field for all locale values locale. The value of this field must be a
Record , which must have fields with the names of all display name types:"language" ,"region" ,"script" ,"currency" ,"calendar" , and"dateTimeField" . - The value of the field
"language" must be aRecord which must have fields with the names of one of the valid language displays:"dialect" and"standard" . - The language display fields under display name type
"language" should containRecords which must have fields with the names of one of the valid display name styles:"narrow" ,"short" , and"long" . - The value of the fields
"region" ,"script" ,"currency" ,"calendar" , and"dateTimeField" must beRecords , which must have fields with the names of all display name styles:"narrow" ,"short" , and"long" . - The display name style fields under display name type
"language" should containRecords with keys corresponding to language codes that can be matched by theunicode_language_id
Unicode locale nonterminal . The value of these fields must be string values. - The display name style fields under display name type
"region" should containRecords with keys corresponding to region codes. The value of these fields must be string values. - The display name style fields under display name type
"script" should containRecords with keys corresponding to script codes. The value of these fields must be string values. - The display name style fields under display name type
"currency" should containRecords with keys corresponding to currency codes. The value of these fields must be string values. - The display name style fields under display name type
"calendar" should containRecords with keys corresponding to calendar identifiers that can be matched by thetype
Unicode locale nonterminal . The value of these fields must be string values. - The display name style fields under display name type
"dateTimeField" should containRecords with keys corresponding to codes listed inTable 19 . The value of these fields must be string values.
12.3 Properties of the Intl.DisplayNames Prototype Object
The Intl.DisplayNames prototype object:
- is %Intl.DisplayNames.prototype%.
- is an
ordinary object . - is not an Intl.DisplayNames instance and does not have an [[InitializedDisplayNames]] internal slot or any of the other internal slots of Intl.DisplayNames instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
12.3.1 Intl.DisplayNames.prototype.constructor
The initial value of Intl.DisplayNames.prototype.constructor
is
12.3.2 Intl.DisplayNames.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let displayNames be
this value. - Perform ?
RequireInternalSlot (displayNames, [[InitializedDisplayNames]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 18 , except the header row, in table order, do- Let p be the Property value of the current row.
- Let v be the value of displayNames's internal slot whose name is the Internal Slot value of the current row.
Assert : v is notundefined .- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Return options.
Internal Slot | Property |
---|---|
[[Locale]] | |
[[Style]] | |
[[Type]] | |
[[Fallback]] | |
[[LanguageDisplay]] |
12.3.3 Intl.DisplayNames.prototype.of ( code )
When the Intl.DisplayNames.prototype.of
is called with an argument code, the following steps are taken:
- Let displayNames be
this value. - Perform ?
RequireInternalSlot (displayNames, [[InitializedDisplayNames]]). - Let code be ?
ToString (code). - Set code to ?
CanonicalCodeForDisplayNames (displayNames.[[Type]], code). - Let fields be displayNames.[[Fields]].
- If fields has a field [[<code>]], return fields.[[<code>]].
- If displayNames.[[Fallback]] is
"code" , return code. - Return
undefined .
12.3.4 Intl.DisplayNames.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
12.4 Properties of Intl.DisplayNames Instances
Intl.DisplayNames instances are
Intl.DisplayNames instances have an [[InitializedDisplayNames]] internal slot.
Intl.DisplayNames instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for formatting. - [[Style]] is one of the String values
"narrow" ,"short" , or"long" , identifying the display name style used. - [[Type]] is one of the String values
"language" ,"region" ,"script" ,"currency" ,"calendar" , or"dateTimeField" , identifying the type of the display names requested. - [[Fallback]] is one of the String values
"code" or"none" , identifying the fallback return when the system does not have the requested display name. - [[LanguageDisplay]] is one of the String values
"dialect" or"standard" , identifying the language display kind. It is only used when [[Type]] has the value"language" . - [[Fields]] is a
Record (see12.2.3 ) which must have fields with keys corresponding to codes according to [[Style]], [[Type]], and [[LanguageDisplay]].
12.5 Abstract Operations for DisplayNames Objects
12.5.1 CanonicalCodeForDisplayNames ( type, code )
The abstract operation CanonicalCodeForDisplayNames takes arguments type (a String) and code (a String) and returns either a
- If type is
"language" , then- If code cannot be matched by the
unicode_language_id
Unicode locale nonterminal , throw aRangeError exception. - If
IsStructurallyValidLanguageTag (code) isfalse , throw aRangeError exception. - Return
CanonicalizeUnicodeLocaleId (code).
- If code cannot be matched by the
- If type is
"region" , then- If code cannot be matched by the
unicode_region_subtag
Unicode locale nonterminal , throw aRangeError exception. - Return the
ASCII-uppercase of code.
- If code cannot be matched by the
- If type is
"script" , then- If code cannot be matched by the
unicode_script_subtag
Unicode locale nonterminal , throw aRangeError exception. Assert : The length of code is 4, and every code unit of code represents an ASCII letter (0x0041 through 0x005A and 0x0061 through 0x007A, both inclusive).- Let first be the
ASCII-uppercase of thesubstring of code from 0 to 1. - Let rest be the
ASCII-lowercase of thesubstring of code from 1. - Return the
string-concatenation of first and rest.
- If code cannot be matched by the
- If type is
"calendar" , then- If code cannot be matched by the
type
Unicode locale nonterminal , throw aRangeError exception. - If code uses any of the backwards compatibility syntax described in Unicode Technical Standard #35 Part 1 Core, Section 3.3 BCP 47 Conformance, throw a
RangeError exception. - Return the
ASCII-lowercase of code.
- If code cannot be matched by the
- If type is
"dateTimeField" , then- If the result of
IsValidDateTimeFieldCode (code) isfalse , throw aRangeError exception. - Return code.
- If the result of
Assert : type is"currency" .- If
IsWellFormedCurrencyCode (code) isfalse , throw aRangeError exception. - Return the
ASCII-uppercase of code.
12.5.2 IsValidDateTimeFieldCode ( field )
The abstract operation IsValidDateTimeFieldCode takes argument field (a String) and returns a Boolean. It verifies that the field argument represents a valid date time field code. It performs the following steps when called:
- If field is listed in the Code column of
Table 19 , returntrue . - Return
false .
Code | Description |
---|---|
The field indicating the era, e.g. AD or BC in the Gregorian or Julian calendar. | |
The field indicating the year (within an era). | |
The field indicating the quarter, e.g. Q2, 2nd quarter, etc. | |
The field indicating the month, e.g. Sep, September, etc. | |
The field indicating the week number within a year. | |
The field indicating the day of week, e.g. Tue, Tuesday, etc. | |
The field indicating the day in month. | |
The field indicating the day period, either am, pm, etc. or noon, evening, etc.. | |
The field indicating the hour. | |
The field indicating the minute. | |
The field indicating the second. | |
The field indicating the time zone name, e.g. PDT, Pacific Daylight Time, etc. |
13 DurationFormat Objects
13.1 The Intl.DurationFormat Constructor
The Intl.DurationFormat
- is %Intl.DurationFormat%.
- is the initial value of the
"DurationFormat" property of theIntl object .
Behaviour common to all
13.1.1 Intl.DurationFormat ( [ locales [ , options ] ] )
When the Intl.DurationFormat
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - Let durationFormat be ?
OrdinaryCreateFromConstructor (NewTarget,"%Intl.DurationFormatPrototype%" , « [[InitializedDurationFormat]], [[Locale]], [[NumberingSystem]], [[Style]], [[YearsOptions]], [[MonthsOptions]], [[WeeksOptions]], [[DaysOptions]], [[HoursOptions]], [[MinutesOptions]], [[SecondsOptions]], [[MillisecondsOptions]], [[MicrosecondsOptions]], [[NanosecondsOptions]], [[HourMinuteSeparator]], [[MinuteSecondSeparator]], [[FractionalDigits]] »). - Let optionsResolution be ?
ResolveOptions (%Intl.DurationFormat% ,%Intl.DurationFormat% .[[LocaleData]], locales, options). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Set durationFormat.[[Locale]] to r.[[Locale]].
- Let resolvedLocaleData be r.[[LocaleData]].
- Let digitalFormat be resolvedLocaleData.[[DigitalFormat]].
- Set durationFormat.[[HourMinuteSeparator]] to digitalFormat.[[HourMinuteSeparator]].
- Set durationFormat.[[MinuteSecondSeparator]] to digitalFormat.[[MinuteSecondSeparator]].
- Set durationFormat.[[NumberingSystem]] to r.[[nu]].
- Let style be ?
GetOption (options,"style" ,string , «"long" ,"short" ,"narrow" ,"digital" »,"short" ). - Set durationFormat.[[Style]] to style.
- Let prevStyle be the empty String.
- For each row of
Table 20 , except the header row, in table order, do- Let slot be the Internal Slot value of the current row.
- Let unit be the Unit value of the current row.
- Let styles be the Styles value of the current row.
- Let digitalBase be the Digital Default value of the current row.
- Let unitOptions be ?
GetDurationUnitOptions (unit, options, style, styles, digitalBase, prevStyle, digitalFormat.[[TwoDigitHours]]). - Set the value of durationFormat's internal slot whose name is slot to unitOptions.
- If unit is one of
"hours" ,"minutes" ,"seconds" ,"milliseconds" , or"microseconds" , then- Set prevStyle to unitOptions.[[Style]].
- Set durationFormat.[[FractionalDigits]] to ?
GetNumberOption (options,"fractionalDigits" , 0, 9,undefined ). - Return durationFormat.
Internal Slot | Unit | Styles | Digital Default |
---|---|---|---|
[[YearsOptions]] | « |
||
[[MonthsOptions]] | « |
||
[[WeeksOptions]] | « |
||
[[DaysOptions]] | « |
||
[[HoursOptions]] | « |
||
[[MinutesOptions]] | « |
||
[[SecondsOptions]] | « |
||
[[MillisecondsOptions]] | « |
||
[[MicrosecondsOptions]] | « |
||
[[NanosecondsOptions]] | « |
13.2 Properties of the Intl.DurationFormat Constructor
The Intl.DurationFormat
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
13.2.1 Intl.DurationFormat.prototype
The value of Intl.DurationFormat.prototype
is
This property has the attributes { [[Writable]]:
13.2.2 Intl.DurationFormat.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.DurationFormat% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
13.2.3 Internal slots
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 [[ResolutionOptionDescriptors]] internal slot is « { [[Key]]:
The value of the [[LocaleData]] internal slot is
- [[LocaleData]].[[<locale>]] must be a
Record with fields [[nu]] and [[DigitalFormat]]. - [[LocaleData]].[[<locale>]].[[nu]] must be a
List as specified in16.2.3 and must not include the values"native" ,"traditio" , or"finance" . - [[LocaleData]].[[<locale>]].[[DigitalFormat]] must be a
Record with keys corresponding to each numbering system available for locale. Each value associated with one of those keys must be aRecord containing the following fields:- [[HourMinuteSeparator]] must be a String value that is the appropriate separator between hours and minutes for that combination of locale and numbering system when using style
"numeric" or"2-digit" . - [[MinuteSecondSeparator]] must be a String value that is the appropriate separator between minutes and seconds for that combination of locale and numbering system when using style
"numeric" or"2-digit" . - [[TwoDigitHours]] must be a Boolean value indicating whether hours are always displayed using two digits when using style
"numeric" .
- [[HourMinuteSeparator]] must be a String value that is the appropriate separator between hours and minutes for that combination of locale and numbering system when using style
13.3 Properties of the Intl.DurationFormat Prototype Object
The Intl.DurationFormat prototype object:
- is %Intl.DurationFormat.prototype%.
- is an
ordinary object . - is not an Intl.DurationFormat instance and does not have an [[InitializedDurationFormat]] internal slot or any of the other internal slots of Intl.DurationFormat instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
13.3.1 Intl.DurationFormat.prototype.constructor
The initial value of Intl.DurationFormat.prototype.constructor
is the intrinsic object
13.3.2 Intl.DurationFormat.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let df be the
this value. - Perform ?
RequireInternalSlot (df, [[InitializedDurationFormat]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 21 , except the header row, in table order, do- Let p be the Property value of the current row.
- Let v be the value of df's internal slot whose name is the Internal Slot value of the current row.
- If v is not
undefined , then- If there is a Conversion value in the current row, let conversion be that value; else let conversion be
empty . - If conversion is
number , then- Set v to
𝔽 (v).
- Set v to
- Else if conversion is not
empty , thenAssert : conversion isstyle+display and v is aDuration Unit Options Record .- NOTE: v.[[Style]] will be represented with a property named p (a plural Temporal unit), then v.[[Display]] will be represented with a property whose name suffixes p with
"Display" . - Let style be v.[[Style]].
- If style is
"fractional" , thenAssert :IsFractionalSecondUnitName (p) istrue .- Set style to
"numeric" .
- Perform !
CreateDataPropertyOrThrow (options, p, style). - Set p to the
string-concatenation of p and"Display" . - Set v to v.[[Display]].
- Perform !
CreateDataPropertyOrThrow (options, p, v).
- If there is a Conversion value in the current row, let conversion be that value; else let conversion be
- Return options.
Internal Slot | Property | Conversion |
---|---|---|
[[Locale]] | ||
[[NumberingSystem]] | ||
[[Style]] | ||
[[YearsOptions]] | ||
[[MonthsOptions]] | ||
[[WeeksOptions]] | ||
[[DaysOptions]] | ||
[[HoursOptions]] | ||
[[MinutesOptions]] | ||
[[SecondsOptions]] | ||
[[MillisecondsOptions]] | ||
[[MicrosecondsOptions]] | ||
[[NanosecondsOptions]] | ||
[[FractionalDigits]] |
13.3.3 Intl.DurationFormat.prototype.format ( duration )
When the format
method is called with an argument duration, the following steps are taken:
- Let df be the
this value. - Perform ?
RequireInternalSlot (df, [[InitializedDurationFormat]]). - Let record be ?
ToDurationRecord (duration). - Let parts be
PartitionDurationFormatPattern (df, record). - Let result be the empty String.
- For each
Record { [[Type]], [[Value]], [[Unit]] } part in parts, do- Set result to the
string-concatenation of result and part.[[Value]].
- Set result to the
- Return result.
13.3.4 Intl.DurationFormat.prototype.formatToParts ( duration )
When the formatToParts
method is called with an argument duration, the following steps are taken:
- Let df be the
this value. - Perform ?
RequireInternalSlot (df, [[InitializedDurationFormat]]). - Let record be ?
ToDurationRecord (duration). - Let parts be
PartitionDurationFormatPattern (df, record). - Let result be !
ArrayCreate (0). - Let n be 0.
- For each
Record { [[Type]], [[Value]], [[Unit]] } part in parts, do- Let obj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (obj,"type" , part.[[Type]]). - Perform !
CreateDataPropertyOrThrow (obj,"value" , part.[[Value]]). - If part.[[Unit]] is not
empty , perform !CreateDataPropertyOrThrow (obj,"unit" , part.[[Unit]]). - Perform !
CreateDataPropertyOrThrow (result, !ToString (n), obj). - Set n to n + 1.
- Let obj be
- Return result.
13.3.5 Intl.DurationFormat.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
13.4 Properties of Intl.DurationFormat Instances
Intl.DurationFormat instances inherit properties from
Intl.DurationFormat instances have an [[InitializedDurationFormat]] internal slot.
Intl.DurationFormat instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for formatting. - [[NumberingSystem]]
is a String value representing the Unicode Number System Identifier used for formatting. - [[Style]] is one of the String values
"long" ,"short" ,"narrow" , or"digital" identifying the duration formatting style used. - [[YearsOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Years]] field. - [[MonthsOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Months]] field. - [[WeeksOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Weeks]] field. - [[DaysOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Days]] field. - [[HoursOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Hours]] field. - [[MinutesOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Minutes]] field. - [[SecondsOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Seconds]] field. - [[MillisecondsOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Milliseconds]] field. - [[MicrosecondsOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Microseconds]] field. - [[NanosecondsOptions]] is a
Duration Unit Options Record identifying the formatting style and display criteria for aDuration Record 's [[Nanoseconds]] field. - [[HourMinuteSeparator]]
is a String value identifying the separator to be used between hours and minutes when both fields are displayed and both fields are formatted using numeric styles. - [[MinuteSecondSeparator]]
is a String value identifying the separator to be used between minutes and seconds when both fields are displayed and both fields are formatted using numeric styles. - [[FractionalDigits]] is either
undefined or a non-negativeinteger identifying the number of fractional digits to be used with numeric styles.
13.5 Abstract Operations for DurationFormat Objects
13.5.1 Duration Records
A Duration Record is a
Duration Records have the fields listed in
Field | Meaning |
---|---|
[[Years]] | The number of years in the duration. |
[[Months]] | The number of months in the duration. |
[[Weeks]] | The number of weeks in the duration. |
[[Days]] | The number of days in the duration. |
[[Hours]] | The number of hours in the duration. |
[[Minutes]] | The number of minutes in the duration. |
[[Seconds]] | The number of seconds in the duration. |
[[Milliseconds]] | The number of milliseconds in the duration. |
[[Microseconds]] | The number of microseconds in the duration. |
[[Nanoseconds]] | The number of nanoseconds in the duration. |
13.5.2 ToIntegerIfIntegral ( argument )
The abstract operation ToIntegerIfIntegral takes argument argument (an
- Let number be ?
ToNumber (argument). - If number is not an
integral Number , throw aRangeError exception. - Return
ℝ (number).
13.5.3 ToDurationRecord ( input )
The abstract operation ToDurationRecord takes argument input (an
- If input
is not an Object , then- If input
is a String , throw aRangeError exception. - Throw a
TypeError exception.
- If input
- Let result be a new
Duration Record with each field set to 0. - Let days be ?
Get (input,"days" ). - If days is not
undefined , set result.[[Days]] to ?ToIntegerIfIntegral (days). - Let hours be ?
Get (input,"hours" ). - If hours is not
undefined , set result.[[Hours]] to ?ToIntegerIfIntegral (hours). - Let microseconds be ?
Get (input,"microseconds" ). - If microseconds is not
undefined , set result.[[Microseconds]] to ?ToIntegerIfIntegral (microseconds). - Let milliseconds be ?
Get (input,"milliseconds" ). - If milliseconds is not
undefined , set result.[[Milliseconds]] to ?ToIntegerIfIntegral (milliseconds). - Let minutes be ?
Get (input,"minutes" ). - If minutes is not
undefined , set result.[[Minutes]] to ?ToIntegerIfIntegral (minutes). - Let months be ?
Get (input,"months" ). - If months is not
undefined , set result.[[Months]] to ?ToIntegerIfIntegral (months). - Let nanoseconds be ?
Get (input,"nanoseconds" ). - If nanoseconds is not
undefined , set result.[[Nanoseconds]] to ?ToIntegerIfIntegral (nanoseconds). - Let seconds be ?
Get (input,"seconds" ). - If seconds is not
undefined , set result.[[Seconds]] to ?ToIntegerIfIntegral (seconds). - Let weeks be ?
Get (input,"weeks" ). - If weeks is not
undefined , set result.[[Weeks]] to ?ToIntegerIfIntegral (weeks). - Let years be ?
Get (input,"years" ). - If years is not
undefined , set result.[[Years]] to ?ToIntegerIfIntegral (years). - If years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds are all
undefined , throw aTypeError exception. - If
IsValidDuration ( result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]) isfalse , then- Throw a
RangeError exception.
- Throw a
- Return result.
13.5.4 DurationSign ( duration )
The abstract operation DurationSign takes argument duration (a
- For each value v of « duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]] », do
- If v < 0, return -1.
- If v > 0, return 1.
- Return 0.
13.5.5 IsValidDuration ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds )
The abstract operation IsValidDuration takes arguments years (an
- Let sign be 0.
- For each value v of « years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds », do
- If
abs (years) ≥ 232, returnfalse . - If
abs (months) ≥ 232, returnfalse . - If
abs (weeks) ≥ 232, returnfalse . - Let normalizedSeconds be days × 86,400 + hours × 3600 + minutes × 60 + seconds +
ℝ (𝔽 (milliseconds)) × 10-3 +ℝ (𝔽 (microseconds)) × 10-6 +ℝ (𝔽 (nanoseconds)) × 10-9. - NOTE: The above step cannot be implemented directly using floating-point arithmetic. Multiplying by 10-3, 10-6, and 10-9 respectively may be imprecise when milliseconds, microseconds, or nanoseconds is an unsafe
integer . This multiplication can be implemented in C++ with an implementation ofstd::remquo()
with sufficient bits in the quotient. String manipulation will also give an exact result, since the multiplication is by a power of 10. - If
abs (normalizedSeconds) ≥ 253, returnfalse . - Return
true .
13.5.6 GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle, twoDigitHours )
The abstract operation GetDurationUnitOptions takes arguments unit (a String), options (an Object), baseStyle (a String), stylesList (a
- Let style be ?
GetOption (options, unit,string , stylesList,undefined ). - Let displayDefault be
"always" . - If style is
undefined , then- If baseStyle is
"digital" , then- Set style to digitalBase.
- If unit is not one of
"hours" ,"minutes" , or"seconds" , set displayDefault to"auto" .
- Else if prevStyle is one of
"fractional" ,"numeric" or"2-digit" , then- Set style to
"numeric" . - If unit is not
"minutes" or"seconds" , set displayDefault to"auto" .
- Set style to
- Else,
- Set style to baseStyle.
- Set displayDefault to
"auto" .
- If baseStyle is
- If style is
"numeric" andIsFractionalSecondUnitName (unit) istrue , then- Set style to
"fractional" . - Set displayDefault to
"auto" .
- Set style to
- Let displayField be the
string-concatenation of unit and"Display" . - Let display be ?
GetOption (options, displayField,string , «"auto" ,"always" », displayDefault). - Perform ?
ValidateDurationUnitStyle (unit, style, display, prevStyle). - If unit is
"hours" and twoDigitHours istrue , set style to"2-digit" . - If unit is
"minutes" or"seconds" and prevStyle is"numeric" or"2-digit" , set style to"2-digit" . - Return the
Duration Unit Options Record { [[Style]]: style, [[Display]]: display }.
13.5.6.1 Duration Unit Options Records
Each Duration Unit Options Record has the fields defined in
Field Name | Value Type |
---|---|
[[Style]] | a String from the Styles column of |
[[Display]] |
13.5.6.2 ValidateDurationUnitStyle ( unit, style, display, prevStyle )
The abstract operation ValidateDurationUnitStyle takes arguments unit (a String), style (a String), display (a String), and prevStyle (a String) and returns either a
- If display is
"always" and style is"fractional" , throw aRangeError exception. - If prevStyle is
"fractional" and style is not"fractional" , throw aRangeError exception. - If prevStyle is
"numeric" or"2-digit" and style is not one of"fractional" ,"numeric" or"2-digit" , throw aRangeError exception. - Return
unused .
13.5.7 ComputeFractionalDigits ( durationFormat, duration )
The abstract operation ComputeFractionalDigits takes arguments durationFormat (a DurationFormat Object) and duration (a
- Let result be 0.
- Let exponent be 3.
- For each row of
Table 24 , except the header row, in table order, do- Let unitOptions be the value of durationFormat's internal slot whose name is the Internal Slot value of the current row.
- If unitOptions.[[Style]] is
"fractional" , then- Let unit be the Unit value of the current row.
Assert :IsFractionalSecondUnitName (unit) istrue .- Let value be the value of duration's field whose name is the Value Field value of the current row.
- Set result to result + (value / 10exponent).
- Set exponent to exponent + 3.
- Return result.
13.5.8 NextUnitFractional ( durationFormat, unit )
The abstract operation NextUnitFractional takes arguments durationFormat (a DurationFormat Object) and unit (a String) and returns a Boolean. It returns
- If unit is
"seconds" and durationFormat.[[MillisecondsOptions]].[[Style]] is"fractional" , returntrue . - If unit is
"milliseconds" and durationFormat.[[MicrosecondsOptions]].[[Style]] is"fractional" , returntrue . - If unit is
"microseconds" and durationFormat.[[NanosecondsOptions]].[[Style]] is"fractional" , returntrue . - Return
false .
13.5.9 FormatNumericHours ( durationFormat, hoursValue, signDisplayed )
The abstract operation FormatNumericHours takes arguments durationFormat (a DurationFormat object), hoursValue (an
- Let result be a new empty
List . - Let hoursStyle be durationFormat.[[HoursOptions]].[[Style]].
Assert : hoursStyle is"numeric" or hoursStyle is"2-digit" .- Let nfOpts be
OrdinaryObjectCreate (null ). - Let numberingSystem be durationFormat.[[NumberingSystem]].
- Perform !
CreateDataPropertyOrThrow (nfOpts,"numberingSystem" , numberingSystem). - If hoursStyle is
"2-digit" , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"minimumIntegerDigits" ,2 𝔽).
- Perform !
- If signDisplayed is
false , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"signDisplay" ,"never" ).
- Perform !
- Perform !
CreateDataPropertyOrThrow (nfOpts,"useGrouping" ,false ). - Let nf be !
Construct (%Intl.NumberFormat% , « durationFormat.[[Locale]], nfOpts »). - Let hoursParts be
PartitionNumberPattern (nf, hoursValue). - For each
Record { [[Type]], [[Value]] } part of hoursParts, do- Append the
Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]:"hour" } to result.
- Append the
- Return result.
13.5.10 FormatNumericMinutes ( durationFormat, minutesValue, hoursDisplayed, signDisplayed )
The abstract operation FormatNumericMinutes takes arguments durationFormat (a DurationFormat Object), minutesValue (an
- Let result be a new empty
List . - If hoursDisplayed is
true , then- Let separator be durationFormat.[[HourMinuteSeparator]].
- Append the
Record { [[Type]]:"literal" , [[Value]]: separator, [[Unit]]:empty } to result.
- Let minutesStyle be durationFormat.[[MinutesOptions]].[[Style]].
Assert : minutesStyle is"numeric" or minutesStyle is"2-digit" .- Let nfOpts be
OrdinaryObjectCreate (null ). - Let numberingSystem be durationFormat.[[NumberingSystem]].
- Perform !
CreateDataPropertyOrThrow (nfOpts,"numberingSystem" , numberingSystem). - If minutesStyle is
"2-digit" , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"minimumIntegerDigits" ,2 𝔽).
- Perform !
- If signDisplayed is
false , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"signDisplay" ,"never" ).
- Perform !
- Perform !
CreateDataPropertyOrThrow (nfOpts,"useGrouping" ,false ). - Let nf be !
Construct (%Intl.NumberFormat% , « durationFormat.[[Locale]], nfOpts »). - Let minutesParts be
PartitionNumberPattern (nf, minutesValue). - For each
Record { [[Type]], [[Value]] } part of minutesParts, do- Append the
Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]:"minute" } to result.
- Append the
- Return result.
13.5.11 FormatNumericSeconds ( durationFormat, secondsValue, minutesDisplayed, signDisplayed )
The abstract operation FormatNumericSeconds takes arguments durationFormat (a DurationFormat Object), secondsValue (a
- Let result be a new empty
List . - If minutesDisplayed is
true , then- Let separator be durationFormat.[[MinuteSecondSeparator]].
- Append the
Record { [[Type]]:"literal" , [[Value]]: separator, [[Unit]]:empty } to result.
- Let secondsStyle be durationFormat.[[SecondsOptions]].[[Style]].
Assert : secondsStyle is"numeric" or secondsStyle is"2-digit" .- Let nfOpts be
OrdinaryObjectCreate (null ). - Let numberingSystem be durationFormat.[[NumberingSystem]].
- Perform !
CreateDataPropertyOrThrow (nfOpts,"numberingSystem" , numberingSystem). - If secondsStyle is
"2-digit" , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"minimumIntegerDigits" ,2 𝔽).
- Perform !
- If signDisplayed is
false , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"signDisplay" ,"never" ).
- Perform !
- Perform !
CreateDataPropertyOrThrow (nfOpts,"useGrouping" ,false ). - Let fractionDigits be durationFormat.[[FractionalDigits]].
- If fractionDigits is
undefined , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"maximumFractionDigits" ,9 𝔽). - Perform !
CreateDataPropertyOrThrow (nfOpts,"minimumFractionDigits" ,+0 𝔽).
- Perform !
- Else,
- Perform !
CreateDataPropertyOrThrow (nfOpts,"maximumFractionDigits" , fractionDigits). - Perform !
CreateDataPropertyOrThrow (nfOpts,"minimumFractionDigits" , fractionDigits).
- Perform !
- Perform !
CreateDataPropertyOrThrow (nfOpts,"roundingMode" ,"trunc" ). - Let nf be !
Construct (%Intl.NumberFormat% , « durationFormat.[[Locale]], nfOpts »). - Let secondsParts be
PartitionNumberPattern (nf, secondsValue). - For each
Record { [[Type]], [[Value]] } part of secondsParts, do- Append the
Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]:"second" } to result.
- Append the
- Return result.
13.5.12 FormatNumericUnits ( durationFormat, duration, firstNumericUnit, signDisplayed )
The abstract operation FormatNumericUnits takes arguments durationFormat (a DurationFormat Object), duration (a
Assert : firstNumericUnit is"hours" ,"minutes" , or"seconds" .- Let numericPartsList be a new empty
List . - Let hoursValue be duration.[[Hours]].
- Let hoursDisplay be durationFormat.[[HoursOptions]].[[Display]].
- Let minutesValue be duration.[[Minutes]].
- Let minutesDisplay be durationFormat.[[MinutesOptions]].[[Display]].
- Let secondsValue be duration.[[Seconds]].
- If duration.[[Milliseconds]] is not 0 or duration.[[Microseconds]] is not 0 or duration.[[Nanoseconds]] is not 0, then
- Set secondsValue to secondsValue +
ComputeFractionalDigits (durationFormat, duration).
- Set secondsValue to secondsValue +
- Let secondsDisplay be durationFormat.[[SecondsOptions]].[[Display]].
- Let hoursFormatted be
false . - If firstNumericUnit is
"hours" , then- If hoursValue is not 0 or hoursDisplay is
"always" , then- Set hoursFormatted to
true .
- Set hoursFormatted to
- If hoursValue is not 0 or hoursDisplay is
- If secondsValue is not 0 or secondsDisplay is
"always" , then- Let secondsFormatted be
true .
- Let secondsFormatted be
- Else,
- Let secondsFormatted be
false .
- Let secondsFormatted be
- Let minutesFormatted be
false . - If firstNumericUnit is
"hours" or firstNumericUnit is"minutes" , then- If hoursFormatted is
true and secondsFormatted istrue , then- Set minutesFormatted to
true .
- Set minutesFormatted to
- Else if minutesValue is not 0 or minutesDisplay is
"always" , then- Set minutesFormatted to
true .
- Set minutesFormatted to
- If hoursFormatted is
- If hoursFormatted is
true , then- If signDisplayed is
true , then- If hoursValue is 0 and
DurationSign (duration) is -1, then- Set hoursValue to
negative-zero .
- Set hoursValue to
- If hoursValue is 0 and
- Let hoursParts be
FormatNumericHours (durationFormat, hoursValue, signDisplayed). - Set numericPartsList to the
list-concatenation of numericPartsList and hoursParts. - Set signDisplayed to
false .
- If signDisplayed is
- If minutesFormatted is
true , then- If signDisplayed is
true , then- If minutesValue is 0 and
DurationSign (duration) is -1, then- Set minutesValue to
negative-zero .
- Set minutesValue to
- If minutesValue is 0 and
- Let minutesParts be
FormatNumericMinutes (durationFormat, minutesValue, hoursFormatted, signDisplayed). - Set numericPartsList to the
list-concatenation of numericPartsList and minutesParts. - Set signDisplayed to
false .
- If signDisplayed is
- If secondsFormatted is
true , then- Let secondsParts be
FormatNumericSeconds (durationFormat, secondsValue, minutesFormatted, signDisplayed). - Set numericPartsList to the
list-concatenation of numericPartsList and secondsParts.
- Let secondsParts be
- Return numericPartsList.
13.5.13 IsFractionalSecondUnitName ( unit )
The abstract operation IsFractionalSecondUnitName takes argument unit (a String) and returns a Boolean. It performs the following steps when called:
- If unit is one of
"milliseconds" ,"microseconds" , or"nanoseconds" , returntrue . - Return
false .
13.5.14 ListFormatParts ( durationFormat, partitionedPartsList )
The abstract operation ListFormatParts takes arguments durationFormat (a DurationFormat Object) and partitionedPartsList (a
- Let lfOpts be
OrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (lfOpts,"type" ,"unit" ). - Let listStyle be durationFormat.[[Style]].
- If listStyle is
"digital" , then- Set listStyle to
"short" .
- Set listStyle to
- Perform !
CreateDataPropertyOrThrow (lfOpts,"style" , listStyle). - Let lf be !
Construct (%Intl.ListFormat% , « durationFormat.[[Locale]], lfOpts »). - Let strings be a new empty
List . - For each element parts of partitionedPartsList, do
- Let string be the empty String.
- For each
Record { [[Type]], [[Value]], [[Unit]] } part in parts, do- Set string to the
string-concatenation of string and part.[[Value]].
- Set string to the
- Append string to strings.
- Let formattedPartsList be
CreatePartsFromList (lf, strings). - Let partitionedPartsIndex be 0.
- Let partitionedLength be the number of elements in partitionedPartsList.
- Let flattenedPartsList be a new empty
List . - For each
Record { [[Type]], [[Value]] } listPart in formattedPartsList, do- If listPart.[[Type]] is
"element" , then - Else,
- If listPart.[[Type]] is
- Return flattenedPartsList.
13.5.15 PartitionDurationFormatPattern ( durationFormat, duration )
The abstract operation PartitionDurationFormatPattern takes arguments durationFormat (a DurationFormat) and duration (a
- Let result be a new empty
List . - Let signDisplayed be
true . - Let numericUnitFound be
false . - While numericUnitFound is
false , repeat for each row inTable 24 in table order, except the header row:- Let value be the value of duration's field whose name is the Value Field value of the current row.
- Let unitOptions be the value of durationFormat's internal slot whose name is the Internal Slot value of the current row.
- Let style be unitOptions.[[Style]].
- Let display be unitOptions.[[Display]].
- Let unit be the Unit value of the current row.
- Let numberFormatUnit be the NumberFormat Unit value of the current row.
- If style is
"numeric" or"2-digit" , then- Let numericPartsList be
FormatNumericUnits (durationFormat, duration, unit, signDisplayed). - If numericPartsList is not empty, append numericPartsList to result.
- Set numericUnitFound to
true .
- Let numericPartsList be
- Else,
- Let nfOpts be
OrdinaryObjectCreate (null ). - If
NextUnitFractional (durationFormat, unit) istrue , then- Set value to value +
ComputeFractionalDigits (durationFormat, duration). - Let fractionDigits be durationFormat.[[FractionalDigits]].
- If fractionDigits is
undefined , then- Perform !
CreateDataPropertyOrThrow (nfOpts,"maximumFractionDigits" ,9 𝔽). - Perform !
CreateDataPropertyOrThrow (nfOpts,"minimumFractionDigits" ,+0 𝔽).
- Perform !
- Else,
- Perform !
CreateDataPropertyOrThrow (nfOpts,"maximumFractionDigits" , fractionDigits). - Perform !
CreateDataPropertyOrThrow (nfOpts,"minimumFractionDigits" , fractionDigits).
- Perform !
- Perform !
CreateDataPropertyOrThrow (nfOpts,"roundingMode" ,"trunc" ). - Set numericUnitFound to
true .
- Set value to value +
- If display is
"always" or value is not 0, then- Perform !
CreateDataPropertyOrThrow (nfOpts,"numberingSystem" , durationFormat.[[NumberingSystem]]). - If signDisplayed is
true , then- Set signDisplayed to
false . - If value is 0 and
DurationSign (duration) is -1, set value tonegative-zero .
- Set signDisplayed to
- Else,
- Perform !
CreateDataPropertyOrThrow (nfOpts,"signDisplay" ,"never" ).
- Perform !
- Perform !
CreateDataPropertyOrThrow (nfOpts,"style" ,"unit" ). - Perform !
CreateDataPropertyOrThrow (nfOpts,"unit" , numberFormatUnit). - Perform !
CreateDataPropertyOrThrow (nfOpts,"unitDisplay" , style). - Let nf be !
Construct (%Intl.NumberFormat% , « durationFormat.[[Locale]], nfOpts »). - Let parts be
PartitionNumberPattern (nf, value). - Let list be a new empty
List . - For each
Record { [[Type]], [[Value]] } part of parts, do- Append the
Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: numberFormatUnit } to list.
- Append the
- Append list to result.
- Perform !
- Let nfOpts be
- Return
ListFormatParts (durationFormat, result).
Value Field | Internal Slot | Unit | NumberFormat Unit |
---|---|---|---|
[[Years]] | [[YearsOptions]] | ||
[[Months]] | [[MonthsOptions]] | ||
[[Weeks]] | [[WeeksOptions]] | ||
[[Days]] | [[DaysOptions]] | ||
[[Hours]] | [[HoursOptions]] | ||
[[Minutes]] | [[MinutesOptions]] | ||
[[Seconds]] | [[SecondsOptions]] | ||
[[Milliseconds]] | [[MillisecondsOptions]] | ||
[[Microseconds]] | [[MicrosecondsOptions]] | ||
[[Nanoseconds]] | [[NanosecondsOptions]] |
14 ListFormat Objects
14.1 The Intl.ListFormat Constructor
The Intl.ListFormat
- is %Intl.ListFormat%.
- is the initial value of the
"ListFormat" property of theIntl object .
Behaviour common to all
14.1.1 Intl.ListFormat ( [ locales [ , options ] ] )
When the Intl.ListFormat
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - Let listFormat be ?
OrdinaryCreateFromConstructor (NewTarget,"%Intl.ListFormat.prototype%" , « [[InitializedListFormat]], [[Locale]], [[Type]], [[Style]], [[Templates]] »). - Let optionsResolution be ?
ResolveOptions (%Intl.ListFormat% ,%Intl.ListFormat% .[[LocaleData]], locales, options). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Set listFormat.[[Locale]] to r.[[Locale]].
- Let type be ?
GetOption (options,"type" ,string , «"conjunction" ,"disjunction" ,"unit" »,"conjunction" ). - Set listFormat.[[Type]] to type.
- Let style be ?
GetOption (options,"style" ,string , «"long" ,"short" ,"narrow" »,"long" ). - Set listFormat.[[Style]] to style.
- Let resolvedLocaleData be r.[[LocaleData]].
- Let dataLocaleTypes be resolvedLocaleData.[[<type>]].
- Set listFormat.[[Templates]] to dataLocaleTypes.[[<style>]].
- Return listFormat.
14.2 Properties of the Intl.ListFormat Constructor
The Intl.ListFormat
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
14.2.1 Intl.ListFormat.prototype
The value of Intl.ListFormat.prototype
is
This property has the attributes { [[Writable]]:
14.2.2 Intl.ListFormat.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.ListFormat% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
14.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[RelevantExtensionKeys]] internal slot is « ».
The value of the [[ResolutionOptionDescriptors]] internal slot is « ».
The value of the [[LocaleData]] internal slot is
- [[LocaleData]].[[<locale>]] is a
Record which has three fields [[conjunction]], [[disjunction]], and [[unit]]. Each of these is aRecord which must have fields with the names of three formatting styles: [[long]], [[short]], and [[narrow]]. - Each of those fields is considered a ListFormat template set, which must be a
List ofRecords with fields named: [[Pair]], [[Start]], [[Middle]], and [[End]]. Each of those fields must be a template string as specified in LDMLList Format Rules. Each template string must contain the substrings"{0}" and"{1}" exactly once. Thesubstring "{0}" should occur before thesubstring "{1}" .
conjunction
corresponds to "standard", disjunction
corresponds to "or", and unit
corresponds to "unit".
conjunction
stands for "and"-based lists (e.g., "A, B, and C"), disjunction
stands for "or"-based lists (e.g., "A, B, or C"), and unit
stands for lists of values with units (e.g., "5 pounds, 12 ounces").
14.3 Properties of the Intl.ListFormat Prototype Object
The Intl.ListFormat prototype object:
- is %Intl.ListFormat.prototype%.
- is an
ordinary object . - is not an Intl.ListFormat instance and does not have an [[InitializedListFormat]] internal slot or any of the other internal slots of Intl.ListFormat instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
14.3.1 Intl.ListFormat.prototype.constructor
The initial value of Intl.ListFormat.prototype.constructor
is
14.3.2 Intl.ListFormat.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let lf be the
this value. - Perform ?
RequireInternalSlot (lf, [[InitializedListFormat]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 25 , except the header row, in table order, do- Let p be the Property value of the current row.
- Let v be the value of lf's internal slot whose name is the Internal Slot value of the current row.
Assert : v is notundefined .- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Return options.
Internal Slot | Property |
---|---|
[[Locale]] | |
[[Type]] | |
[[Style]] |
14.3.3 Intl.ListFormat.prototype.format ( list )
When the format
method is called with an argument list, the following steps are taken:
- Let lf be the
this value. - Perform ?
RequireInternalSlot (lf, [[InitializedListFormat]]). - Let stringList be ?
StringListFromIterable (list). - Return
FormatList (lf, stringList).
14.3.4 Intl.ListFormat.prototype.formatToParts ( list )
When the formatToParts
method is called with an argument list, the following steps are taken:
- Let lf be the
this value. - Perform ?
RequireInternalSlot (lf, [[InitializedListFormat]]). - Let stringList be ?
StringListFromIterable (list). - Return
FormatListToParts (lf, stringList).
14.3.5 Intl.ListFormat.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
14.4 Properties of Intl.ListFormat Instances
Intl.ListFormat instances inherit properties from
Intl.ListFormat instances have an [[InitializedListFormat]] internal slot.
Intl.ListFormat instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used by the list format styles. - [[Type]] is one of the String values
"conjunction" ,"disjunction" , or"unit" , identifying the list of types used. - [[Style]] is one of the String values
"long" ,"short" , or"narrow" , identifying the list formatting style used. - [[Templates]] is a
ListFormat template set .
14.5 Abstract Operations for ListFormat Objects
14.5.1 DeconstructPattern ( pattern, placeables )
The abstract operation DeconstructPattern takes arguments pattern (a
It deconstructs the pattern string into a
placeables is a
Input: DeconstructPattern("AA{xx}BB{yy}CC", { [[xx]]: {[[Type]]: "hour", [[Value]]: "15"}, [[yy]]: {[[Type]]: "minute", [[Value]]: "06"} }) Output (List of parts Records): « {[[Type]]: "literal", [[Value]]: "AA"}, {[[Type]]: "hour", [[Value]]: "15"}, {[[Type]]: "literal", [[Value]]: "BB"}, {[[Type]]: "minute", [[Value]]: "06"}, {[[Type]]: "literal", [[Value]]: "CC"} »
It performs the following steps when called:
- Let patternParts be
PartitionPattern (pattern). - Let result be a new empty
List . - For each
Record { [[Type]], [[Value]] } patternPart of patternParts, do- Let part be patternPart.[[Type]].
- If part is
"literal" , then- Append the
Record { [[Type]]:"literal" , [[Value]]: patternPart.[[Value]] } to result.
- Append the
- Else,
- Return result.
14.5.2 CreatePartsFromList ( listFormat, list )
The abstract operation CreatePartsFromList takes arguments listFormat (an Intl.ListFormat) and list (a
- Let size be the number of elements of list.
- If size is 0, then
- Return a new empty
List .
- Return a new empty
- If size is 2, then
- Let n be an index into listFormat.[[Templates]] based on listFormat.[[Locale]], list[0], and list[1].
- Let pattern be listFormat.[[Templates]][n].[[Pair]].
- Let first be the
Record { [[Type]]:"element" , [[Value]]: list[0] }. - Let second be the
Record { [[Type]]:"element" , [[Value]]: list[1] }. - Let placeables be the
Record { [[0]]: first, [[1]]: second }. - Return
DeconstructPattern (pattern, placeables).
- Let last be the
Record { [[Type]]:"element" , [[Value]]: list[size - 1] }. - Let parts be « last ».
- Let i be size - 2.
- Repeat, while i ≥ 0,
- Let head be the
Record { [[Type]]:"element" , [[Value]]: list[i] }. - Let n be an
implementation-defined index into listFormat.[[Templates]] based on listFormat.[[Locale]], head, and parts. - If i is 0, then
- Let pattern be listFormat.[[Templates]][n].[[Start]].
- Else if i is less than size - 2, then
- Let pattern be listFormat.[[Templates]][n].[[Middle]].
- Else,
- Let pattern be listFormat.[[Templates]][n].[[End]].
- Let placeables be the
Record { [[0]]: head, [[1]]: parts }. - Set parts to
DeconstructPattern (pattern, placeables). - Decrement i by 1.
- Let head be the
- Return parts.
14.5.3 FormatList ( listFormat, list )
The abstract operation FormatList takes arguments listFormat (an Intl.ListFormat) and list (a
- Let parts be
CreatePartsFromList (listFormat, list). - Let result be the empty String.
- For each
Record { [[Type]], [[Value]] } part of parts, do- Set result to the
string-concatenation of result and part.[[Value]].
- Set result to the
- Return result.
14.5.4 FormatListToParts ( listFormat, list )
The abstract operation FormatListToParts takes arguments listFormat (an Intl.ListFormat) and list (a
- Let parts be
CreatePartsFromList (listFormat, list). - Let result be !
ArrayCreate (0). - Let n be 0.
- For each
Record { [[Type]], [[Value]] } part of parts, do- Let O be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (O,"type" , part.[[Type]]). - Perform !
CreateDataPropertyOrThrow (O,"value" , part.[[Value]]). - Perform !
CreateDataPropertyOrThrow (result, !ToString (𝔽 (n)), O). - Increment n by 1.
- Let O be
- Return result.
14.5.5 StringListFromIterable ( iterable )
The abstract operation StringListFromIterable takes argument iterable (an
- If iterable is
undefined , then- Return a new empty
List .
- Return a new empty
- Let iteratorRecord be ?
GetIterator (iterable,sync ). - Let list be a new empty
List . - Repeat,
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , then- Return list.
- If next
is not a String , then- Let error be
ThrowCompletion (a newly createdTypeError object). - Return ?
IteratorClose (iteratorRecord, error).
- Let error be
- Append next to list.
- Let next be ?
This algorithm raises exceptions when it encounters values that are not Strings, because there is no obvious locale-aware coercion for arbitrary values.
15 Locale Objects
15.1 The Intl.Locale Constructor
The Intl.Locale
- is %Intl.Locale%.
- is the initial value of the
"Locale" property of theIntl object .
15.1.1 Intl.Locale ( tag [ , options ] )
When the Intl.Locale
function is called with an argument tag and an optional argument options, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - Let localeExtensionKeys be
%Intl.Locale% .[[LocaleExtensionKeys]]. - Let internalSlotsList be « [[InitializedLocale]], [[Locale]], [[Calendar]], [[Collation]], [[HourCycle]], [[NumberingSystem]] ».
- If localeExtensionKeys contains
"kf" , then- Append [[CaseFirst]] to internalSlotsList.
- If localeExtensionKeys contains
"kn" , then- Append [[Numeric]] to internalSlotsList.
- Let locale be ?
OrdinaryCreateFromConstructor (NewTarget,"%Intl.Locale.prototype%" , internalSlotsList). - If tag
is not a String and tagis not an Object , throw aTypeError exception. - If tag
is an Object and tag has an [[InitializedLocale]] internal slot, then- Let tag be tag.[[Locale]].
- Else,
- Let tag be ?
ToString (tag).
- Let tag be ?
- Set options to ?
CoerceOptionsToObject (options). - If
IsStructurallyValidLanguageTag (tag) isfalse , throw aRangeError exception. - Set tag to
CanonicalizeUnicodeLocaleId (tag). - Set tag to ?
UpdateLanguageId (tag, options). - Let opt be a new
Record . - Let calendar be ?
GetOption (options,"calendar" ,string ,empty ,undefined ). - If calendar is not
undefined , then- If calendar cannot be matched by the
type
Unicode locale nonterminal , throw aRangeError exception.
- If calendar cannot be matched by the
- Set opt.[[ca]] to calendar.
- Let collation be ?
GetOption (options,"collation" ,string ,empty ,undefined ). - If collation is not
undefined , then- If collation cannot be matched by the
type
Unicode locale nonterminal , throw aRangeError exception.
- If collation cannot be matched by the
- Set opt.[[co]] to collation.
- Let hc be ?
GetOption (options,"hourCycle" ,string , «"h11" ,"h12" ,"h23" ,"h24" »,undefined ). - Set opt.[[hc]] to hc.
- Let kf be ?
GetOption (options,"caseFirst" ,string , «"upper" ,"lower" ,"false" »,undefined ). - Set opt.[[kf]] to kf.
- Let kn be ?
GetOption (options,"numeric" ,boolean ,empty ,undefined ). - If kn is not
undefined , set kn to !ToString (kn). - Set opt.[[kn]] to kn.
- Let numberingSystem be ?
GetOption (options,"numberingSystem" ,string ,empty ,undefined ). - If numberingSystem is not
undefined , then- If numberingSystem cannot be matched by the
type
Unicode locale nonterminal , throw aRangeError exception.
- If numberingSystem cannot be matched by the
- Set opt.[[nu]] to numberingSystem.
- Let r be
MakeLocaleRecord (tag, opt, localeExtensionKeys). - Set locale.[[Locale]] to r.[[locale]].
- Set locale.[[Calendar]] to r.[[ca]].
- Set locale.[[Collation]] to r.[[co]].
- Set locale.[[HourCycle]] to r.[[hc]].
- If localeExtensionKeys contains
"kf" , then- Set locale.[[CaseFirst]] to r.[[kf]].
- If localeExtensionKeys contains
"kn" , then- If
SameValue (r.[[kn]],"true" ) istrue or r.[[kn]] is the empty String, then- Set locale.[[Numeric]] to
true .
- Set locale.[[Numeric]] to
- Else,
- Set locale.[[Numeric]] to
false .
- Set locale.[[Numeric]] to
- If
- Set locale.[[NumberingSystem]] to r.[[nu]].
- Return locale.
15.1.2 UpdateLanguageId ( tag, options )
The abstract operation UpdateLanguageId takes arguments tag (a unicode_language_id
- Let baseName be
GetLocaleBaseName (tag). - Let language be ?
GetOption (options,"language" ,string ,empty ,GetLocaleLanguage (baseName)). - If language cannot be matched by the
unicode_language_subtag
Unicode locale nonterminal , throw aRangeError exception. - Let script be ?
GetOption (options,"script" ,string ,empty ,GetLocaleScript (baseName)). - If script is not
undefined , then- If script cannot be matched by the
unicode_script_subtag
Unicode locale nonterminal , throw aRangeError exception.
- If script cannot be matched by the
- Let region be ?
GetOption (options,"region" ,string ,empty ,GetLocaleRegion (baseName)). - If region is not
undefined , then- If region cannot be matched by the
unicode_region_subtag
Unicode locale nonterminal , throw aRangeError exception.
- If region cannot be matched by the
- Let variants be ?
GetOption (options,"variants" ,string ,empty ,GetLocaleVariants (baseName)). - If variants is not
undefined , then- If variants is the empty String, throw a
RangeError exception. - Let lowerVariants be the
ASCII-lowercase of variants. - Let variantSubtags be
StringSplitToList (lowerVariants,"-" ). - For each element variant of variantSubtags, do
- If variant cannot be matched by the
unicode_variant_subtag
Unicode locale nonterminal , throw aRangeError exception.
- If variant cannot be matched by the
- If variantSubtags contains any duplicate elements, throw a
RangeError exception.
- If variants is the empty String, throw a
- Let allExtensions be the suffix of tag following baseName.
- Let newTag be language.
- If script is not
undefined , set newTag to thestring-concatenation of newTag,"-" , and script. - If region is not
undefined , set newTag to thestring-concatenation of newTag,"-" , and region. - If variants is not
undefined , set newTag to thestring-concatenation of newTag,"-" , and variants. - Set newTag to the
string-concatenation of newTag and allExtensions. - Return newTag.
15.1.3 MakeLocaleRecord ( tag, options, localeExtensionKeys )
The abstract operation MakeLocaleRecord takes arguments tag (a
- If tag contains a
substring that is aUnicode locale extension sequence , then- Let extension be the String value consisting of the
substring of theUnicode locale extension sequence within tag. - Let components be
UnicodeExtensionComponents (extension). - Let attributes be components.[[Attributes]].
- Let keywords be components.[[Keywords]].
- Let extension be the String value consisting of the
- Else,
- Let result be a new
Record . - For each element key of localeExtensionKeys, do
- If keywords contains an element whose [[Key]] is key, then
- Let entry be the element of keywords whose [[Key]] is key.
- Let value be entry.[[Value]].
- Else,
- Let entry be
empty . - Let value be
undefined .
- Let entry be
Assert : options has a field [[<key>]].- Let overrideValue be options.[[<key>]].
- If overrideValue is not
undefined , then- Set value to
CanonicalizeUValue (key, overrideValue). - If entry is not
empty , then- Set entry.[[Value]] to value.
- Else,
- Append the
Record { [[Key]]: key, [[Value]]: value } to keywords.
- Append the
- Set value to
- Set result.[[<key>]] to value.
- If keywords contains an element whose [[Key]] is key, then
- Let locale be the String value that is tag with any
Unicode locale extension sequences removed. - If attributes is not empty or keywords is not empty, then
- Set result.[[locale]] to
InsertUnicodeExtensionAndCanonicalize (locale, attributes, keywords).
- Set result.[[locale]] to
- Else,
- Set result.[[locale]] to
CanonicalizeUnicodeLocaleId (locale).
- Set result.[[locale]] to
- Return result.
15.2 Properties of the Intl.Locale Constructor
The Intl.Locale
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
15.2.1 Intl.Locale.prototype
The value of Intl.Locale.prototype
is
This property has the attributes { [[Writable]]:
15.2.2 Internal slots
The value of the [[LocaleExtensionKeys]] internal slot is a
15.3 Properties of the Intl.Locale Prototype Object
The Intl.Locale prototype object:
- is %Intl.Locale.prototype%.
- is an
ordinary object . - is not an Intl.Locale instance and does not have an [[InitializedLocale]] internal slot or any of the other internal slots of Intl.Locale instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
15.3.1 Intl.Locale.prototype.constructor
The initial value of Intl.Locale.prototype.constructor
is
15.3.2 get Intl.Locale.prototype.baseName
Intl.Locale.prototype.baseName
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return
GetLocaleBaseName (loc.[[Locale]]).
15.3.3 get Intl.Locale.prototype.calendar
Intl.Locale.prototype.calendar
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return loc.[[Calendar]].
15.3.4 get Intl.Locale.prototype.caseFirst
This property only exists if
Intl.Locale.prototype.caseFirst
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return loc.[[CaseFirst]].
15.3.5 get Intl.Locale.prototype.collation
Intl.Locale.prototype.collation
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return loc.[[Collation]].
15.3.6 get Intl.Locale.prototype.hourCycle
Intl.Locale.prototype.hourCycle
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return loc.[[HourCycle]].
15.3.7 get Intl.Locale.prototype.language
Intl.Locale.prototype.language
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return
GetLocaleLanguage (loc.[[Locale]]).
15.3.8 Intl.Locale.prototype.maximize ( )
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set maximal to loc.[[Locale]].
- Return !
Construct (%Intl.Locale% , maximal).
15.3.9 Intl.Locale.prototype.minimize ( )
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set minimal to loc.[[Locale]].
- Return !
Construct (%Intl.Locale% , minimal).
15.3.10 get Intl.Locale.prototype.numberingSystem
Intl.Locale.prototype.numberingSystem
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return loc.[[NumberingSystem]].
15.3.11 get Intl.Locale.prototype.numeric
This property only exists if
Intl.Locale.prototype.numeric
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return loc.[[Numeric]].
15.3.12 get Intl.Locale.prototype.region
Intl.Locale.prototype.region
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return
GetLocaleRegion (loc.[[Locale]]).
15.3.13 get Intl.Locale.prototype.script
Intl.Locale.prototype.script
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return
GetLocaleScript (loc.[[Locale]]).
15.3.14 Intl.Locale.prototype.toString ( )
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return loc.[[Locale]].
15.3.15 get Intl.Locale.prototype.variants
Intl.Locale.prototype.variants
is an
- Let loc be the
this value. - Perform ?
RequireInternalSlot (loc, [[InitializedLocale]]). - Return
GetLocaleVariants (loc.[[Locale]]).
15.3.16 Intl.Locale.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
15.4 Properties of Intl.Locale Instances
Intl.Locale instances are
Intl.Locale instances have an [[InitializedLocale]] internal slot.
Intl.Locale instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for formatting. - [[Calendar]] is either
undefined or a String value that is a well-formed Unicode Calendar Identifier in canonical form. - [[Collation]] is either
undefined or a String value that is a well-formed Unicode Collation Identifier in canonical form. - [[HourCycle]] is either
undefined or a String value that is a valid Unicode Hour Cycle Identifier in canonical form. - [[NumberingSystem]] is either
undefined or a String value that is a well-formed Unicode Number System Identifier in canonical form. - [[CaseFirst]] is either
undefined or one of the String values"upper" ,"lower" , or"false" . This internal slot only exists if the [[LocaleExtensionKeys]] internal slot of%Intl.Locale% contains"kf" . - [[Numeric]] is either
undefined or a Boolean value specifying whether numeric sorting is used by the locale. This internal slot only exists if the [[LocaleExtensionKeys]] internal slot of%Intl.Locale% contains"kn" .
15.5 Abstract Operations for Locale Objects
15.5.1 GetLocaleBaseName ( locale )
The abstract operation GetLocaleBaseName takes argument locale (a String) and returns a String. It performs the following steps when called:
Assert : locale can be matched by theunicode_locale_id
Unicode locale nonterminal .- Return the longest prefix of locale matched by the
unicode_language_id
Unicode locale nonterminal .
15.5.2 GetLocaleLanguage ( locale )
The abstract operation GetLocaleLanguage takes argument locale (a String) and returns a String. It performs the following steps when called:
- Let baseName be
GetLocaleBaseName (locale). Assert : The firstsubtag of baseName can be matched by theunicode_language_subtag
Unicode locale nonterminal .- Return the first
subtag of baseName.
15.5.3 GetLocaleScript ( locale )
The abstract operation GetLocaleScript takes argument locale (a String) and returns a String or
- Let baseName be
GetLocaleBaseName (locale). Assert : baseName contains at most onesubtag that can be matched by theunicode_script_subtag
Unicode locale nonterminal .- If baseName contains a
subtag matched by theunicode_script_subtag
Unicode locale nonterminal , return thatsubtag . - Return
undefined .
15.5.4 GetLocaleRegion ( locale )
The abstract operation GetLocaleRegion takes argument locale (a String) and returns a String or
- Let baseName be
GetLocaleBaseName (locale). - NOTE: A
unicode_region_subtag
subtag is only valid immediately after an initialunicode_language_subtag
subtag , optionally with a singleunicode_script_subtag
subtag between them. In that position,unicode_region_subtag
cannot be confused with any other validsubtag because all their productions are disjoint. Assert : The firstsubtag of baseName can be matched by theunicode_language_subtag
Unicode locale nonterminal .- Let baseNameTail be the suffix of baseName following the first
subtag . Assert : baseNameTail contains at most onesubtag that can be matched by theunicode_region_subtag
Unicode locale nonterminal .- If baseNameTail contains a
subtag matched by theunicode_region_subtag
Unicode locale nonterminal , return thatsubtag . - Return
undefined .
15.5.5 GetLocaleVariants ( locale )
The abstract operation GetLocaleVariants takes argument locale (a String) and returns a String or
- Let baseName be
GetLocaleBaseName (locale). - NOTE: Each
subtag in baseName that is preceded by"-" is either aunicode_script_subtag
,unicode_region_subtag
, orunicode_variant_subtag
, but anysubstring matched byunicode_variant_subtag
is strictly longer than any prefix thereof which could also be matched by one of the other productions. - Let variants be the longest suffix of baseName that starts with a
"-" followed by asubstring that is matched by theunicode_variant_subtag
Unicode locale nonterminal . If there is no such suffix, returnundefined . - Return the
substring of variants from 1.
16 NumberFormat Objects
16.1 The Intl.NumberFormat Constructor
The Intl.NumberFormat
- is %Intl.NumberFormat%.
- is the initial value of the
"NumberFormat" property of theIntl object .
Behaviour common to all
16.1.1 Intl.NumberFormat ( [ locales [ , options ] ] )
When the Intl.NumberFormat
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , let newTarget be theactive function object , else let newTarget be NewTarget. - Let numberFormat be ?
OrdinaryCreateFromConstructor (newTarget,"%Intl.NumberFormat.prototype%" , « [[InitializedNumberFormat]], [[Locale]], [[LocaleData]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[RoundingIncrement]], [[RoundingMode]], [[ComputedRoundingPriority]], [[TrailingZeroDisplay]], [[BoundFormat]] »). - Let optionsResolution be ?
ResolveOptions (%Intl.NumberFormat% ,%Intl.NumberFormat% .[[LocaleData]], locales, options, «coerce-options »). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Set numberFormat.[[Locale]] to r.[[Locale]].
- Set numberFormat.[[LocaleData]] to r.[[LocaleData]].
- Set numberFormat.[[NumberingSystem]] to r.[[nu]].
- Perform ?
SetNumberFormatUnitOptions (numberFormat, options). - Let style be numberFormat.[[Style]].
- Let notation be ?
GetOption (options,"notation" ,string , «"standard" ,"scientific" ,"engineering" ,"compact" »,"standard" ). - Set numberFormat.[[Notation]] to notation.
- If style is
"currency" and notation is"standard" , then- Let currency be numberFormat.[[Currency]].
- Let cDigits be
CurrencyDigits (currency). - Let mnfdDefault be cDigits.
- Let mxfdDefault be cDigits.
- Else,
- Let mnfdDefault be 0.
- If style is
"percent" , then- Let mxfdDefault be 0.
- Else,
- Let mxfdDefault be 3.
- Perform ?
SetNumberFormatDigitOptions (numberFormat, options, mnfdDefault, mxfdDefault, notation). - Let compactDisplay be ?
GetOption (options,"compactDisplay" ,string , «"short" ,"long" »,"short" ). - Let defaultUseGrouping be
"auto" . - If notation is
"compact" , then- Set numberFormat.[[CompactDisplay]] to compactDisplay.
- Set defaultUseGrouping to
"min2" .
- NOTE: For historical reasons, the strings
"true" and"false" are accepted and replaced with the default value. - Let useGrouping be ?
GetBooleanOrStringNumberFormatOption (options,"useGrouping" , «"min2" ,"auto" ,"always" ,"true" ,"false" », defaultUseGrouping). - If useGrouping is
"true" or useGrouping is"false" , set useGrouping to defaultUseGrouping. - If useGrouping is
true , set useGrouping to"always" . - Set numberFormat.[[UseGrouping]] to useGrouping.
- Let signDisplay be ?
GetOption (options,"signDisplay" ,string , «"auto" ,"never" ,"always" ,"exceptZero" ,"negative" »,"auto" ). - Set numberFormat.[[SignDisplay]] to signDisplay.
- If the implementation supports the normative optional
constructor mode of4.3 Note 1 , then- Let this be the
this value. - Return ?
ChainNumberFormat (numberFormat, NewTarget, this).
- Let this be the
- Return numberFormat.
16.1.1.1 ChainNumberFormat ( numberFormat, newTarget, this )
The abstract operation ChainNumberFormat takes arguments numberFormat (an Intl.NumberFormat), newTarget (an
- If newTarget is
undefined and ?OrdinaryHasInstance (%Intl.NumberFormat% , this) istrue , then- Perform ?
DefinePropertyOrThrow (this,%Intl% .[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: numberFormat, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:false }). - Return this.
- Perform ?
- Return numberFormat.
16.1.2 SetNumberFormatDigitOptions ( intlObj, options, mnfdDefault, mxfdDefault, notation )
The abstract operation SetNumberFormatDigitOptions takes arguments intlObj (an Object), options (an Object), mnfdDefault (an
- Let mnid be ?
GetNumberOption (options,"minimumIntegerDigits," , 1, 21, 1). - Let mnfd be ?
Get (options,"minimumFractionDigits" ). - Let mxfd be ?
Get (options,"maximumFractionDigits" ). - Let mnsd be ?
Get (options,"minimumSignificantDigits" ). - Let mxsd be ?
Get (options,"maximumSignificantDigits" ). - Set intlObj.[[MinimumIntegerDigits]] to mnid.
- Let roundingIncrement be ?
GetNumberOption (options,"roundingIncrement" , 1, 5000, 1). - If roundingIncrement is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a
RangeError exception. - Let roundingMode be ?
GetOption (options,"roundingMode" ,string , «"ceil" ,"floor" ,"expand" ,"trunc" ,"halfCeil" ,"halfFloor" ,"halfExpand" ,"halfTrunc" ,"halfEven" »,"halfExpand" ). - Let roundingPriority be ?
GetOption (options,"roundingPriority" ,string , «"auto" ,"morePrecision" ,"lessPrecision" »,"auto" ). - Let trailingZeroDisplay be ?
GetOption (options,"trailingZeroDisplay" ,string , «"auto" ,"stripIfInteger" »,"auto" ). - NOTE: All fields required by
SetNumberFormatDigitOptions have now been read from options. The remainder of this AO interprets the options and may throw exceptions. - If roundingIncrement is not 1, set mxfdDefault to mnfdDefault.
- Set intlObj.[[RoundingIncrement]] to roundingIncrement.
- Set intlObj.[[RoundingMode]] to roundingMode.
- Set intlObj.[[TrailingZeroDisplay]] to trailingZeroDisplay.
- If mnsd is
undefined and mxsd isundefined , let hasSd befalse . Otherwise, let hasSd betrue . - If mnfd is
undefined and mxfd isundefined , let hasFd befalse . Otherwise, let hasFd betrue . - Let needSd be
true . - Let needFd be
true . - If roundingPriority is
"auto" , then- Set needSd to hasSd.
- If needSd is
true , or hasFd isfalse and notation is"compact" , then- Set needFd to
false .
- Set needFd to
- If needSd is
true , then- If hasSd is
true , then- Set intlObj.[[MinimumSignificantDigits]] to ?
DefaultNumberOption (mnsd, 1, 21, 1). - Set intlObj.[[MaximumSignificantDigits]] to ?
DefaultNumberOption (mxsd, intlObj.[[MinimumSignificantDigits]], 21, 21).
- Set intlObj.[[MinimumSignificantDigits]] to ?
- Else,
- Set intlObj.[[MinimumSignificantDigits]] to 1.
- Set intlObj.[[MaximumSignificantDigits]] to 21.
- If hasSd is
- If needFd is
true , then- If hasFd is
true , then- Set mnfd to ?
DefaultNumberOption (mnfd, 0, 100,undefined ). - Set mxfd to ?
DefaultNumberOption (mxfd, 0, 100,undefined ). - If mnfd is
undefined , set mnfd tomin (mnfdDefault, mxfd). - Else if mxfd is
undefined , set mxfd tomax (mxfdDefault, mnfd). - Else if mnfd is greater than mxfd, throw a
RangeError exception. - Set intlObj.[[MinimumFractionDigits]] to mnfd.
- Set intlObj.[[MaximumFractionDigits]] to mxfd.
- Set mnfd to ?
- Else,
- Set intlObj.[[MinimumFractionDigits]] to mnfdDefault.
- Set intlObj.[[MaximumFractionDigits]] to mxfdDefault.
- If hasFd is
- If needSd is
false and needFd isfalse , then- Set intlObj.[[MinimumFractionDigits]] to 0.
- Set intlObj.[[MaximumFractionDigits]] to 0.
- Set intlObj.[[MinimumSignificantDigits]] to 1.
- Set intlObj.[[MaximumSignificantDigits]] to 2.
- Set intlObj.[[RoundingType]] to
more-precision . - Set intlObj.[[ComputedRoundingPriority]] to
"morePrecision" .
- Else if roundingPriority is
"morePrecision" , then- Set intlObj.[[RoundingType]] to
more-precision . - Set intlObj.[[ComputedRoundingPriority]] to
"morePrecision" .
- Set intlObj.[[RoundingType]] to
- Else if roundingPriority is
"lessPrecision" , then- Set intlObj.[[RoundingType]] to
less-precision . - Set intlObj.[[ComputedRoundingPriority]] to
"lessPrecision" .
- Set intlObj.[[RoundingType]] to
- Else if hasSd is
true , then- Set intlObj.[[RoundingType]] to
significant-digits . - Set intlObj.[[ComputedRoundingPriority]] to
"auto" .
- Set intlObj.[[RoundingType]] to
- Else,
- Set intlObj.[[RoundingType]] to
fraction-digits . - Set intlObj.[[ComputedRoundingPriority]] to
"auto" .
- Set intlObj.[[RoundingType]] to
- If roundingIncrement is not 1, then
- If intlObj.[[RoundingType]] is not
fraction-digits , throw aTypeError exception. - If intlObj.[[MaximumFractionDigits]] is not intlObj.[[MinimumFractionDigits]], throw a
RangeError exception.
- If intlObj.[[RoundingType]] is not
- Return
unused .
16.1.3 SetNumberFormatUnitOptions ( intlObj, options )
The abstract operation SetNumberFormatUnitOptions takes arguments intlObj (an Intl.NumberFormat) and options (an Object) and returns either a
- Let style be ?
GetOption (options,"style" ,string , «"decimal" ,"percent" ,"currency" ,"unit" »,"decimal" ). - Set intlObj.[[Style]] to style.
- Let currency be ?
GetOption (options,"currency" ,string ,empty ,undefined ). - If currency is
undefined , then- If style is
"currency" , throw aTypeError exception.
- If style is
- Else,
- If
IsWellFormedCurrencyCode (currency) isfalse , throw aRangeError exception.
- If
- Let currencyDisplay be ?
GetOption (options,"currencyDisplay" ,string , «"code" ,"symbol" ,"narrowSymbol" ,"name" »,"symbol" ). - Let currencySign be ?
GetOption (options,"currencySign" ,string , «"standard" ,"accounting" »,"standard" ). - Let unit be ?
GetOption (options,"unit" ,string ,empty ,undefined ). - If unit is
undefined , then- If style is
"unit" , throw aTypeError exception.
- If style is
- Else,
- If
IsWellFormedUnitIdentifier (unit) isfalse , throw aRangeError exception.
- If
- Let unitDisplay be ?
GetOption (options,"unitDisplay" ,string , «"short" ,"narrow" ,"long" »,"short" ). - If style is
"currency" , then- Set intlObj.[[Currency]] to the
ASCII-uppercase of currency. - Set intlObj.[[CurrencyDisplay]] to currencyDisplay.
- Set intlObj.[[CurrencySign]] to currencySign.
- Set intlObj.[[Currency]] to the
- If style is
"unit" , then- Set intlObj.[[Unit]] to unit.
- Set intlObj.[[UnitDisplay]] to unitDisplay.
- Return
unused .
16.2 Properties of the Intl.NumberFormat Constructor
The Intl.NumberFormat
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
16.2.1 Intl.NumberFormat.prototype
The value of Intl.NumberFormat.prototype
is
This property has the attributes { [[Writable]]:
16.2.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.NumberFormat% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
16.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[RelevantExtensionKeys]] internal slot is «
The value of the [[ResolutionOptionDescriptors]] internal slot is « { [[Key]]:
The value of the [[LocaleData]] internal slot is
- The
List that is the value of the"nu" field of any locale field of [[LocaleData]] must not include the values"native" ,"traditio" , or"finance" . - [[LocaleData]].[[<locale>]] must have a [[patterns]] field for all locale values locale. The value of this field must be a
Record , which must have fields with the names of the four number format styles:"decimal" ,"percent" ,"currency" , and"unit" . -
The two fields
"currency" and"unit" noted above must beRecords with at least one field,"fallback" . The"currency" may have additional fields with keys corresponding to currency codes according to6.3 . Each field of"currency" must be aRecord with fields corresponding to the possible currencyDisplay values:"code" ,"symbol" ,"narrowSymbol" , and"name" . Each of those fields must contain aRecord with fields corresponding to the possible currencySign values:"standard" or"accounting" . The"unit" field (of [[LocaleData]].[[<locale>]]) may have additional fields beyond the required field"fallback" with keys corresponding to core measurement unit identifiers corresponding to6.6 . Each field of"unit" must be aRecord with fields corresponding to the possible unitDisplay values:"narrow" ,"short" , and"long" . - All of the leaf fields so far described for the patterns tree (
"decimal" ,"percent" , great-grandchildren of"currency" , and grandchildren of"unit" ) must beRecords with the keys"positivePattern" ,"zeroPattern" , and"negativePattern" . -
The value of the aforementioned fields (the sign-dependent pattern fields) must be string values that must contain the
substring "{number}" ."positivePattern" must contain thesubstring "{plusSign}" but not"{minusSign}" ;"negativePattern" must contain thesubstring "{minusSign}" but not"{plusSign}" ; and"zeroPattern" must not contain either"{plusSign}" or"{minusSign}" . Additionally, the values within the"percent" field must also contain thesubstring "{percentSign}" ; the values within the"currency" field must also contain one or more of the following substrings:"{currencyCode}" ,"{currencyPrefix}" , or"{currencySuffix}" ; and the values within the"unit" field must also contain one or more of the following substrings:"{unitPrefix}" or"{unitSuffix}" . The pattern strings, when interpreted as a sequence of UTF-16 encoded code points as described inECMA-262 ,6.1.4 , must not contain any code points in the General Category "Number, decimal digit" as specified by the Unicode Standard. - [[LocaleData]].[[<locale>]] must also have a [[notationSubPatterns]] field for all locale values locale. The value of this field must be a
Record , which must have two fields: [[scientific]] and [[compact]]. The [[scientific]] field must be a string value containing the substrings"{number}" ,"{scientificSeparator}" , and"{scientificExponent}" . The [[compact]] field must be aRecord with two fields:"short" and"long" . Each of these fields must be aRecord withinteger keys corresponding to all discrete magnitudes the implementation supports for compact notation. Each of these fields must be a string value which may contain thesubstring "{number}" . Strings descended from"short" must contain thesubstring "{compactSymbol}" , and strings descended from"long" must contain thesubstring "{compactName}" .
16.3 Properties of the Intl.NumberFormat Prototype Object
The Intl.NumberFormat prototype object:
- is %Intl.NumberFormat.prototype%.
- is an
ordinary object . - is not an Intl.NumberFormat instance and does not have an [[InitializedNumberFormat]] internal slot or any of the other internal slots of Intl.NumberFormat instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
16.3.1 Intl.NumberFormat.prototype.constructor
The initial value of Intl.NumberFormat.prototype.constructor
is
16.3.2 Intl.NumberFormat.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let nf be the
this value. - If the implementation supports the normative optional
constructor mode of4.3 Note 1 , then- Set nf to ?
UnwrapNumberFormat (nf).
- Set nf to ?
- Perform ?
RequireInternalSlot (nf, [[InitializedNumberFormat]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 26 , except the header row, in table order, do- Let p be the Property value of the current row.
- Let v be the value of nf's internal slot whose name is the Internal Slot value of the current row.
- If v is not
undefined , then- If there is a Conversion value in the current row, then
- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Return options.
Internal Slot | Property | Conversion |
---|---|---|
[[Locale]] | ||
[[NumberingSystem]] | ||
[[Style]] | ||
[[Currency]] | ||
[[CurrencyDisplay]] | ||
[[CurrencySign]] | ||
[[Unit]] | ||
[[UnitDisplay]] | ||
[[MinimumIntegerDigits]] | ||
[[MinimumFractionDigits]] | ||
[[MaximumFractionDigits]] | ||
[[MinimumSignificantDigits]] | ||
[[MaximumSignificantDigits]] | ||
[[UseGrouping]] | ||
[[Notation]] | ||
[[CompactDisplay]] | ||
[[SignDisplay]] | ||
[[RoundingIncrement]] | ||
[[RoundingMode]] | ||
[[ComputedRoundingPriority]] | ||
[[TrailingZeroDisplay]] |
16.3.3 get Intl.NumberFormat.prototype.format
Intl.NumberFormat.prototype.format is an
- Let nf be the
this value. - If the implementation supports the normative optional
constructor mode of4.3 Note 1 , then- Set nf to ?
UnwrapNumberFormat (nf).
- Set nf to ?
- Perform ?
RequireInternalSlot (nf, [[InitializedNumberFormat]]). - If nf.[[BoundFormat]] is
undefined , then- Let F be a new built-in
function object as defined in Number Format Functions (16.5.2 ). - Set F.[[NumberFormat]] to nf.
- Set nf.[[BoundFormat]] to F.
- Let F be a new built-in
- Return nf.[[BoundFormat]].
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.
16.3.4 Intl.NumberFormat.prototype.formatRange ( start, end )
When the formatRange
method is called with arguments start and end, the following steps are taken:
- Let nf be the
this value. - Perform ?
RequireInternalSlot (nf, [[InitializedNumberFormat]]). - If start is
undefined or end isundefined , throw aTypeError exception. - Let x be ?
ToIntlMathematicalValue (start). - Let y be ?
ToIntlMathematicalValue (end). - Return ?
FormatNumericRange (nf, x, y).
16.3.5 Intl.NumberFormat.prototype.formatRangeToParts ( start, end )
When the formatRangeToParts
method is called with arguments start and end, the following steps are taken:
- Let nf be the
this value. - Perform ?
RequireInternalSlot (nf, [[InitializedNumberFormat]]). - If start is
undefined or end isundefined , throw aTypeError exception. - Let x be ?
ToIntlMathematicalValue (start). - Let y be ?
ToIntlMathematicalValue (end). - Return ?
FormatNumericRangeToParts (nf, x, y).
16.3.6 Intl.NumberFormat.prototype.formatToParts ( value )
When the formatToParts
method is called with an optional argument value, the following steps are taken:
- Let nf be the
this value. - Perform ?
RequireInternalSlot (nf, [[InitializedNumberFormat]]). - Let x be ?
ToIntlMathematicalValue (value). - Return
FormatNumericToParts (nf, x).
16.3.7 Intl.NumberFormat.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
16.4 Properties of Intl.NumberFormat Instances
Intl.NumberFormat instances are
Intl.NumberFormat instances have an [[InitializedNumberFormat]] internal slot.
Intl.NumberFormat instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for formatting. - [[LocaleData]] is a
Record representing the data available to the implementation for formatting. It is the value of an entry in%Intl.NumberFormat% .[[LocaleData]] associated with either the value of [[Locale]] or a prefix thereof. - [[NumberingSystem]]
is a String value representing the Unicode Number System Identifier used for formatting. - [[Style]] is one of the String values
"decimal" ,"currency" ,"percent" , or"unit" , identifying the type of quantity being measured. - [[Currency]]
is a String value with the currency code identifying the currency to be used if formatting with the"currency" unit type. It is only used when [[Style]] has the value"currency" . - [[CurrencyDisplay]] is one of the String values
"code" ,"symbol" ,"narrowSymbol" , or"name" , specifying whether to display the currency as an ISO 4217 alphabetic currency code, a localized currency symbol, or a localized currency name if formatting with the"currency" style. It is only used when [[Style]] has the value"currency" . - [[CurrencySign]] is one of the String values
"standard" or"accounting" , specifying whether to render negative numbers in accounting format, often signified by parenthesis. It is only used when [[Style]] has the value"currency" and when [[SignDisplay]] is not"never" . - [[Unit]] is a
core unit identifier . It is only used when [[Style]] has the value"unit" . - [[UnitDisplay]] is one of the String values
"short" ,"narrow" , or"long" , specifying whether to display the unit as a symbol, narrow symbol, or localized long name if formatting with the"unit" style. It is only used when [[Style]] has the value"unit" . - [[MinimumIntegerDigits]] is a non-negative
integer indicating the minimuminteger digits to be used. Numbers will be padded with leading zeroes if necessary. - [[MinimumFractionDigits]] and [[MaximumFractionDigits]] are non-negative
integers indicating the minimum and maximum fraction digits to be used. Numbers will be rounded or padded with trailing zeroes if necessary. These properties are only used when [[RoundingType]] isfraction-digits ,more-precision , orless-precision . - [[MinimumSignificantDigits]] and [[MaximumSignificantDigits]] are positive
integers indicating the minimum and maximum fraction digits to be shown. If present, the formatter uses however many fraction digits are required to display the specified number of significant digits. These properties are only used when [[RoundingType]] issignificant-digits ,more-precision , orless-precision . - [[UseGrouping]]
is a Boolean or String value indicating the conditions under which a grouping separator should be used. The positions of grouping separators, and whether to display grouping separators for a formatted number, isimplementation-defined . A value"always" hints the implementation to display grouping separators if possible;"min2" , if there are at least 2 digits in a group;"auto" , if the locale prefers to use grouping separators for the formatted number. A valuefalse disables grouping separators. - [[RoundingType]] is one of the values
fraction-digits ,significant-digits ,more-precision , orless-precision , indicating which rounding strategy to use. Iffraction-digits , formatted numbers are rounded according to [[MinimumFractionDigits]] and [[MaximumFractionDigits]], as described above. Ifsignificant-digits , formatted numbers are rounded according to [[MinimumSignificantDigits]] and [[MaximumSignificantDigits]] as described above. Ifmore-precision orless-precision , all four of those settings are used, with specific rules for disambiguating when to use one set versus the other. [[RoundingType]] is derived from the"roundingPriority" option. - [[ComputedRoundingPriority]] is one of the String values
"auto" ,"morePrecision" , or"lessPrecision" . It is only used in16.3.2 to convert [[RoundingType]] back to a valid"roundingPriority" option. - [[Notation]] is one of the String values
"standard" ,"scientific" ,"engineering" , or"compact" , specifying whether the formatted number should be displayed without scaling, scaled to the units place with the power of ten in scientific notation, scaled to the nearest thousand with the power of ten in scientific notation, or scaled to the nearestILD compact decimal notation power of ten with the corresponding compact decimal notation affix. - [[CompactDisplay]] is one of the String values
"short" or"long" , specifying whether to display compact notation affixes in short form ("5K") or long form ("5 thousand") if formatting with the"compact" notation. It is only used when [[Notation]] has the value"compact" . -
[[SignDisplay]] is one of the String values
"auto" ,"always" ,"never" ,"exceptZero" , or"negative" , specifying when to include a sign (with non-"auto" options respectively corresponding with inclusion always, never, only for non-zero numbers, or only for non-zero negative numbers). In scientific notation, this slot affects the sign display of the mantissa but not the exponent. - [[RoundingIncrement]] is an
integer that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then formatted numbers are rounded to the nearest 0.05 ("nickel rounding"). - [[RoundingMode]] is a rounding mode, one of the String values in the Identifier column of
Table 27 . - [[TrailingZeroDisplay]] is one of the String values
"auto" or"stripIfInteger" , indicating whether to strip trailing zeros if the formatted number is aninteger (i.e., has no non-zero fraction digit).
Identifier | Description | Examples: Round to 0 fraction digits | ||||
---|---|---|---|---|---|---|
-1.5 | 0.4 | 0.5 | 0.6 | 1.5 | ||
Toward positive infinity | ⬆️ [-1] | ⬆️ [1] | ⬆️ [1] | ⬆️ [1] | ⬆️ [2] | |
Toward negative infinity | ⬇️ [-2] | ⬇️ [0] | ⬇️ [0] | ⬇️ [0] | ⬇️ [1] | |
Away from zero | ⬇️ [-2] | ⬆️ [1] | ⬆️ [1] | ⬆️ [1] | ⬆️ [2] | |
Toward zero | ⬆️ [-1] | ⬇️ [0] | ⬇️ [0] | ⬇️ [0] | ⬇️ [1] | |
Ties toward positive infinity | ⬆️ [-1] | ⬇️ [0] | ⬆️ [1] | ⬆️ [1] | ⬆️ [2] | |
Ties toward negative infinity | ⬇️ [-2] | ⬇️ [0] | ⬇️ [0] | ⬆️ [1] | ⬇️ [1] | |
Ties away from zero | ⬇️ [-2] | ⬇️ [0] | ⬆️ [1] | ⬆️ [1] | ⬆️ [2] | |
Ties toward zero | ⬆️ [-1] | ⬇️ [0] | ⬇️ [0] | ⬆️ [1] | ⬇️ [1] | |
Ties toward an even rounding increment multiple | ⬇️ [-2] | ⬇️ [0] | ⬇️ [0] | ⬆️ [1] | ⬆️ [2] |
Finally, Intl.NumberFormat instances have a [[BoundFormat]] internal slot that caches the function returned by the format accessor (
16.5 Abstract Operations for NumberFormat Objects
16.5.1 CurrencyDigits ( currency )
The
Assert :IsWellFormedCurrencyCode (currency) istrue .- Return a non-negative
integer indicating the number of fractional digits used when formatting quantities of the currency corresponding to currency. If there is no available information on the number of digits to be used, return 2.
16.5.2 Number Format Functions
A Number format function is an anonymous built-in function that has a [[NumberFormat]] internal slot.
When a Number format function F is called with optional argument value, the following steps are taken:
- Let nf be F.[[NumberFormat]].
Assert : nfis an Object and nf has an [[InitializedNumberFormat]] internal slot.- If value is not provided, let value be
undefined . - Let x be ?
ToIntlMathematicalValue (value). - Return
FormatNumeric (nf, x).
The
16.5.3 FormatNumericToString ( intlObject, x )
The abstract operation FormatNumericToString takes arguments intlObject (an Object) and x (a
Assert : intlObject has [[RoundingMode]], [[RoundingType]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[RoundingIncrement]], and [[TrailingZeroDisplay]] internal slots.- If x is
negative-zero , then- Let sign be
negative . - Set x to 0.
- Let sign be
- Else,
Assert : x is amathematical value .- If x < 0, let sign be
negative ; else let sign bepositive . - If sign is
negative , then- Set x to -x.
- Let unsignedRoundingMode be
GetUnsignedRoundingMode (intlObject.[[RoundingMode]], sign). - If intlObject.[[RoundingType]] is
significant-digits , then- Let result be
ToRawPrecision (x, intlObject.[[MinimumSignificantDigits]], intlObject.[[MaximumSignificantDigits]], unsignedRoundingMode).
- Let result be
- Else if intlObject.[[RoundingType]] is
fraction-digits , then- Let result be
ToRawFixed (x, intlObject.[[MinimumFractionDigits]], intlObject.[[MaximumFractionDigits]], intlObject.[[RoundingIncrement]], unsignedRoundingMode).
- Let result be
- Else,
- Let sResult be
ToRawPrecision (x, intlObject.[[MinimumSignificantDigits]], intlObject.[[MaximumSignificantDigits]], unsignedRoundingMode). - Let fResult be
ToRawFixed (x, intlObject.[[MinimumFractionDigits]], intlObject.[[MaximumFractionDigits]], intlObject.[[RoundingIncrement]], unsignedRoundingMode). - If fResult.[[RoundingMagnitude]] < sResult.[[RoundingMagnitude]], let fixedIsMorePrecise be
true ; else let fixedIsMorePrecise befalse . - If intlObject.[[RoundingType]] is
more-precision and fixedIsMorePrecise istrue , then- Let result be fResult.
- Else if intlObject.[[RoundingType]] is
less-precision and fixedIsMorePrecise isfalse , then- Let result be fResult.
- Else,
- Let result be sResult.
- Let sResult be
- Set x to result.[[RoundedNumber]].
- Let string be result.[[FormattedString]].
- If intlObject.[[TrailingZeroDisplay]] is
"stripIfInteger" andx , thenmodulo 1 = 0- Let i be
StringIndexOf (string,"." , 0). - If i is not
not-found , set string to thesubstring of string from 0 to i.
- Let i be
- Let int be result.[[IntegerDigitsCount]].
- Let minInteger be intlObject.[[MinimumIntegerDigits]].
- If int < minInteger, then
- Let forwardZeros be the String consisting of minInteger - int occurrences of the code unit 0x0030 (DIGIT ZERO).
- Set string to the
string-concatenation of forwardZeros and string.
- If sign is
negative , then- If x is 0, set x to
negative-zero . Otherwise, set x to -x.
- If x is 0, set x to
- Return the
Record { [[RoundedNumber]]: x, [[FormattedString]]: string }.
16.5.4 PartitionNumberPattern ( numberFormat, x )
The abstract operation PartitionNumberPattern takes arguments numberFormat (an object initialized as a NumberFormat) and x (an
- Let exponent be 0.
- If x is
not-a-number , then- Let n be an
ILD String value indicating theNaN value.
- Let n be an
- Else if x is
positive-infinity , then- Let n be an
ILD String value indicating positive infinity.
- Let n be an
- Else if x is
negative-infinity , then- Let n be an
ILD String value indicating negative infinity.
- Let n be an
- Else,
- If x is not
negative-zero , thenAssert : x is amathematical value .- If numberFormat.[[Style]] is
"percent" , set x be 100 × x. - Set exponent to
ComputeExponent (numberFormat, x). - Set x to x × 10-exponent.
- Let formatNumberResult be
FormatNumericToString (numberFormat, x). - Let n be formatNumberResult.[[FormattedString]].
- Set x to formatNumberResult.[[RoundedNumber]].
- If x is not
- Let pattern be
GetNumberFormatPattern (numberFormat, x). - Let result be a new empty
List . - Let patternParts be
PartitionPattern (pattern). - For each
Record { [[Type]], [[Value]] } patternPart of patternParts, do- Let p be patternPart.[[Type]].
- If p is
"literal" , then- Append the
Record { [[Type]]:"literal" , [[Value]]: patternPart.[[Value]] } to result.
- Append the
- Else if p is
"number" , then- Let notationSubParts be
PartitionNotationSubPattern (numberFormat, x, n, exponent). - Set result to the
list-concatenation of result and notationSubParts.
- Let notationSubParts be
- Else if p is
"plusSign" , then - Else if p is
"minusSign" , then - Else if p is
"percentSign" and numberFormat.[[Style]] is"percent" , then - Else if p is
"unitPrefix" and numberFormat.[[Style]] is"unit" , then - Else if p is
"unitSuffix" and numberFormat.[[Style]] is"unit" , then - Else if p is
"currencyCode" and numberFormat.[[Style]] is"currency" , then- Let currency be numberFormat.[[Currency]].
- Let cd be currency.
- Append the
Record { [[Type]]:"currency" , [[Value]]: cd } to result.
- Else if p is
"currencyPrefix" and numberFormat.[[Style]] is"currency" , then- Let currency be numberFormat.[[Currency]].
- Let currencyDisplay be numberFormat.[[CurrencyDisplay]].
- Let cd be an
ILD String value representing currency before x in currencyDisplay form, which may depend on x in languages having different plural forms. - Append the
Record { [[Type]]:"currency" , [[Value]]: cd } to result.
- Else if p is
"currencySuffix" and numberFormat.[[Style]] is"currency" , then- Let currency be numberFormat.[[Currency]].
- Let currencyDisplay be numberFormat.[[CurrencyDisplay]].
- Let cd be an
ILD String value representing currency after x in currencyDisplay form, which may depend on x in languages having different plural forms. If the implementation does not have such a representation of currency, use currency itself. - Append the
Record { [[Type]]:"currency" , [[Value]]: cd } to result.
- Else,
- Return result.
16.5.5 PartitionNotationSubPattern ( numberFormat, x, n, exponent )
The abstract operation PartitionNotationSubPattern takes arguments numberFormat (an Intl.NumberFormat), x (an
- Let result be a new empty
List . - If x is
not-a-number , then- Append the
Record { [[Type]]:"nan" , [[Value]]: n } to result.
- Append the
- Else if x is
positive-infinity ornegative-infinity , then- Append the
Record { [[Type]]:"infinity" , [[Value]]: n } to result.
- Append the
- Else,
- Let notationSubPattern be
GetNotationSubPattern (numberFormat, exponent). - Let patternParts be
PartitionPattern (notationSubPattern). - For each
Record { [[Type]], [[Value]] } patternPart of patternParts, do- Let p be patternPart.[[Type]].
- If p is
"literal" , then- Append the
Record { [[Type]]:"literal" , [[Value]]: patternPart.[[Value]] } to result.
- Append the
- Else if p is
"number" , then- If the numberFormat.[[NumberingSystem]] matches one of the values in the Numbering System column of
Table 28 below, then- Let digits be a
List whose elements are the code points specified in the Digits column of the matching row inTable 28 . Assert : The length of digits is 10.- Let transliterated be the empty String.
- Let len be the length of n.
- Let position be 0.
- Repeat, while position < len,
- Let c be the code unit at index position within n.
- If 0x0030 ≤ c ≤ 0x0039, then
- NOTE: c is an ASCII digit.
- Let i be c - 0x0030.
- Set c to
CodePointsToString (« digits[i] »).
- Set transliterated to the
string-concatenation of transliterated and c. - Set position to position + 1.
- Set n to transliterated.
- Let digits be a
- Else,
- Use an implementation dependent algorithm to map n to the appropriate representation of n in the given numbering system.
- Let decimalSepIndex be
StringIndexOf (n,"." , 0). - If decimalSepIndex is not
not-found and decimalSepIndex > 0, then - Else,
- Let integer be n.
- Let fraction be
undefined .
- If the numberFormat.[[UseGrouping]] is
false , then- Append the
Record { [[Type]]:"integer" , [[Value]]: integer } to result.
- Append the
- Else,
- Let groupSepSymbol be the
ILND String representing the grouping separator. - Let groups be a
List whose elements are, in left to right order, the substrings defined byILND set of locations within the integer, which may depend on the value of numberFormat.[[UseGrouping]]. Assert : The number of elements in groupsList is greater than 0.- Repeat, while groups
List is not empty,
- Let groupSepSymbol be the
- If fraction is not
undefined , then
- If the numberFormat.[[NumberingSystem]] matches one of the values in the Numbering System column of
- Else if p is
"compactSymbol" , then- Let compactSymbol be an
ILD string representing exponent in short form, which may depend on x in languages having different plural forms. The implementation must be able to provide this string, or else the pattern would not have a"{compactSymbol}" placeholder. - Append the
Record { [[Type]]:"compact" , [[Value]]: compactSymbol } to result.
- Let compactSymbol be an
- Else if p is
"compactName" , then- Let compactName be an
ILD string representing exponent in long form, which may depend on x in languages having different plural forms. The implementation must be able to provide this string, or else the pattern would not have a"{compactName}" placeholder. - Append the
Record { [[Type]]:"compact" , [[Value]]: compactName } to result.
- Let compactName be an
- Else if p is
"scientificSeparator" , then - Else if p is
"scientificExponent" , then- If exponent < 0, then
- Let exponentResult be
ToRawFixed (exponent, 0, 0, 1,undefined ). - Append the
Record { [[Type]]:"exponentInteger" , [[Value]]: exponentResult.[[FormattedString]] } to result.
- Else,
- Let notationSubPattern be
- Return result.
Numbering System | Digits |
---|---|
adlm | U+1E950 to U+1E959 |
ahom | U+11730 to U+11739 |
arab | U+0660 to U+0669 |
arabext | U+06F0 to U+06F9 |
bali | U+1B50 to U+1B59 |
beng | U+09E6 to U+09EF |
bhks | U+11C50 to U+11C59 |
brah | U+11066 to U+1106F |
cakm | U+11136 to U+1113F |
cham | U+AA50 to U+AA59 |
deva | U+0966 to U+096F |
diak | U+11950 to U+11959 |
fullwide | U+FF10 to U+FF19 |
gara | U+10D40 to U+10D49 |
gong | U+11DA0 to U+11DA9 |
gonm | U+11D50 to U+11D59 |
gujr | U+0AE6 to U+0AEF |
gukh | U+16130 to U+16139 |
guru | U+0A66 to U+0A6F |
hanidec | U+3007, U+4E00, U+4E8C, U+4E09, U+56DB, U+4E94, U+516D, U+4E03, U+516B, U+4E5D |
hmng | U+16B50 to U+16B59 |
hmnp | U+1E140 to U+1E149 |
java | U+A9D0 to U+A9D9 |
kali | U+A900 to U+A909 |
kawi | U+11F50 to U+11F59 |
khmr | U+17E0 to U+17E9 |
knda | U+0CE6 to U+0CEF |
krai | U+16D70 to U+16D79 |
lana | U+1A80 to U+1A89 |
lanatham | U+1A90 to U+1A99 |
laoo | U+0ED0 to U+0ED9 |
latn | U+0030 to U+0039 |
lepc | U+1C40 to U+1C49 |
limb | U+1946 to U+194F |
mathbold | U+1D7CE to U+1D7D7 |
mathdbl | U+1D7D8 to U+1D7E1 |
mathmono | U+1D7F6 to U+1D7FF |
mathsanb | U+1D7EC to U+1D7F5 |
mathsans | U+1D7E2 to U+1D7EB |
mlym | U+0D66 to U+0D6F |
modi | U+11650 to U+11659 |
mong | U+1810 to U+1819 |
mroo | U+16A60 to U+16A69 |
mtei | U+ABF0 to U+ABF9 |
mymr | U+1040 to U+1049 |
mymrepka | U+116DA to U+116E3 |
mymrpao | U+116D0 to U+116D9 |
mymrshan | U+1090 to U+1099 |
mymrtlng | U+A9F0 to U+A9F9 |
nagm | U+1E4F0 to U+1E4F9 |
newa | U+11450 to U+11459 |
nkoo | U+07C0 to U+07C9 |
olck | U+1C50 to U+1C59 |
onao | U+1E5F1 to U+1E5FA |
orya | U+0B66 to U+0B6F |
osma | U+104A0 to U+104A9 |
outlined | U+1CCF0 to U+1CCF9 |
rohg | U+10D30 to U+10D39 |
saur | U+A8D0 to U+A8D9 |
segment | U+1FBF0 to U+1FBF9 |
shrd | U+111D0 to U+111D9 |
sind | U+112F0 to U+112F9 |
sinh | U+0DE6 to U+0DEF |
sora | U+110F0 to U+110F9 |
sund | U+1BB0 to U+1BB9 |
sunu | U+11BF0 to U+11BF9 |
takr | U+116C0 to U+116C9 |
talu | U+19D0 to U+19D9 |
tamldec | U+0BE6 to U+0BEF |
telu | U+0C66 to U+0C6F |
thai | U+0E50 to U+0E59 |
tibt | U+0F20 to U+0F29 |
tirh | U+114D0 to U+114D9 |
tnsa | U+16AC0 to U+16AC9 |
vaii | U+A620 to U+A629 |
wara | U+118E0 to U+118E9 |
wcho | U+1E2F0 to U+1E2F9 |
16.5.6 FormatNumeric ( numberFormat, x )
The abstract operation FormatNumeric takes arguments numberFormat (an Intl.NumberFormat) and x (an
- Let parts be
PartitionNumberPattern (numberFormat, x). - Let result be the empty String.
- For each
Record { [[Type]], [[Value]] } part of parts, do- Set result to the
string-concatenation of result and part.[[Value]].
- Set result to the
- Return result.
16.5.7 FormatNumericToParts ( numberFormat, x )
The abstract operation FormatNumericToParts takes arguments numberFormat (an Intl.NumberFormat) and x (an
- Let parts be
PartitionNumberPattern (numberFormat, x). - Let result be !
ArrayCreate (0). - Let n be 0.
- For each
Record { [[Type]], [[Value]] } part of parts, do- Let O be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (O,"type" , part.[[Type]]). - Perform !
CreateDataPropertyOrThrow (O,"value" , part.[[Value]]). - Perform !
CreateDataPropertyOrThrow (result, !ToString (𝔽 (n)), O). - Increment n by 1.
- Let O be
- Return result.
16.5.8 ToRawPrecision ( x, minPrecision, maxPrecision, unsignedRoundingMode )
The abstract operation ToRawPrecision takes arguments x (a non-negative
It involves solving the following equation, which returns a valid
It performs the following steps when called:
- Let p be maxPrecision.
- If x = 0, then
- Let m be the String consisting of p occurrences of the code unit 0x0030 (DIGIT ZERO).
- Let e be 0.
- Let xFinal be 0.
- Else,
- Let n1 and e1 each be an
integer and r1 amathematical value , withr1 = , such thatToRawPrecisionFn (n1, e1, p)r1 ≤ x and r1 is maximized. - Let n2 and e2 each be an
integer and r2 amathematical value , withr2 = , such thatToRawPrecisionFn (n2, e2, p)r2 ≥ x and r2 is minimized. - Let xFinal be
ApplyUnsignedRoundingMode (x, r1, r2, unsignedRoundingMode). - If xFinal is r1, then
- Let n be n1.
- Let e be e1.
- Else,
- Let n be n2.
- Let e be e2.
- Let m be the String consisting of the digits of the decimal representation of n (in order, with no leading zeroes).
- Let n1 and e1 each be an
- If e ≥ (p - 1), then
- Set m to the
string-concatenation of m and e - p + 1 occurrences of the code unit 0x0030 (DIGIT ZERO). - Let int be e + 1.
- Set m to the
- Else if e ≥ 0, then
- Set m to the
string-concatenation of the first e + 1 code units of m, the code unit 0x002E (FULL STOP), and the remaining p - (e + 1) code units of m. - Let int be e + 1.
- Set m to the
- Else,
Assert : e < 0.- Set m to the
string-concatenation of"0." , -(e + 1) occurrences of the code unit 0x0030 (DIGIT ZERO), and m. - Let int be 1.
- If m contains the code unit 0x002E (FULL STOP) and maxPrecision > minPrecision, then
- Let cut be maxPrecision - minPrecision.
- Repeat, while cut > 0 and the last code unit of m is 0x0030 (DIGIT ZERO),
- Remove the last code unit from m.
- Set cut to cut - 1.
- If the last code unit of m is 0x002E (FULL STOP), then
- Remove the last code unit from m.
- Return the
Record { [[FormattedString]]: m, [[RoundedNumber]]: xFinal, [[IntegerDigitsCount]]: int, [[RoundingMagnitude]]: e–p+1 }.
16.5.9 ToRawFixed ( x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode )
The abstract operation ToRawFixed takes arguments x (a non-negative
It involves solving the following equation, which returns a valid
It performs the following steps when called:
- Let f be maxFraction.
- Let n1 be an
integer and r1 amathematical value , withr1 = , such thatToRawFixedFn (n1, f)n1 ,modulo roundingIncrement = 0r1 ≤ x , and r1 is maximized. - Let n2 be an
integer and r2 amathematical value , withr2 = , such thatToRawFixedFn (n2, f)n2 ,modulo roundingIncrement = 0r2 ≥ x , and r2 is minimized. - Let xFinal be
ApplyUnsignedRoundingMode (x, r1, r2, unsignedRoundingMode). - If xFinal is r1, let n be n1. Otherwise, let n be n2.
- If n = 0, let m be
"0" . Otherwise, let m be the String consisting of the digits of the decimal representation of n (in order, with no leading zeroes). - If f ≠ 0, then
- Let k be the length of m.
- If k ≤ f, then
- Let z be the String value consisting of f + 1 - k occurrences of the code unit 0x0030 (DIGIT ZERO).
- Set m to the
string-concatenation of z and m. - Set k to f + 1.
- Let a be the first k - f code units of m, and let b be the remaining f code units of m.
- Set m to the
string-concatenation of a,"." , and b. - Let int be the length of a.
- Else,
- Let int be the length of m.
- Let cut be maxFraction - minFraction.
- Repeat, while cut > 0 and the last code unit of m is 0x0030 (DIGIT ZERO),
- Remove the last code unit from m.
- Set cut to cut - 1.
- If the last code unit of m is 0x002E (FULL STOP), then
- Remove the last code unit from m.
- Return the
Record { [[FormattedString]]: m, [[RoundedNumber]]: xFinal, [[IntegerDigitsCount]]: int, [[RoundingMagnitude]]: –f }.
16.5.10 UnwrapNumberFormat ( nf )
The abstract operation UnwrapNumberFormat takes argument nf (an
- If nf
is not an Object , throw aTypeError exception. - If nf does not have an [[InitializedNumberFormat]] internal slot and ?
OrdinaryHasInstance (%Intl.NumberFormat% , nf) istrue , then - Return nf.
16.5.11 GetNumberFormatPattern ( numberFormat, x )
The abstract operation GetNumberFormatPattern takes arguments numberFormat (an Intl.NumberFormat) and x (an
- Let resolvedLocaleData be numberFormat.[[LocaleData]].
- Let patterns be resolvedLocaleData.[[patterns]].
Assert : patterns is aRecord (see16.2.3 ).- Let style be numberFormat.[[Style]].
- If style is
"percent" , then- Set patterns to patterns.[[percent]].
- Else if style is
"unit" , then- Let unit be numberFormat.[[Unit]].
- Let unitDisplay be numberFormat.[[UnitDisplay]].
- Set patterns to patterns.[[unit]].
- If patterns doesn't have a field [[<unit>]], then
- Set unit to
"fallback" .
- Set unit to
- Set patterns to patterns.[[<unit>]].
- Set patterns to patterns.[[<unitDisplay>]].
- Else if style is
"currency" , then- Let currency be numberFormat.[[Currency]].
- Let currencyDisplay be numberFormat.[[CurrencyDisplay]].
- Let currencySign be numberFormat.[[CurrencySign]].
- Set patterns to patterns.[[currency]].
- If patterns doesn't have a field [[<currency>]], then
- Set currency to
"fallback" .
- Set currency to
- Set patterns to patterns.[[<currency>]].
- Set patterns to patterns.[[<currencyDisplay>]].
- Set patterns to patterns.[[<currencySign>]].
- Else,
Assert : style is"decimal" .- Set patterns to patterns.[[decimal]].
- If x is
negative-infinity , then- Let category be
negative-non-zero .
- Let category be
- Else if x is
negative-zero , then- Let category be
negative-zero .
- Let category be
- Else if x is
not-a-number , then- Let category be
positive-zero .
- Let category be
- Else if x is
positive-infinity , then- Let category be
positive-non-zero .
- Let category be
- Else,
Assert : x is amathematical value .- If x < 0, then
- Let category be
negative-non-zero .
- Let category be
- Else if x > 0, then
- Let category be
positive-non-zero .
- Let category be
- Else,
- Let category be
positive-zero .
- Let category be
- Let signDisplay be numberFormat.[[SignDisplay]].
- If signDisplay is
"never" , then- Let pattern be patterns.[[zeroPattern]].
- Else if signDisplay is
"auto" , then- If category is
positive-non-zero orpositive-zero , then- Let pattern be patterns.[[zeroPattern]].
- Else,
- Let pattern be patterns.[[negativePattern]].
- If category is
- Else if signDisplay is
"always" , then- If category is
positive-non-zero orpositive-zero , then- Let pattern be patterns.[[positivePattern]].
- Else,
- Let pattern be patterns.[[negativePattern]].
- If category is
- Else if signDisplay is
"exceptZero" , then- If category is
positive-zero ornegative-zero , then- Let pattern be patterns.[[zeroPattern]].
- Else if category is
positive-non-zero , then- Let pattern be patterns.[[positivePattern]].
- Else,
- Let pattern be patterns.[[negativePattern]].
- If category is
- Else,
Assert : signDisplay is"negative" .- If category is
negative-non-zero , then- Let pattern be patterns.[[negativePattern]].
- Else,
- Let pattern be patterns.[[zeroPattern]].
- Return pattern.
16.5.12 GetNotationSubPattern ( numberFormat, exponent )
The abstract operation GetNotationSubPattern takes arguments numberFormat (an Intl.NumberFormat) and exponent (an
- Let resolvedLocaleData be numberFormat.[[LocaleData]].
- Let notationSubPatterns be resolvedLocaleData.[[notationSubPatterns]].
Assert : notationSubPatterns is aRecord (see16.2.3 ).- Let notation be numberFormat.[[Notation]].
- If notation is
"scientific" or notation is"engineering" , then- Return notationSubPatterns.[[scientific]].
- Else if exponent is not 0, then
Assert : notation is"compact" .- Let compactDisplay be numberFormat.[[CompactDisplay]].
- Let compactPatterns be notationSubPatterns.[[compact]].[[<compactDisplay>]].
- Return compactPatterns.[[<exponent>]].
- Else,
- Return
"{number}" .
- Return
16.5.13 ComputeExponent ( numberFormat, x )
The abstract operation ComputeExponent takes arguments numberFormat (an Intl.NumberFormat) and x (a
- If x = 0, then
- Return 0.
- If x < 0, then
- Let x = -x.
- Let magnitude be the base 10 logarithm of x rounded down to the nearest
integer . - Let exponent be
ComputeExponentForMagnitude (numberFormat, magnitude). - Let x be x × 10-exponent.
- Let formatNumberResult be
FormatNumericToString (numberFormat, x). - If formatNumberResult.[[RoundedNumber]] = 0, then
- Return exponent.
- Let newMagnitude be the base 10 logarithm of formatNumberResult.[[RoundedNumber]] rounded down to the nearest
integer . - If newMagnitude is magnitude - exponent, then
- Return exponent.
- Return
ComputeExponentForMagnitude (numberFormat, magnitude + 1).
16.5.14 ComputeExponentForMagnitude ( numberFormat, magnitude )
The abstract operation ComputeExponentForMagnitude takes arguments numberFormat (an Intl.NumberFormat) and magnitude (an
- Let notation be numberFormat.[[Notation]].
- If notation is
"standard" , then- Return 0.
- Else if notation is
"scientific" , then- Return magnitude.
- Else if notation is
"engineering" , then- Let thousands be the greatest
integer that is not greater than magnitude / 3. - Return thousands × 3.
- Let thousands be the greatest
- Else,
16.5.15 Runtime Semantics: StringIntlMV
The
The conversion of a
It is defined piecewise over the following productions:
- Return 0.
- Return
StringIntlMV ofStrNumericLiteral .
- Return MV of
NonDecimalIntegerLiteral .
- Let a be
StringIntlMV ofStrUnsignedDecimalLiteral . - If a is 0, return
negative-zero . - If a is
positive-infinity , returnnegative-infinity . - Return -a.
- Return
positive-infinity .
- Let a be MV of the first
DecimalDigits . - If the second
DecimalDigits is present, then- Let b be MV of the second
DecimalDigits . - Let n be the number of code points in the second
DecimalDigits .
- Let b be MV of the second
- Else,
- Let b be 0.
- Let n be 0.
- If
ExponentPart is present, let e be MV ofExponentPart . Otherwise, let e be 0. - Return (a + (b × 10-n)) × 10e.
- Let b be MV of
DecimalDigits . - If
ExponentPart is present, let e be MV ofExponentPart . Otherwise, let e be 0. - Let n be the number of code points in
DecimalDigits . - Return b × 10e - n.
- Let a be MV of
DecimalDigits . - If
ExponentPart is present, let e be MV ofExponentPart . Otherwise, let e be 0. - Return a × 10e.
16.5.16 ToIntlMathematicalValue ( value )
The abstract operation ToIntlMathematicalValue takes argument value (an
- Let primValue be ?
ToPrimitive (value,number ). - If primValue
is a BigInt , returnℝ (primValue). - If primValue
is a String , then- Let str be primValue.
- Else,
- Let x be ?
ToNumber (primValue). - If x is
-0 𝔽, returnnegative-zero . - Let str be
Number::toString (x, 10).
- Let x be ?
- Let text be
StringToCodePoints (str). - Let literal be
ParseText (text,StringNumericLiteral ). - If literal is a
List of errors, returnnot-a-number . - Let intlMV be the
StringIntlMV of literal. - If intlMV is a
mathematical value , then- Let rounded be
RoundMVResult (abs (intlMV)). - If rounded is
+∞ 𝔽 and intlMV < 0, returnnegative-infinity . - If rounded is
+∞ 𝔽, returnpositive-infinity . - If rounded is
+0 𝔽 and intlMV < 0, returnnegative-zero . - If rounded is
+0 𝔽, return 0.
- Let rounded be
- Return intlMV.
16.5.17 GetUnsignedRoundingMode ( roundingMode, sign )
The abstract operation GetUnsignedRoundingMode takes arguments roundingMode (a
- Return the specification type in the Unsigned Rounding Mode column of
Table 29 for the row where the value in the Identifier column is roundingMode and the value in the Sign column is sign.
Identifier | Sign | Unsigned Rounding Mode |
---|---|---|
16.5.18 ApplyUnsignedRoundingMode ( x, r1, r2, unsignedRoundingMode )
The abstract operation ApplyUnsignedRoundingMode takes arguments x (a
- If x is r1, return r1.
Assert : r1 < x < r2.Assert : unsignedRoundingMode is notundefined .- If unsignedRoundingMode is
zero , return r1. - If unsignedRoundingMode is
infinity , return r2. - Let d1 be
x – r1 . - Let d2 be
r2 – x . - If d1 < d2, return r1.
- If d2 < d1, return r2.
Assert : d1 is d2.- If unsignedRoundingMode is
half-zero , return r1. - If unsignedRoundingMode is
half-infinity , return r2. Assert : unsignedRoundingMode ishalf-even .- Let cardinality be
(r1 / (r2 – r1)) .modulo 2 - If cardinality is 0, return r1.
- Return r2.
16.5.19 PartitionNumberRangePattern ( numberFormat, x, y )
The abstract operation PartitionNumberRangePattern takes arguments numberFormat (an Intl.NumberFormat), x (an
- If x is
not-a-number or y isnot-a-number , throw aRangeError exception. - Let xResult be
PartitionNumberPattern (numberFormat, x). - Let yResult be
PartitionNumberPattern (numberFormat, y). - If
FormatNumeric (numberFormat, x) isFormatNumeric (numberFormat, y), then- Let appxResult be
FormatApproximately (numberFormat, xResult). - For each element r of appxResult, do
- Set r.[[Source]] to
"shared" .
- Set r.[[Source]] to
- Return appxResult.
- Let appxResult be
- Let result be a new empty
List . - For each element r of xResult, do
- Append the
Record { [[Type]]: r.[[Type]], [[Value]]: r.[[Value]], [[Source]]:"startRange" } to result.
- Append the
- Let rangeSeparator be an
ILND String value used to separate two numbers. - Append the
Record { [[Type]]:"literal" , [[Value]]: rangeSeparator, [[Source]]:"shared" } to result. - For each element r of yResult, do
- Append the
Record { [[Type]]: r.[[Type]], [[Value]]: r.[[Value]], [[Source]]:"endRange" } to result.
- Append the
- Return
CollapseNumberRange (numberFormat, result).
16.5.20 FormatApproximately ( numberFormat, result )
The abstract operation FormatApproximately takes arguments numberFormat (an Intl.NumberFormat) and result (a
- Let approximatelySign be an
ILND String value used to signify that a number is approximate. - If approximatelySign is not empty, insert the
Record { [[Type]]:"approximatelySign" , [[Value]]: approximatelySign } at anILND index in result. For example, if numberFormat has [[Locale]]"en-US" and [[NumberingSystem]]"latn" and [[Style]]"decimal" , the newRecord might be inserted before the first element of result. - Return result.
16.5.21 CollapseNumberRange ( numberFormat, result )
The
For example, an implementation may remove the
An implementation may also modify
Returning result unmodified is guaranteed to be a correct implementation of CollapseNumberRange.
16.5.22 FormatNumericRange ( numberFormat, x, y )
The abstract operation FormatNumericRange takes arguments numberFormat (an Intl.NumberFormat), x (an
- Let parts be ?
PartitionNumberRangePattern (numberFormat, x, y). - Let result be the empty String.
- For each element part of parts, do
- Set result to the
string-concatenation of result and part.[[Value]].
- Set result to the
- Return result.
16.5.23 FormatNumericRangeToParts ( numberFormat, x, y )
The abstract operation FormatNumericRangeToParts takes arguments numberFormat (an Intl.NumberFormat), x (an
- Let parts be ?
PartitionNumberRangePattern (numberFormat, x, y). - Let result be !
ArrayCreate (0). - Let n be 0.
- For each element part of parts, do
- Let O be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (O,"type" , part.[[Type]]). - Perform !
CreateDataPropertyOrThrow (O,"value" , part.[[Value]]). - Perform !
CreateDataPropertyOrThrow (O,"source" , part.[[Source]]). - Perform !
CreateDataPropertyOrThrow (result, !ToString (𝔽 (n)), O). - Increment n by 1.
- Let O be
- Return result.
17 PluralRules Objects
17.1 The Intl.PluralRules Constructor
The Intl.PluralRules
- is %Intl.PluralRules%.
- is the initial value of the
"PluralRules" property of theIntl object .
Behaviour common to all
17.1.1 Intl.PluralRules ( [ locales [ , options ] ] )
When the Intl.PluralRules
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - Let pluralRules be ?
OrdinaryCreateFromConstructor (NewTarget,"%Intl.PluralRules.prototype%" , « [[InitializedPluralRules]], [[Locale]], [[Type]], [[Notation]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[RoundingIncrement]], [[RoundingMode]], [[ComputedRoundingPriority]], [[TrailingZeroDisplay]] »). - Let optionsResolution be ?
ResolveOptions (%Intl.PluralRules% ,%Intl.PluralRules% .[[LocaleData]], locales, options, «coerce-options »). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Set pluralRules.[[Locale]] to r.[[Locale]].
- Let t be ?
GetOption (options,"type" ,string , «"cardinal" ,"ordinal" »,"cardinal" ). - Set pluralRules.[[Type]] to t.
- Let notation be ?
GetOption (options,"notation" ,string , «"standard" ,"scientific" ,"engineering" ,"compact" »,"standard" ). - Set pluralRules.[[Notation]] to notation.
- Perform ?
SetNumberFormatDigitOptions (pluralRules, options, 0, 3, notation). - Return pluralRules.
17.2 Properties of the Intl.PluralRules Constructor
The Intl.PluralRules
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
17.2.1 Intl.PluralRules.prototype
The value of Intl.PluralRules.prototype
is
This property has the attributes { [[Writable]]:
17.2.2 Intl.PluralRules.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.PluralRules% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
17.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[RelevantExtensionKeys]] internal slot is « ».
The value of the [[ResolutionOptionDescriptors]] internal slot is « ».
The value of the [[LocaleData]] internal slot is
17.3 Properties of the Intl.PluralRules Prototype Object
The Intl.PluralRules prototype object:
- is %Intl.PluralRules.prototype%.
- is an
ordinary object . - is not an Intl.PluralRules instance and does not have an [[InitializedPluralRules]] internal slot or any of the other internal slots of Intl.PluralRules instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
17.3.1 Intl.PluralRules.prototype.constructor
The initial value of Intl.PluralRules.prototype.constructor
is
17.3.2 Intl.PluralRules.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let pr be the
this value. - Perform ?
RequireInternalSlot (pr, [[InitializedPluralRules]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - Let pluralCategories be a
List of Strings containing all possible results ofPluralRuleSelect for the selected locale pr.[[Locale]], sorted according to the following order:"zero" ,"one" ,"two" ,"few" ,"many" ,"other" . - For each row of
Table 30 , except the header row, in table order, do- Let p be the Property value of the current row.
- If p is
"pluralCategories" , then- Let v be
CreateArrayFromList (pluralCategories).
- Let v be
- Else,
- Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row.
- If v is not
undefined , then- If there is a Conversion value in the current row, then
- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Return options.
Internal Slot | Property | Conversion |
---|---|---|
[[Locale]] | ||
[[Type]] | ||
[[Notation]] | ||
[[MinimumIntegerDigits]] | ||
[[MinimumFractionDigits]] | ||
[[MaximumFractionDigits]] | ||
[[MinimumSignificantDigits]] | ||
[[MaximumSignificantDigits]] | ||
[[RoundingIncrement]] | ||
[[RoundingMode]] | ||
[[ComputedRoundingPriority]] | ||
[[TrailingZeroDisplay]] |
17.3.3 Intl.PluralRules.prototype.select ( value )
When the select
method is called with an argument value, the following steps are taken:
- Let pr be the
this value. - Perform ?
RequireInternalSlot (pr, [[InitializedPluralRules]]). - Let n be ?
ToNumber (value). - Return
ResolvePlural (pr, n).[[PluralCategory]].
17.3.4 Intl.PluralRules.prototype.selectRange ( start, end )
When the selectRange
method is called with arguments start and end, the following steps are taken:
- Let pr be the
this value. - Perform ?
RequireInternalSlot (pr, [[InitializedPluralRules]]). - If start is
undefined or end isundefined , throw aTypeError exception. - Let x be ?
ToNumber (start). - Let y be ?
ToNumber (end). - Return ?
ResolvePluralRange (pr, x, y).
17.3.5 Intl.PluralRules.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
17.4 Properties of Intl.PluralRules Instances
Intl.PluralRules instances are
Intl.PluralRules instances have an [[InitializedPluralRules]] internal slot.
Intl.PluralRules instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used by the plural rules. - [[Type]] is one of the String values
"cardinal" or"ordinal" , identifying the plural rules used. - [[Notation]] is one of the String values
"standard" ,"scientific" ,"engineering" , or"compact" , identifying the notation used. - [[MinimumIntegerDigits]] is a non-negative
integer indicating the minimuminteger digits to be used. - [[MinimumFractionDigits]] and [[MaximumFractionDigits]] are non-negative
integers indicating the minimum and maximum fraction digits to be used. Numbers will be rounded or padded with trailing zeroes if necessary. - [[MinimumSignificantDigits]] and [[MaximumSignificantDigits]] are positive
integers indicating the minimum and maximum fraction digits to be used. Either none or both of these properties are present; if they are, they override minimum and maximuminteger and fraction digits. - [[RoundingType]] is one of the values
fraction-digits ,significant-digits ,more-precision , orless-precision , indicating which rounding strategy to use, as discussed in16.4 . - [[ComputedRoundingPriority]] is one of the String values
"auto" ,"morePrecision" , or"lessPrecision" . It is only used in17.3.2 to convert [[RoundingType]] back to a valid"roundingPriority" option. - [[RoundingIncrement]] is an
integer that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then formatted numbers are rounded to the nearest 0.05 ("nickel rounding"). - [[RoundingMode]] identifies the
rounding mode to use. - [[TrailingZeroDisplay]] is one of the String values
"auto" or"stripIfInteger" , indicating whether to strip trailing zeros if the formatted number is aninteger (i.e., has no non-zero fraction digit).
17.5 Abstract Operations for PluralRules Objects
17.5.1 PluralRuleSelect ( locale, type, notation, s )
The
17.5.2 ResolvePlural ( pluralRules, n )
The abstract operation ResolvePlural takes arguments pluralRules (an Intl.PluralRules) and n (a Number) and returns a
- If n is not a
finite Number, then - Let res be
FormatNumericToString (pluralRules,ℝ (n)). - Let s be res.[[FormattedString]].
- Let locale be pluralRules.[[Locale]].
- Let type be pluralRules.[[Type]].
- Let notation be pluralRules.[[Notation]].
- Let p be
PluralRuleSelect (locale, type, notation, s). - Return the
Record { [[PluralCategory]]: p, [[FormattedString]]: s }.
17.5.3 PluralRuleSelectRange ( locale, type, notation, xp, yp )
The
17.5.4 ResolvePluralRange ( pluralRules, x, y )
The abstract operation ResolvePluralRange takes arguments pluralRules (an Intl.PluralRules), x (a Number), and y (a Number) and returns either a
- If x is
NaN or y isNaN , throw aRangeError exception. - Let xp be
ResolvePlural (pluralRules, x). - Let yp be
ResolvePlural (pluralRules, y). - If xp.[[FormattedString]] is yp.[[FormattedString]], then
- Return xp.[[PluralCategory]].
- Let locale be pluralRules.[[Locale]].
- Let type be pluralRules.[[Type]].
- Let notation be pluralRules.[[Notation]].
- Return
PluralRuleSelectRange (locale, type, notation, xp.[[PluralCategory]], yp.[[PluralCategory]]).
18 RelativeTimeFormat Objects
18.1 The Intl.RelativeTimeFormat Constructor
The Intl.RelativeTimeFormat
- is %Intl.RelativeTimeFormat%.
- is the initial value of the
"RelativeTimeFormat" property of theIntl object .
Behaviour common to all
18.1.1 Intl.RelativeTimeFormat ( [ locales [ , options ] ] )
When the Intl.RelativeTimeFormat
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - Let relativeTimeFormat be ?
OrdinaryCreateFromConstructor (NewTarget,"%Intl.RelativeTimeFormat.prototype%" , « [[InitializedRelativeTimeFormat]], [[Locale]], [[LocaleData]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). - Let optionsResolution be ?
ResolveOptions (%Intl.RelativeTimeFormat% ,%Intl.RelativeTimeFormat% .[[LocaleData]], locales, options, «coerce-options »). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Let locale be r.[[Locale]].
- Set relativeTimeFormat.[[Locale]] to locale.
- Set relativeTimeFormat.[[LocaleData]] to r.[[LocaleData]].
- Set relativeTimeFormat.[[NumberingSystem]] to r.[[nu]].
- Let style be ?
GetOption (options,"style" ,string , «"long" ,"short" ,"narrow" »,"long" ). - Set relativeTimeFormat.[[Style]] to style.
- Let numeric be ?
GetOption (options,"numeric" ,string , «"always" ,"auto" »,"always" ). - Set relativeTimeFormat.[[Numeric]] to numeric.
- Let nfOptions be
OrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (nfOptions,"numberingSystem" , relativeTimeFormat.[[NumberingSystem]]). - Let relativeTimeFormat.[[NumberFormat]] be !
Construct (%Intl.NumberFormat% , « locale, nfOptions »). - Let relativeTimeFormat.[[PluralRules]] be !
Construct (%Intl.PluralRules% , « locale »). - Return relativeTimeFormat.
18.2 Properties of the Intl.RelativeTimeFormat Constructor
The Intl.RelativeTimeFormat
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
18.2.1 Intl.RelativeTimeFormat.prototype
The value of Intl.RelativeTimeFormat.prototype
is
This property has the attributes { [[Writable]]:
18.2.2 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.RelativeTimeFormat% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
18.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[RelevantExtensionKeys]] internal slot is «
The value of the [[ResolutionOptionDescriptors]] internal slot is « { [[Key]]:
The value of the [[LocaleData]] internal slot is
- [[LocaleData]].[[<locale>]] has fields
"second" ,"minute" ,"hour" ,"day" ,"week" ,"month" ,"quarter" , and"year" . Additional fields may exist with the previous names concatenated with the strings"-narrow" or"-short" . The values corresponding to these fields areRecords which contain these two categories of fields:"future" and"past" fields, which areRecords with a field for each of the plural categories relevant for locale. The value corresponding to those fields is a pattern which may contain"{0}" to be replaced by a formatted number.- Optionally, additional fields whose key is the result of
ToString of a Number, and whose values are literal Strings which are not treated as templates.
-
The
List that is the value of the"nu" field of any locale field of [[LocaleData]] must not include the values"native" ,"traditio" , or"finance" .
18.3 Properties of the Intl.RelativeTimeFormat Prototype Object
The Intl.RelativeTimeFormat prototype object:
- is %Intl.RelativeTimeFormat.prototype%.
- is an
ordinary object . - is not an Intl.RelativeTimeFormat instance and does not have an [[InitializedRelativeTimeFormat]] internal slot or any of the other internal slots of Intl.RelativeTimeFormat instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
18.3.1 Intl.RelativeTimeFormat.prototype.constructor
The initial value of Intl.RelativeTimeFormat.prototype.constructor
is
18.3.2 Intl.RelativeTimeFormat.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let relativeTimeFormat be the
this value. - Perform ?
RequireInternalSlot (relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 31 , except the header row, in table order, do- Let p be the Property value of the current row.
- Let v be the value of relativeTimeFormat's internal slot whose name is the Internal Slot value of the current row.
Assert : v is notundefined .- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Return options.
Internal Slot | Property |
---|---|
[[Locale]] | |
[[Style]] | |
[[Numeric]] | |
[[NumberingSystem]] |
18.3.3 Intl.RelativeTimeFormat.prototype.format ( value, unit )
When the format
method is called with arguments value and unit, the following steps are taken:
- Let relativeTimeFormat be the
this value. - Perform ?
RequireInternalSlot (relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - Let value be ?
ToNumber (value). - Let unit be ?
ToString (unit). - Return ?
FormatRelativeTime (relativeTimeFormat, value, unit).
18.3.4 Intl.RelativeTimeFormat.prototype.formatToParts ( value, unit )
When the formatToParts
method is called with arguments value and unit, the following steps are taken:
- Let relativeTimeFormat be the
this value. - Perform ?
RequireInternalSlot (relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - Let value be ?
ToNumber (value). - Let unit be ?
ToString (unit). - Return ?
FormatRelativeTimeToParts (relativeTimeFormat, value, unit).
18.3.5 Intl.RelativeTimeFormat.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
18.4 Properties of Intl.RelativeTimeFormat Instances
Intl.RelativeTimeFormat instances are
Intl.RelativeTimeFormat instances have an [[InitializedRelativeTimeFormat]] internal slot.
Intl.RelativeTimeFormat instances also have several internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for formatting. - [[LocaleData]] is a
Record representing the data available to the implementation for formatting. It is the value of an entry in%Intl.RelativeTimeFormat% .[[LocaleData]] associated with either the value of [[Locale]] or a prefix thereof. - [[Style]] is one of the String values
"long" ,"short" , or"narrow" , identifying the relative time format style used. - [[Numeric]] is one of the String values
"always" or"auto" , identifying whether numerical descriptions are always used, or used only when no more specific version is available (e.g., "1 day ago" vs "yesterday"). - [[NumberFormat]] is an Intl.NumberFormat object used for formatting.
- [[NumberingSystem]]
is a String value representing the Unicode Number System Identifier used for formatting. - [[PluralRules]] is an Intl.PluralRules object used for formatting.
18.5 Abstract Operations for RelativeTimeFormat Objects
18.5.1 SingularRelativeTimeUnit ( unit )
The abstract operation SingularRelativeTimeUnit takes argument unit (a String) and returns either a
- If unit is
"seconds" , return"second" . - If unit is
"minutes" , return"minute" . - If unit is
"hours" , return"hour" . - If unit is
"days" , return"day" . - If unit is
"weeks" , return"week" . - If unit is
"months" , return"month" . - If unit is
"quarters" , return"quarter" . - If unit is
"years" , return"year" . - If unit is not one of
"second" ,"minute" ,"hour" ,"day" ,"week" ,"month" ,"quarter" , or"year" , throw aRangeError exception. - Return unit.
18.5.2 PartitionRelativeTimePattern ( relativeTimeFormat, value, unit )
The abstract operation PartitionRelativeTimePattern takes arguments relativeTimeFormat (an Intl.RelativeTimeFormat), value (a Number), and unit (a String) and returns either a
- If value is
NaN ,+∞ 𝔽, or-∞ 𝔽, throw aRangeError exception. - Let unit be ?
SingularRelativeTimeUnit (unit). - Let fields be relativeTimeFormat.[[LocaleData]].
- Let patterns be fields.[[<unit>]].
- Let style be relativeTimeFormat.[[Style]].
- If style is
"short" or"narrow" , then- Let key be the
string-concatenation of unit,"-" , and style. - If fields has a field [[<key>]], set patterns to fields.[[<key>]].
- Let key be the
- If relativeTimeFormat.[[Numeric]] is
"auto" , then - If value is
-0 𝔽 or value <-0 𝔽, then- Let tl be
"past" .
- Let tl be
- Else,
- Let tl be
"future" .
- Let tl be
- Let po be patterns.[[<tl>]].
- Let fv be
PartitionNumberPattern (relativeTimeFormat.[[NumberFormat]],ℝ (value)). - Let pr be
ResolvePlural (relativeTimeFormat.[[PluralRules]], value).[[PluralCategory]]. - Let pattern be po.[[<pr>]].
- Return
MakePartsList (pattern, unit, fv).
18.5.3 MakePartsList ( pattern, unit, parts )
The abstract operation MakePartsList takes arguments pattern (a
- Let patternParts be
PartitionPattern (pattern). - Let result be a new empty
List . - For each
Record { [[Type]], [[Value]] } patternPart of patternParts, do- If patternPart.[[Type]] is
"literal" , then- Append the
Record { [[Type]]:"literal" , [[Value]]: patternPart.[[Value]], [[Unit]]:empty } to result.
- Append the
- Else,
- If patternPart.[[Type]] is
- Return result.
- Return
MakePartsList ("AA{0}BB" ,"hour" , «Record { [[Type]]:"integer" , [[Value]]:"15" } »).
18.5.4 FormatRelativeTime ( relativeTimeFormat, value, unit )
The abstract operation FormatRelativeTime takes arguments relativeTimeFormat (an Intl.RelativeTimeFormat), value (a Number), and unit (a String) and returns either a
- Let parts be ?
PartitionRelativeTimePattern (relativeTimeFormat, value, unit). - Let result be the empty String.
- For each
Record { [[Type]], [[Value]], [[Unit]] } part of parts, do- Set result to the
string-concatenation of result and part.[[Value]].
- Set result to the
- Return result.
18.5.5 FormatRelativeTimeToParts ( relativeTimeFormat, value, unit )
The abstract operation FormatRelativeTimeToParts takes arguments relativeTimeFormat (an Intl.RelativeTimeFormat), value (a Number), and unit (a String) and returns either a
- Let parts be ?
PartitionRelativeTimePattern (relativeTimeFormat, value, unit). - Let result be !
ArrayCreate (0). - Let n be 0.
- For each
Record { [[Type]], [[Value]], [[Unit]] } part of parts, do- Let O be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (O,"type" , part.[[Type]]). - Perform !
CreateDataPropertyOrThrow (O,"value" , part.[[Value]]). - If part.[[Unit]] is not
empty , then- Perform !
CreateDataPropertyOrThrow (O,"unit" , part.[[Unit]]).
- Perform !
- Perform !
CreateDataPropertyOrThrow (result, !ToString (𝔽 (n)), O). - Increment n by 1.
- Let O be
- Return result.
19 Segmenter Objects
19.1 The Intl.Segmenter Constructor
The Intl.Segmenter
- is %Intl.Segmenter%.
- is the initial value of the
"Segmenter" property of theIntl object .
Behaviour common to all
19.1.1 Intl.Segmenter ( [ locales [ , options ] ] )
When the Intl.Segmenter
function is called with optional arguments locales and options, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - Let internalSlotsList be « [[InitializedSegmenter]], [[Locale]], [[SegmenterGranularity]] ».
- Let segmenter be ?
OrdinaryCreateFromConstructor (NewTarget,"%Intl.Segmenter.prototype%" , internalSlotsList). - Let optionsResolution be ?
ResolveOptions (%Intl.Segmenter% ,%Intl.Segmenter% .[[LocaleData]], locales, options). - Set options to optionsResolution.[[Options]].
- Let r be optionsResolution.[[ResolvedLocale]].
- Set segmenter.[[Locale]] to r.[[Locale]].
- Let granularity be ?
GetOption (options,"granularity" ,string , «"grapheme" ,"word" ,"sentence" »,"grapheme" ). - Set segmenter.[[SegmenterGranularity]] to granularity.
- Return segmenter.
19.2 Properties of the Intl.Segmenter Constructor
The Intl.Segmenter
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
19.2.1 Intl.Segmenter.prototype
The value of Intl.Segmenter.prototype
is
This property has the attributes { [[Writable]]:
19.2.2 Intl.Segmenter.supportedLocalesOf ( locales [ , options ] )
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
- Let availableLocales be
%Intl.Segmenter% .[[AvailableLocales]]. - Let requestedLocales be ?
CanonicalizeLocaleList (locales). - Return ?
FilterLocales (availableLocales, requestedLocales, options).
19.2.3 Internal slots
The value of the [[AvailableLocales]] internal slot is
The value of the [[RelevantExtensionKeys]] internal slot is « ».
The value of the [[ResolutionOptionDescriptors]] internal slot is « ».
The value of the [[LocaleData]] internal slot is
19.3 Properties of the Intl.Segmenter Prototype Object
The Intl.Segmenter prototype object:
- is %Intl.Segmenter.prototype%.
- is an
ordinary object . - is not an Intl.Segmenter instance and does not have an [[InitializedSegmenter]] internal slot or any of the other internal slots of Intl.Segmenter instance objects.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
19.3.1 Intl.Segmenter.prototype.constructor
The initial value of Intl.Segmenter.prototype.constructor
is
19.3.2 Intl.Segmenter.prototype.resolvedOptions ( )
This function provides access to the locale and options computed during initialization of the object.
- Let segmenter be the
this value. - Perform ?
RequireInternalSlot (segmenter, [[InitializedSegmenter]]). - Let options be
OrdinaryObjectCreate (%Object.prototype% ). - For each row of
Table 32 , except the header row, in table order, do- Let p be the Property value of the current row.
- Let v be the value of segmenter's internal slot whose name is the Internal Slot value of the current row.
Assert : v is notundefined .- Perform !
CreateDataPropertyOrThrow (options, p, v).
- Return options.
Internal Slot | Property |
---|---|
[[Locale]] | |
[[SegmenterGranularity]] |
19.3.3 Intl.Segmenter.prototype.segment ( string )
The Intl.Segmenter.prototype.segment
method is called on an Intl.Segmenter instance with argument string to create a
- Let segmenter be the
this value. - Perform ?
RequireInternalSlot (segmenter, [[InitializedSegmenter]]). - Let string be ?
ToString (string). - Return
CreateSegmentsObject (segmenter, string).
19.3.4 Intl.Segmenter.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
19.4 Properties of Intl.Segmenter Instances
Intl.Segmenter instances are
Intl.Segmenter instances have an [[InitializedSegmenter]] internal slot.
Intl.Segmenter instances also have internal slots that are computed by
- [[Locale]]
is a String value with thelanguage tag of the locale whose localization is used for segmentation. - [[SegmenterGranularity]] is one of the String values
"grapheme" ,"word" , or"sentence" , identifying the kind of text element to segment.
19.5 Segments Objects
A Segments instance is an object that represents the segments of a specific string, subject to the locale and options of its constructing Intl.Segmenter instance.
19.5.1 CreateSegmentsObject ( segmenter, string )
The abstract operation CreateSegmentsObject takes arguments segmenter (an Intl.Segmenter) and string (a String) and returns a
- Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
- Let segments be
OrdinaryObjectCreate (%IntlSegmentsPrototype% , internalSlotsList). - Set segments.[[SegmentsSegmenter]] to segmenter.
- Set segments.[[SegmentsString]] to string.
- Return segments.
19.5.2 The %IntlSegmentsPrototype% Object
The %IntlSegmentsPrototype% object:
- is the prototype of all Segments objects.
- is an
ordinary object . - has a [[Prototype]] internal slot whose value is
%Object.prototype% . - has the following properties:
19.5.2.1 %IntlSegmentsPrototype%.containing ( index )
The containing
method is called on a
- Let segments be the
this value. - Perform ?
RequireInternalSlot (segments, [[SegmentsSegmenter]]). - Let segmenter be segments.[[SegmentsSegmenter]].
- Let string be segments.[[SegmentsString]].
- Let len be the length of string.
- Let n be ?
ToIntegerOrInfinity (index). - If n < 0 or n ≥ len, return
undefined . - Let startIndex be
FindBoundary (segmenter, string, n,before ). - Let endIndex be
FindBoundary (segmenter, string, n,after ). - Return
CreateSegmentDataObject (segmenter, string, startIndex, endIndex).
19.5.2.2 %IntlSegmentsPrototype% [ %Symbol.iterator% ] ( )
The %Symbol.iterator%
method is called on a
- Let segments be the
this value. - Perform ?
RequireInternalSlot (segments, [[SegmentsSegmenter]]). - Let segmenter be segments.[[SegmentsSegmenter]].
- Let string be segments.[[SegmentsString]].
- Return
CreateSegmentIterator (segmenter, string).
The value of the
19.5.3 Properties of Segments Instances
Segments instances are
Segments instances have a [[SegmentsSegmenter]] internal slot that references the constructing Intl.Segmenter instance.
Segments instances have a [[SegmentsString]] internal slot that references the String value whose segments they expose.
19.6 Segment Iterator Objects
A Segment Iterator is an object that represents a particular iteration over the segments of a specific string.
19.6.1 CreateSegmentIterator ( segmenter, string )
The abstract operation CreateSegmentIterator takes arguments segmenter (an Intl.Segmenter) and string (a String) and returns a
- Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ».
- Let iterator be
OrdinaryObjectCreate (%IntlSegmentIteratorPrototype% , internalSlotsList). - Set iterator.[[IteratingSegmenter]] to segmenter.
- Set iterator.[[IteratedString]] to string.
- Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
- Return iterator.
19.6.2 The %IntlSegmentIteratorPrototype% Object
The %IntlSegmentIteratorPrototype% object:
- is the prototype of all
Segment Iterator objects. - is an
ordinary object . - has a [[Prototype]] internal slot whose value is
%Iterator.prototype% . - has the following properties:
19.6.2.1 %IntlSegmentIteratorPrototype%.next ( )
The next
method is called on a
- Let iterator be the
this value. - Perform ?
RequireInternalSlot (iterator, [[IteratingSegmenter]]). - Let segmenter be iterator.[[IteratingSegmenter]].
- Let string be iterator.[[IteratedString]].
- Let startIndex be iterator.[[IteratedStringNextSegmentCodeUnitIndex]].
- Let len be the length of string.
- If startIndex ≥ len, then
- Return
CreateIteratorResultObject (undefined ,true ).
- Return
- Let endIndex be
FindBoundary (segmenter, string, startIndex,after ). - Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to endIndex.
- Let segmentData be
CreateSegmentDataObject (segmenter, string, startIndex, endIndex). - Return
CreateIteratorResultObject (segmentData,false ).
19.6.2.2 %IntlSegmentIteratorPrototype% [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
19.6.3 Properties of Segment Iterator Instances
Internal Slot | Description |
---|---|
[[IteratingSegmenter]] | The Intl.Segmenter instance used for iteration. |
[[IteratedString]] | The String value being iterated upon. |
[[IteratedStringNextSegmentCodeUnitIndex]] | The code unit index in the String value being iterated upon at the start of the next segment. |
19.7 Segment Data Objects
A Segment Data object is an object that represents a particular segment from a string.
19.7.1 CreateSegmentDataObject ( segmenter, string, startIndex, endIndex )
The abstract operation CreateSegmentDataObject takes arguments segmenter (an Intl.Segmenter), string (a String), startIndex (a non-negative
- Let len be the length of string.
Assert : endIndex ≤ len.Assert : startIndex < endIndex.- Let result be
OrdinaryObjectCreate (%Object.prototype% ). - Let segment be the
substring of string from startIndex to endIndex. - Perform !
CreateDataPropertyOrThrow (result,"segment" , segment). - Perform !
CreateDataPropertyOrThrow (result,"index" ,𝔽 (startIndex)). - Perform !
CreateDataPropertyOrThrow (result,"input" , string). - Let granularity be segmenter.[[SegmenterGranularity]].
- If granularity is
"word"
, then- Let isWordLike be a Boolean value indicating whether the segment in string is "word-like" according to locale segmenter.[[Locale]].
- Perform !
CreateDataPropertyOrThrow (result,"isWordLike" , isWordLike).
- Return result.
19.8 Abstract Operations for Segmenter Objects
19.8.1 FindBoundary ( segmenter, string, startIndex, direction )
The abstract operation FindBoundary takes arguments segmenter (an Intl.Segmenter), string (a String), startIndex (a non-negative
- Let len be the length of string.
Assert : startIndex < len.- Let locale be segmenter.[[Locale]].
- Let granularity be segmenter.[[SegmenterGranularity]].
- If direction is
before , then- Search string for the last segmentation boundary that is preceded by at most startIndex code units from the beginning, using locale locale and text element granularity granularity.
- If a boundary is found, return the count of code units in string preceding it.
- Return 0.
Assert : direction isafter .- Search string for the first segmentation boundary that follows the code unit at index startIndex, using locale locale and text element granularity granularity.
- If a boundary is found, return the count of code units in string preceding it.
- Return len.
20 Locale Sensitive Functions of the ECMAScript Language Specification
20.1 Properties of the String Prototype Object
20.1.1 String.prototype.localeCompare ( that [ , locales [ , options ] ] )
This definition supersedes the definition provided in
When the localeCompare
method is called with argument that and optional arguments locales, and options, the following steps are taken:
- Let O be ?
RequireObjectCoercible (this value). - Let S be ?
ToString (O). - Let thatValue be ?
ToString (that). - Let collator be ?
Construct (%Intl.Collator% , « locales, options »). - Return
CompareStrings (collator, S, thatValue).
The
localeCompare
method itself is not directly suitable as an argument to Array.prototype.sort
because the latter requires a function of two arguments.
localeCompare
function is intentionally generic; it does not require that its 20.1.2 String.prototype.toLocaleLowerCase ( [ locales ] )
This definition supersedes the definition provided in
This function interprets a String value as a sequence of code points, as described in
- Let O be ?
RequireObjectCoercible (this value). - Let S be ?
ToString (O). - Return ?
TransformCase (S, locales,lower ).
toLocaleLowerCase
function is intentionally generic; it does not require that its 20.1.2.1 TransformCase ( S, locales, targetCase )
The abstract operation TransformCase takes arguments S (a String), locales (an
- Let requestedLocales be ?
CanonicalizeLocaleList (locales). - If requestedLocales is not an empty
List , then- Let requestedLocale be requestedLocales[0].
- Else,
- Let requestedLocale be
DefaultLocale ().
- Let requestedLocale be
- Let availableLocales be an
Available Locales List which includes thelanguage tags for which the Unicode Character Database contains language-sensitive case mappings. If the implementation supports additional locale-sensitive case mappings, availableLocales should also include their correspondinglanguage tags . - Let match be
LookupMatchingLocaleByPrefix (availableLocales, « requestedLocale »). - If match is not
undefined , let locale be match.[[locale]]; else let locale be"und" . - Let codePoints be
StringToCodePoints (S). - If targetCase is
lower , then- Let newCodePoints be a
List whose elements are the result of a lowercase transformation of codePoints according to an implementation-derived algorithm using locale or the Unicode Default Case Conversion algorithm.
- Let newCodePoints be a
- Else,
- Return
CodePointsToString (newCodePoints).
Code point mappings may be derived according to a tailored version of the Default Case Conversion Algorithms of the Unicode Standard. Implementations may use locale-sensitive tailoring defined in the file SpecialCasing.txt
of the Unicode Character Database and/or CLDR and/or any other custom tailoring. Regardless of tailoring, a conforming implementation's case transformation algorithm must always yield the same result given the same input code points, locale, and target case.
toLocaleUpperCase
and toLocaleLowerCase
have context-sensitive behaviour, the functions are not symmetrical. In other words, s.toLocaleUpperCase().toLocaleLowerCase()
is not necessarily equal to s.toLocaleLowerCase()
and s.toLocaleLowerCase().toLocaleUpperCase()
is not necessarily equal to s.toLocaleUpperCase()
.
20.1.3 String.prototype.toLocaleUpperCase ( [ locales ] )
This definition supersedes the definition provided in
This function interprets a String value as a sequence of code points, as described in
- Let O be ?
RequireObjectCoercible (this value). - Let S be ?
ToString (O). - Return ?
TransformCase (S, locales,upper ).
toLocaleUpperCase
function is intentionally generic; it does not require that its 20.2 Properties of the Number Prototype Object
The following definition(s) refer to the abstract operation thisNumberValue as defined in
20.2.1 Number.prototype.toLocaleString ( [ locales [ , options ] ] )
This definition supersedes the definition provided in
When the toLocaleString
method is called with optional arguments locales and options, the following steps are taken:
- Let x be ?
ThisNumberValue (this value). - Let numberFormat be ?
Construct (%Intl.NumberFormat% , « locales, options »). - Return
FormatNumeric (numberFormat, !ToIntlMathematicalValue (x)).
20.3 Properties of the BigInt Prototype Object
The following definition(s) refer to the abstract operation thisBigIntValue as defined in
20.3.1 BigInt.prototype.toLocaleString ( [ locales [ , options ] ] )
This definition supersedes the definition provided in
When the toLocaleString
method is called with optional arguments locales and options, the following steps are taken:
- Let x be ?
ThisBigIntValue (this value). - Let numberFormat be ?
Construct (%Intl.NumberFormat% , « locales, options »). - Return
FormatNumeric (numberFormat,ℝ (x)).
20.4 Properties of the Date Prototype Object
The following definition(s) refer to the abstract operation thisTimeValue as defined in
20.4.1 Date.prototype.toLocaleString ( [ locales [ , options ] ] )
This definition supersedes the definition provided in
When the toLocaleString
method is called with optional arguments locales and options, the following steps are taken:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let x be dateObject.[[DateValue]].
- If x is
NaN , return"Invalid Date" . - Let dateFormat be ?
CreateDateTimeFormat (%Intl.DateTimeFormat% , locales, options,any ,all ). - Return !
FormatDateTime (dateFormat, x).
20.4.2 Date.prototype.toLocaleDateString ( [ locales [ , options ] ] )
This definition supersedes the definition provided in
When the toLocaleDateString
method is called with optional arguments locales and options, the following steps are taken:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let x be dateObject.[[DateValue]].
- If x is
NaN , return"Invalid Date" . - Let dateFormat be ?
CreateDateTimeFormat (%Intl.DateTimeFormat% , locales, options,date ,date ). - Return !
FormatDateTime (dateFormat, x).
20.4.3 Date.prototype.toLocaleTimeString ( [ locales [ , options ] ] )
This definition supersedes the definition provided in
When the toLocaleTimeString
method is called with optional arguments locales and options, the following steps are taken:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let x be dateObject.[[DateValue]].
- If x is
NaN , return"Invalid Date" . - Let timeFormat be ?
CreateDateTimeFormat (%Intl.DateTimeFormat% , locales, options,time ,time ). - Return !
FormatDateTime (timeFormat, x).
20.5 Properties of the Array Prototype Object
20.5.1 Array.prototype.toLocaleString ( [ locales [ , options ] ] )
This definition supersedes the definition provided in
When the toLocaleString
method is called with optional arguments locales and options, the following steps are taken:
- Let array be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (array). - Let separator be the
implementation-defined list-separator String value appropriate for thehost environment 's current locale (such as", " ). - Let R be the empty String.
- Let k be 0.
- Repeat, while k < len,
- If k > 0, then
- Set R to the
string-concatenation of R and separator.
- Set R to the
- Let nextElement be ?
Get (array, !ToString (𝔽 (k))). - If nextElement is not
undefined ornull , then- Let S be ?
ToString (?Invoke (nextElement,"toLocaleString" , « locales, options »)). - Set R to the
string-concatenation of R and S.
- Let S be ?
- Set k to k + 1.
- If k > 0, then
- Return R.
toLocaleString
methods, and these Strings are then concatenated, separated by occurrences of an toString
except that it is intended to yield a locale-sensitive result corresponding with conventions of the toLocaleString
function is intentionally generic; it does not require that its Annex A (informative) Implementation Dependent Behaviour
The following aspects of this specification are implementation dependent:
-
In all functionality:
-
Additional values for some properties of options arguments (
2 ) -
The default locale (
6.2.3 ) -
The set of available locales for each
constructor (9.1 ) -
The
LookupMatchingLocaleByBestFit algorithm (9.2.4 )
-
Additional values for some properties of options arguments (
-
In Collator:
-
Support for the Unicode extensions keys
"kf" ,"kn" and the parallel options properties"caseFirst" ,"numeric" (10.1.1 ) -
The set of supported
"co" key values (collations) per locale beyond a default collation (10.2.3 ) -
The set of supported
"kf" key values (case order) per locale (10.2.3 ) -
The set of supported
"kn" key values (numeric collation) per locale (10.2.3 ) -
The default search sensitivity per locale (
10.2.3 ) -
The default ignore punctuation value per locale (
10.2.3 ) -
The
sort order for each supported locale and options combination (10.3.3.1 )
-
Support for the Unicode extensions keys
- In DateTimeFormat:
-
The
BestFitFormatMatcher algorithm (11.1.2 ) -
The set of supported
"ca" key values (calendars) per locale (11.2.3 ) -
The set of supported
"nu" key values (numbering systems) per locale (11.2.3 ) -
The default hourCycle setting per locale (
11.2.3 ) -
The set of supported date-time formats per locale beyond a core set, including the representations used for each component and the associated patterns (
11.2.3 ) -
Localized weekday names, era names, month names, day period names, am/pm indicators, and time zone names (
11.5.5 ) -
The calendric calculations used for calendars other than
"gregory" (11.5.12 ) -
The set of all known registered Zone and Link names of the IANA Time Zone Database and the information about their offsets from UTC and their daylight saving time rules (
21.4.1.19 )
-
The
-
In DisplayNames:
-
The localized names (
12.2.3 )
-
The localized names (
- In DurationFormat:
-
In ListFormat:
-
The patterns used for formatting values (
14.2.3 )
-
The patterns used for formatting values (
-
In Locale:
-
Support for the Unicode extensions keys
"kf" ,"kn" and the parallel options properties"caseFirst" ,"numeric" (15.1.1 )
-
Support for the Unicode extensions keys
-
In NumberFormat:
-
The set of supported
"nu" key values (numbering systems) per locale (16.2.3 ) -
The patterns used for formatting values as decimal, percent, currency, or unit values per locale, with or without the sign, with or without accounting format for currencies, and in standard, compact, or scientific notation (
16.5.6 ) -
The number of fractional digits used when formatting currency values (
16.5.6 ) -
Localized representations of
NaN andInfinity (16.5.6 ) -
The implementation of numbering systems not listed in
Table 28 (16.5.6 ) -
Localized decimal and grouping separators (
16.5.6 ) -
Localized plus and minus signs (
16.5.6 ) -
Localized digit grouping schemata (
16.5.6 ) -
Localized magnitude thresholds for compact notation (
16.5.6 ) -
Localized symbols for compact and scientific notation (
16.5.6 ) -
Localized narrow, short, and long currency symbols and names (
16.5.6 ) -
Localized narrow, short, and long unit symbols (
16.5.6 )
-
The set of supported
- In PluralRules:
- In RelativeTimeFormat:
- In Segmenter:
Annex B (informative) Additions and Changes That Introduce Incompatibilities with Prior Editions
-
10.1 ,16.1 ,11.1 In ECMA-402, 1st Edition,constructors could be used to create Intl objects from arbitrary objects. This is no longer possible in 2nd Edition. -
11.3.3 In ECMA-402, 1st Edition, the"length" property of thefunction object F was set to+0 𝔽. In 2nd Edition,"length" is set to1 𝔽. -
10.3.4 In ECMA-402, 7th Edition, the%Symbol.toStringTag% property ofIntl.Collator.prototype
was set to"Object" . In 8th Edition,%Symbol.toStringTag% is set to"Intl.Collator" . -
11.3.7 In ECMA-402, 7th Edition, the%Symbol.toStringTag% property ofIntl.DateTimeFormat.prototype
was set to"Object" . In 8th Edition,%Symbol.toStringTag% is set to"Intl.DateTimeFormat" . -
16.3.7 In ECMA-402, 7th Edition, the%Symbol.toStringTag% property ofIntl.NumberFormat.prototype
was set to"Object" . In 8th Edition,%Symbol.toStringTag% is set to"Intl.NumberFormat" . -
17.3.5 In ECMA-402, 7th Edition, the%Symbol.toStringTag% property ofIntl.PluralRules.prototype
was set to"Object" . In 8th Edition,%Symbol.toStringTag% is set to"Intl.PluralRules" . -
8.1.1 In ECMA-402, 7th Edition, the%Symbol.toStringTag% property ofIntl
was not defined. In 8th Edition,%Symbol.toStringTag% is set to"Intl" . -
16.1 In ECMA-402, 8th Edition, the NumberFormatconstructor used to throw an error when style is"currency" and maximumFractionDigits was set to a value lower than the default fractional digits for that currency. This behaviour was corrected in the 9th edition, and it no longer throws an error.
Annex C (informative) Colophon
This specification is authored on GitHub in a plaintext source format called Ecmarkup. Ecmarkup is an HTML and Markdown dialect that provides a framework and toolset for authoring ECMAScript specifications in plaintext and processing the specification into a full-featured HTML rendering that follows the editorial conventions for this document. Ecmarkup builds on and integrates a number of other formats and technologies including Grammarkdown for defining syntax and Ecmarkdown for authoring algorithm steps. PDF renderings of this specification are produced by printing the HTML rendering to a PDF.
Prior editions of this specification were authored using Word—the Ecmarkup source text that formed the basis of this edition was produced by converting the ECMAScript 2015 Word document to Ecmarkup using an automated conversion tool.
Copyright & Software License
Ecma International
Rue du Rhone 114
CH-1204 Geneva
Tel: +41 22 849 6000
Fax: +41 22 849 6001
Web: https://ecma-international.org/
Copyright Notice
© 2025 Ecma International
This draft document may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published, and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this section are included on all such copies and derivative works. However, this document itself may not be modified in any way, including by removing the copyright notice or references to Ecma International, except as needed for the purpose of developing any document or deliverable produced by Ecma International.
This disclaimer is valid only prior to final version of this document. After approval all rights on the standard are reserved by Ecma International.
The limited permissions are granted through the standardization phase and will not be revoked by Ecma International or its successors or assigns during this time.
This document and the information contained herein is provided on an "AS IS" basis and ECMA INTERNATIONAL DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Software License
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:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
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.