-
Notifications
You must be signed in to change notification settings - Fork 10
/
spec.emu.html
65 lines (63 loc) · 7.5 KB
/
spec.emu.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<pre class="metadata">
title: Uniform parsing of quasi-standard Date.parse input
status: proposal
stage: 1
shortname: <a href="https://github.com/tc39/proposal-uniform-interchange-date-parsing">proposal-uniform-interchange-date-parsing</a>
contributors: Richard Gibson
</pre>
<emu-biblio href="./missing-productions.json"></emu-biblio>
<emu-clause id="sec-date.parse">
<h1>Date.parse ( _string_ )</h1>
<p>The `parse` function <del>applies the ToString operator to its argument. If ToString results in an abrupt completion the Completion Record is immediately returned. Otherwise, `parse` interprets the resulting String</del><ins>interprets its argument</ins> as a date and time; it returns a Number, the UTC time value corresponding to the date and time. The String may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the String. The function first attempts to parse the String according to the format described in Date Time String Format (<emu-xref href="#sec-date-time-string-format"></emu-xref>), including expanded years. If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats. Strings that are unrecognizable or contain out-of-bounds format field values shall cause `Date.parse` to return *NaN*.</p>
<ins class="block">
<p>If the String conforms to the <emu-xref href="#sec-date-time-string-format">Date Time String Format</emu-xref>, substitute values take the place of absent format elements. When the `MM` or `DD` elements are absent, `"01"` is used. When the `HH`, `mm`, or `ss` elements are absent, `"00"` is used. When the `sss` element is absent, `"000"` is used. When the time zone designator is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time.</p>
</ins>
<p>If `x` is any Date object whose milliseconds amount is zero within a particular implementation of ECMAScript, then all of the following expressions should produce the same numeric value in that implementation, if all the properties referenced have their initial values:</p>
<pre><code class="javascript">
x.valueOf()
Date.parse(x.toString())
Date.parse(x.toUTCString())
Date.parse(x.toISOString())
</code></pre>
<p>However, the expression</p>
<pre><code class="javascript">
Date.parse(x.toLocaleString())
</code></pre>
<p>is not required to produce the same Number value as the preceding three expressions and, in general, the value produced by `Date.parse` is implementation-dependent when given any String value that does not conform to the Date Time String Format (<emu-xref href="#sec-date-time-string-format"></emu-xref>) and that could not be produced in that implementation by the `toString` or `toUTCString` method.</p>
<ins class="block">
<p>When the `parse` function is called, the following steps are taken:</p>
<emu-alg>
1. Let _inputString_ be ? ToString(_string_).
1. Let _extendedDecimalInputString_ be the String value that is the same as _inputString_ except that each sequence of the code unit 0x002E (FULL STOP) followed by one or more consecutive |DecimalDigit|s has been replaced with `.` followed by the first three code units of the string-concatenation of the |DecimalDigit|s of the sequence and `"00"`.
1. Let _msInputString_ be the String value that is the same as _extendedDecimalInputString_ except that each sequence of the code unit 0x002E (FULL STOP) followed by four or more consecutive |DecimalDigit|s has been replaced with `.` followed by the first three |DecimalDigit|s of the sequence.
1. Let _inBoundsInputString_ be the String value that is the same as _msInputString_ except that each occurrence of |DecimalDigit| has been replaced with `1`.
1. If _inBoundsInputString_ conforms to the interchange format described in Date Time String Format (<emu-xref href="#sec-date-time-string-format"></emu-xref>), including expanded years, then
1. Assert: The `YYYY` format element is present in _msInputString_.
1. If the `YYYY` format element of _msInputString_ represents a year exceeding the bounds of a time value, return *NaN*.
1. If the `MM` format element is present in _msInputString_ and its value is `"00"` or its value is greater than `"12"` or the combination of the `YYYY` and `MM` format elements of _msInputString_ represents a year and month exceeding the bounds of a time value, return *NaN*.
1. If the `DD` format element is present in _msInputString_ and the combination of the `YYYY`, `MM`, and `DD` format elements of _msInputString_ represents a nonexistent date or a date exceeding the bounds of a time value, return *NaN*.
1. Assert: The combination of the `YYYY`, `MM`, and `DD` format elements of _msInputString_ (substituting `"01"` for any absent `MM` or `DD` element) represents a date that is part of the proleptic Gregorian calendar.
1. If the `HH` format element is present in _msInputString_ and its value is greater than `"24"` or its value is equal to `"24"` and one or more of the `mm`, `ss`, and `sss` format elements are present in _msInputString_ with a value including any code unit other than `0`, return *NaN*.
1. If the `mm` format element is present in _msInputString_ and its value is greater than `"59"`, return *NaN*.
1. If the `ss` format element is present in _msInputString_ and its value is greater than `"59"`, return *NaN*.
1. Assert: The combination of the `HH`, `mm`, and `ss` format elements of _msInputString_ (substituting `"00"` for any absent element) represents either a valid time of day that is at most `"23:59:59"` or a special end-of-day `"24:00:00"`.
1. If the `Z` format element is present in _msInputString_ and its `HH` component is greater than `"23"` or its `mm` component is greater than `"59"`, return *NaN*.
1. Assert: The `Z` format element is either absent from _msInputString_ or represents a UTC offset of magnitude less than 24 hours.
1. If the date and time represented by _msInputString_ exceeds the bounds of a time value, return *NaN*.
1. Return the time value corresponding with the date and time represented by _msInputString_.
1. Assert: _inputString_ does not conform to the Date Time String Format (<emu-xref href="#sec-date-time-string-format"></emu-xref>).
1. Let _tv_ be *NaN*.
1. If there is a nonempty set of finite time values such that invoking the initial value of `Date.prototype.toString` (<emu-xref href="#sec-date.prototype.tostring"></emu-xref>) with a Date instance having a [[DateValue]] internal slot equal to any of them would return _inputString_, then
1. Let _tv_ be the lowest-valued member of the set.
1. Else if there is a nonempty set of finite time values such that invoking the initial value of `Date.prototype.toUTCString` (<emu-xref href="#sec-date.prototype.toutcstring"></emu-xref>) with a Date instance having a [[DateValue]] internal slot equal to any of them would return _inputString_, then
1. Let _tv_ be the lowest-valued member of the set.
1. Else if the implementation includes a further facility for parsing dates and times, then
1. Let _tv_ be the implementation-dependent time value returned from using that facility to attempt parsing _inputString_.
1. Assert: _tv_ is *NaN* or abs(_tv_) ≤ 8.64 × 10<sup>15</sup>.
1. Return _tv_.
</emu-alg>
</ins>
</emu-clause>