Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Date.from(). #194

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 45 additions & 31 deletions spec/civildate.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,19 @@ <h1>Temporal.Date.fromString ( _isostring_ )</h1>
</p>
<emu-alg>
1. Let _isostring_ be ? ToString(_isostring_).
1. Let _validSyntax_ be *true* if _isostring_ conforms to the format `YYYY-MM-DD`, and *false* otherwise, where:
* `YYYY` is either four decimal digits or an expanded year of `"+"` or `"-"` followed by six decimal digits;
* `-` is the code unit 0x002D (HYPHEN-MINUS);
* `MM` is two decimal digits;
* `-` is the code unit 0x002D (HYPHEN-MINUS);
* `DD` is two decimal digits.
1. If _validSyntax_ is *false*, then
1. Throw a *RangeError* exception.
1. Let _year_, _month_, and _day_ be the respective parts of _isostring_, interpreted as decimal numbers.
1. Let _result_ be ? RegulateDate(_year_, _month_, _day_, `"reject"`).
1. Return ? CreateDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]).
1. Return ? DateFromString(_isostring_).
</emu-alg>
</emu-clause>

<emu-clause>
<h1>Temporal.Date.from ( …_args_ )</h1>
<h1>Temporal.Date.from ( _arg_ )</h1>
<p>
<mark>TODO: Define.</mark>
The `fromString` method takes one argument _arg_.
The following steps are taken:
</p>
<emu-alg>
1. Return ? ToDate(_arg_).
</emu-alg>
</emu-clause>

<emu-clause>
Expand Down Expand Up @@ -467,28 +461,48 @@ <h1>CreateDate ( _y_, _m_, _d_ [ , _newTarget_ ] )</h1>
</emu-alg>
</emu-clause>

<emu-clause id=sec-temporal-DateFromString aoid=DateFromString>
<h1>DateFromString ( _date_ )</h1>
<emu-alg>
1. Assert: Type(_date_) is String.
1. Let _validSyntax_ be *true* if _isostring_ conforms to the format `YYYY-MM-DD`, and *false* otherwise, where:
* `YYYY` is either four decimal digits or an expanded year of `"+"` or `"-"` followed by six decimal digits;
* `-` is the code unit 0x002D (HYPHEN-MINUS);
* `MM` is two decimal digits;
* `-` is the code unit 0x002D (HYPHEN-MINUS);
* `DD` is two decimal digits.
ryzokuken marked this conversation as resolved.
Show resolved Hide resolved
1. If _validSyntax_ is *false*, then
1. Throw a *RangeError* exception.
1. Let _year_, _month_, and _day_ be the respective parts of _isostring_, interpreted as decimal numbers.
1. Let _result_ be ? RegulateDate(_year_, _month_, _day_, `"reject"`).
1. Return ? CreateDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]).
</emu-alg>
</emu-clause>

<emu-clause id=sec-temporal-ToDate aoid=ToDate>
<h1>ToDate ( _date_ )</h1>
<emu-alg>
1. Let _result_ be {
[[Year]]: *undefined*,
[[Month]]: *undefined*,
[[Day]]: *undefined*,
}.
1. <mark>TODO: Handle strings?</mark>
1. If Type(_date_) is not Object, then
1. Throw a *TypeError* exception.
1. For each row of <emu-xref href="#table-temporal-datelike-properties"></emu-xref>, except the header row, in table order, do
1. Let _property_ be the Property value of the current row.
1. Let _value_ be ? Get(_date_, _property_).
1. If _value_ is *undefined*, then
1. If Type(_date_) is String, then
1. Return ? DateFromString(_date_).
1. If Type(_date_) is Object, then
1. Let _result_ be the Record {
[[Year]]: *undefined*,
[[Month]]: *undefined*,
[[Day]]: *undefined*,
}.
1. If _date_ has an [[InitializedTemporalDate]] internal slot, then
1. Return _date_.
1. For each row of <emu-xref href="#table-temporal-datelike-properties"></emu-xref>, except the header row, in table order, do
1. Let _property_ be the Property value of the current row.
1. Let _value_ be ? Get(_date_, _property_).
1. If _value_ is *undefined*, then
1. Throw a *TypeError* exception.
1. Let _value_ be ? ToInteger(_value_).
1. Set _result_'s internal slot whose name is the Internal Slot value of the current row to _value_.
1. If ! ValidateDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *false*, then
1. Throw a *TypeError* exception.
1. Let _value_ be ? ToInteger(_value_).
1. Set _result_'s internal slot whose name is the Internal Slot value of the current row to _value_.
1. If ! ValidateDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *false*, then
1. Throw a *TypeError* exception.
1. <mark>TODO: Throw if any time properties are present?</mark>
1. Return _result_.
1. Return ? CreateDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]).
1. Throw a *TypeError* exception.
</emu-alg>
</emu-clause>

Expand Down