Skip to content

Commit

Permalink
Editorial: Add CreateDateTimeFormat abstract operation
Browse files Browse the repository at this point in the history
The next commits will merge `CreateDateTimeFormat` and
`InitializeDateTimeFormat` and remove the two calls to
`ToDateTimeOptions`.
  • Loading branch information
anba authored and ryzokuken committed Jul 21, 2023
1 parent f6d2945 commit b6ed64b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
43 changes: 36 additions & 7 deletions spec/datetimeformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ <h1>Intl.DateTimeFormat ( [ _locales_ [ , _options_ ] ] )</h1>

<emu-alg>
1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget.
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%DateTimeFormat.prototype%"*, &laquo; [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[DateStyle]], [[TimeStyle]], [[Pattern]], [[RangePatterns]], [[BoundFormat]] &raquo;).
1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_).
1. Let _dateTimeFormat_ be ? CreateDateTimeFormat(_newTarget_, _locales_, _options_, *"any"*, *"date"*).
1. If the implementation supports the normative optional constructor mode of <emu-xref href="#legacy-constructor"></emu-xref>, then
1. Let _this_ be the *this* value.
1. Return ? ChainDateTimeFormat(_dateTimeFormat_, NewTarget, _this_).
Expand All @@ -38,15 +37,45 @@ <h1>ChainDateTimeFormat ( _dateTimeFormat_, _newTarget_, _this_ )</h1>
</emu-normative-optional>
</emu-clause>

<emu-clause id="sec-initializedatetimeformat" aoid="InitializeDateTimeFormat">
<h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
<emu-clause id="sec-createdatetimeformat" type="abstract operation">
<h1>
CreateDateTimeFormat (
_newTarget_: a constructor,
_locales_: an ECMAScript language value,
_options_: an ECMAScript language value,
_required_: a String,
_defaults_: a String
): either a normal completion containing a DateTimeFormat object or a throw completion
</h1>
<dl class="header">
</dl>

<p>
The abstract operation InitializeDateTimeFormat accepts the arguments _dateTimeFormat_ (which must be an object), _locales_, and _options_. It initializes _dateTimeFormat_ as a DateTimeFormat object. This abstract operation functions as follows:
</p>
<emu-alg>
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%DateTimeFormat.prototype%"*, &laquo; [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[DateStyle]], [[TimeStyle]], [[Pattern]], [[RangePatterns]], [[BoundFormat]] &raquo;).
1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_, _required_, _defaults_).
1. Return _dateTimeFormat_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-initializedatetimeformat" aoid="InitializeDateTimeFormat">
<h1>
InitializeDateTimeFormat (
_dateTimeFormat_: an Object,
_locales_: an ECMAScript language value,
_options_: an ECMAScript language value,
_required_: a String,
_defaults_: a String
): either a normal completion containing a DateTimeFormat object or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It initializes _dateTimeFormat_ as a DateTimeFormat object.</dd>
</dl>

<emu-alg>
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
1. If _required_ is not *"any"* or _defaults_ is not *"date"*, then
1. Set _options_ to ? ToDateTimeOptions(_options_, _required_, _defaults_).
1. Set _options_ to ? ToDateTimeOptions(_options_, *"any"*, *"date"*).
1. Let _opt_ be a new Record.
1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, ~string~, &laquo; *"lookup"*, *"best fit"* &raquo;, *"best fit"*).
Expand Down
9 changes: 3 additions & 6 deletions spec/locale-sensitive-functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ <h1>Date.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )</h1>
<emu-alg>
1. Let _x_ be ? thisTimeValue(*this* value).
1. If _x_ is *NaN*, return *"Invalid Date"*.
1. Let _options_ be ? ToDateTimeOptions(_options_, *"any"*, *"all"*).
1. Let _dateFormat_ be ? Construct(%DateTimeFormat%, &laquo; _locales_, _options_ &raquo;).
1. Let _dateFormat_ be ? CreateDateTimeFormat(%DateTimeFormat%, _locales_, _options_, *"any"*, *"all"*).
1. Return ? FormatDateTime(_dateFormat_, _x_).
</emu-alg>
</emu-clause>
Expand All @@ -222,8 +221,7 @@ <h1>Date.prototype.toLocaleDateString ( [ _locales_ [ , _options_ ] ] )</h1>
<emu-alg>
1. Let _x_ be ? thisTimeValue(*this* value).
1. If _x_ is *NaN*, return *"Invalid Date"*.
1. Let _options_ be ? ToDateTimeOptions(_options_, *"date"*, *"date"*).
1. Let _dateFormat_ be ? Construct(%DateTimeFormat%, &laquo; _locales_, _options_ &raquo;).
1. Let _dateFormat_ be ? CreateDateTimeFormat(%DateTimeFormat%, _locales_, _options_, *"date"*, *"date"*).
1. Return ? FormatDateTime(_dateFormat_, _x_).
</emu-alg>
</emu-clause>
Expand All @@ -242,8 +240,7 @@ <h1>Date.prototype.toLocaleTimeString ( [ _locales_ [ , _options_ ] ] )</h1>
<emu-alg>
1. Let _x_ be ? thisTimeValue(*this* value).
1. If _x_ is *NaN*, return *"Invalid Date"*.
1. Let _options_ be ? ToDateTimeOptions(_options_, *"time"*, *"time"*).
1. Let _timeFormat_ be ? Construct(%DateTimeFormat%, &laquo; _locales_, _options_ &raquo;).
1. Let _timeFormat_ be ? CreateDateTimeFormat(%DateTimeFormat%, _locales_, _options_, *"time"*, *"time"*).
1. Return ? FormatDateTime(_timeFormat_, _x_).
</emu-alg>
</emu-clause>
Expand Down

0 comments on commit b6ed64b

Please sign in to comment.