Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #43 from anba/mixed-options
Browse files Browse the repository at this point in the history
Throw a RangeError when mixing date-/timeStyle with other date/time options
  • Loading branch information
zbraniecki authored Apr 23, 2020
2 parents 9805bf7 + a4f6ccd commit d725d38
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
6 changes: 6 additions & 0 deletions biblio.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"https://tc39.github.io/ecma402/": [
{
"type": "clause",
"title": "Internal slots of Service Constructors",
"number": "9.1",
"id": "sec-internal-slots"
},
{
"type": "op",
"aoid": "BasicFormatMatcher",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "[ -d out ] || mkdir out && ecmarkup spec.html out/index.html"
},
"dependencies": {
"ecmarkup": "^3.12.0"
"ecmarkup": "^3.19.0"
},
"devDependencies": {
"@alrra/travis-scripts": "^3.0.0"
Expand Down
57 changes: 49 additions & 8 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,29 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
1. Else,
1. Let _timeZone_ be DefaultTimeZone().
1. Set _dateTimeFormat_.[[TimeZone]] to _timeZone_.
1. Let _opt_ be a new Record.
1. For each row of <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, do
1. Let _prop_ be the name given in the Property column of the row.
1. Let _value_ be ? GetOption(_options_, _prop_, `"string"`, &laquo; the strings given in the Values column of the row &raquo;, *undefined*).
1. Set _opt_.[[&lt;_prop_&gt;]] to _value_.
1. Let _matcher_ be ? GetOption(_options_, `"formatMatcher"`, `"string"`, &laquo; `"basic"`, `"best fit"` &raquo;, `"best fit"`).
1. <del>Let _dataLocaleData_ be _localeData_.[[&lt;_dataLocale_&gt;]].</del>
1. Let _formats_ be _dataLocaleData_.[[formats]].
1. <del>Let _formats_ be _dataLocaleData_.[[formats]].</del>
1. <ins>Let _dateStyle_ be ? GetOption(_options_, `"dateStyle"`, `"string"`, &laquo; `"full"`, `"long"`, `"medium"`, `"short"` &raquo;, *undefined*).</ins>
1. <ins>If _dateStyle_ is not *undefined*, set _dateTimeFormat_.[[DateStyle]] to _dateStyle_.</ins>
1. <ins>Let _timeStyle_ be ? GetOption(_options_, `"timeStyle"`, `"string"`, &laquo; `"full"`, `"long"`, `"medium"`, `"short"` &raquo;, *undefined*).</ins>
1. <ins>If _timeStyle_ is not *undefined*, then</ins>
1. <ins>Set _dateTimeFormat_.[[TimeStyle]] to _timeStyle_.</ins>
1. <ins>Set _dateTimeFormat_.[[HourCycle]] to _hc_.</ins>
1. <ins>If _dateStyle_ or _timeStyle_ are not *undefined*, then</ins>
1. <ins>If _dateStyle_ is not *undefined* or _timeStyle_ is not *undefined*, then</ins>
1. <ins>For each row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, do</ins>
1. <ins>Let _prop_ be the name given in the Property column of the row.</ins>
1. <ins>Let _p_ be _opt_.[[&lt;_prop_&gt;]].</ins>
1. <ins>If _p_ is not *undefined*, then</ins>
1. <ins>Throw a *RangeError* exception.</ins>
1. <ins>Let _pattern_ be DateTimeStylePattern(_dateStyle_, _timeStyle_, _dataLocaleData_, _hc_).</ins>
1. <ins>Else,</ins>
1. Let _opt_ be a new Record.
1. For each row of <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, do
1. Let _prop_ be the name given in the Property column of the row.
1. Let _value_ be ? GetOption(_options_, _prop_, `"string"`, &laquo; the strings given in the Values column of the row &raquo;, *undefined*).
1. Set _opt_.[[&lt;_prop_&gt;]] to _value_.
1. Let _matcher_ be ? GetOption(_options_, `"formatMatcher"`, `"string"`, &laquo; `"basic"`, `"best fit"` &raquo;, `"best fit"`).
1. Let _formats_ be _dataLocaleData_.[[formats]].
1. If _matcher_ is `"basic"`, then
1. Let _bestFormat_ be BasicFormatMatcher(_opt_, _formats_).
1. Else,
Expand Down Expand Up @@ -190,6 +196,41 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
1. Return _dateTimeFormat_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-todatetimeoptions" aoid="ToDateTimeOptions">
<h1>ToDateTimeOptions ( _options_, _required_, _defaults_ )</h1>

<p>
When the ToDateTimeOptions abstract operation is called with arguments _options_, _required_, and _defaults_, the following steps are taken:
</p>

<emu-alg>
1. If _options_ is *undefined*, let _options_ be *null*; otherwise let _options_ be ? ToObject(_options_).
1. Let _options_ be ObjectCreate(_options_).
1. Let _needDefaults_ be *true*.
1. If _required_ is *"date"* or *"any"*, then
1. For each of the property names *"weekday"*, *"year"*, *"month"*, *"day"*, do
1. Let _prop_ be the property name.
1. Let _value_ be ? Get(_options_, _prop_).
1. If _value_ is not *undefined*, let _needDefaults_ be *false*.
1. If _required_ is *"time"* or *"any"*, then
1. For each of the property names *"hour"*, *"minute"*, *"second"*, do
1. Let _prop_ be the property name.
1. Let _value_ be ? Get(_options_, _prop_).
1. If _value_ is not *undefined*, let _needDefaults_ be *false*.
1. <ins>Let _dateStyle_ be ? Get(_options_, *"dateStyle"*).</ins>
1. <ins>Let _timeStyle_ be ? Get(_options_, *"timeStyle"*).</ins>
1. <ins>If _dateStyle_ is not *undefined* or _timeStyle_ is not *undefined*, let _needDefaults_ be *false*.</ins>
1. If _needDefaults_ is *true* and _defaults_ is either *"date"* or *"all"*, then
1. For each of the property names *"year"*, *"month"*, *"day"*, do
1. Perform ? CreateDataPropertyOrThrow(_options_, _prop_, *"numeric"*).
1. If _needDefaults_ is *true* and _defaults_ is either *"time"* or *"all"*, then
1. For each of the property names *"hour"*, *"minute"*, *"second"*, do
1. Perform ? CreateDataPropertyOrThrow(_options_, _prop_, *"numeric"*).
1. Return _options_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-date-time-style-pattern" aoid="DateTimeStylePattern">
<h1><ins>DateTimeStylePattern ( _dateStyle_, _timeStyle_, _dataLocaleData_, _hourCycle_ )</ins></h1>
<p>The DateTimeStylePattern abstract operation accepts arguments _dateStyle_ and _timeStyle_, which are each either *undefined*, `"full"`, `"long"`, `"medium"`, or `"short"`, at least one of which is not *undefined*, _dataLocaleData_, which is a record from %DateTimeFormat%.[[LocaleData]][_locale_] for some locale _locale_, and _hourCycle_, which is either `"h11"`, `"h12"`, `"h23"`, or `"h24"`. It returns the appropriate pattern for date time formatting based on the parameters.</p>
Expand Down

0 comments on commit d725d38

Please sign in to comment.