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

Normative: Specify Date string conversion functions #848

Merged
merged 7 commits into from
May 30, 2017
Merged
Changes from 1 commit
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
246 changes: 239 additions & 7 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -27066,7 +27066,13 @@ <h1>Date.prototype.setUTCSeconds ( _sec_ [ , _ms_ ] )</h1>
<!-- es6num="20.3.4.35" -->
<emu-clause id="sec-date.prototype.todatestring">
<h1>Date.prototype.toDateString ( )</h1>
<p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the &ldquo;date&rdquo; portion of the Date in the current time zone in a convenient, human-readable form.</p>
<emu-alg>
1. Let _O_ be this Date object.
1. Let _tv_ be ? thisTimeValue(_O_).
1. If _tv_ is *NaN*, return `"Invalid Date"`.
1. Let _t_ be LocalTime(_tv_).
1. Return DateString(_t_).
</emu-alg>
</emu-clause>

<!-- es6num="20.3.4.36" -->
Expand Down Expand Up @@ -27137,31 +27143,257 @@ <h1>Date.prototype.toString ( )</h1>
<p>The `toString` function is intentionally generic; it does not require that its *this* value be a Date object. Therefore, it can be transferred to other kinds of objects for use as a method.</p>
</emu-note>

<emu-clause id="sec-timestring" aoid="TimeString">
<h1>Runtime Semantics: TimeString( _tv_ )</h1>
<p>The following steps are performed:</p>
<emu-alg>
1. Assert: Type(_tv_) is Number.
1. Assert: _tv_ is not *NaN*.
1. Return String value formed by concatenating _result_, ToString(HourFromTime(_tv_)), `":"`, ToString(MinFromTime(_tv_)), `":"`, ToString(SecFromTime(_tv_)) and `" GMT"`
</emu-alg>
</emu-clause>

<emu-clause id="sec-datestring" aoid="DateString">
<h1>Runtime Semantics: DateString( _tv_, _zone_, _components_ )</h1>
<p>The following steps are performed:</p>
<emu-alg>
1. Assert: Type(_tv_) is Number.
1. Assert: _tv_ is not *NaN*.
1. Let _weekday_ be the Name of the entry in <emu-xref href="#sec-todatestring-day-names"></emu-xref> with the Number WeekDay(_t_).
1. Let _month_ be the Name of the entry in <emu-xref href="#sec-todatestring-month-names"></emu-xref> with the Number MonthFromTime(_t_).
1. Let _result_ be the String value formed by concatenating _weekday_, `" "`, _month_, `" "`, ToString(DateFromTime(_t_)), `" "`, and ToString(YearFromTime(_t_)).
</emu-alg>
<emu-table id="sec-todatestring-day-names" caption="Names of days of the week">
<table>
<tbody>
<tr>
<th>
Number
</th>
<th>
Name
</th>
</tr>
<tr>
<td>
0
</td>
<td>
`"Sun"`
</td>
</tr>
<tr>
<td>
1
</td>
<td>
`"Mon"`
</td>
</tr>
<tr>
<td>
2
</td>
<td>
`"Tue"`
</td>
</tr>
<tr>
<td>
3
</td>
<td>
`"Wed"`
</td>
</tr>
<tr>
<td>
4
</td>
<td>
`"Thu"`
</td>
</tr>
<tr>
<td>
5
</td>
<td>
`"Fri"`
</td>
</tr>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extraneous result variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

<tr>
<td>
6
</td>
<td>
`"Sat"`
</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-table id="sec-todatestring-month-names" caption="Names of months of the year">
<table>
<tbody>
<tr>
<th>
Number
</th>
<th>
Name
</th>
</tr>
<tr>
<td>
0
</td>
<td>
`"Jan"`
</td>
</tr>
<tr>
<td>
1
</td>
<td>
`"Feb"`
</td>
</tr>
<tr>
<td>
2
</td>
<td>
`"Mar"`
</td>
</tr>
<tr>
<td>
3
</td>
<td>
`"Apr"`
</td>
</tr>
<tr>
<td>
4
</td>
<td>
`"May"`
</td>
</tr>
<tr>
<td>
5
</td>
<td>
`"Jun"`
</td>
</tr>
<tr>
<td>
6
</td>
<td>
`"Jul"`
</td>
</tr>
<tr>
<td>
7
</td>
<td>
`"Aug"`
</td>
</tr>
<tr>
<td>
8
</td>
<td>
`"Sep"`
</td>
</tr>
<tr>
<td>
9
</td>
<td>
`"Oct"`
</td>
</tr>
<tr>
<td>
10
</td>
<td>
`"Nov"`
</td>
</tr>
<tr>
<td>
11
</td>
<td>
`"Dec"`
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>

<emu-clause id="sec-timezoneestring" aoid="TimeZoneString">
<h1>Runtime Semantics: TimeZoneString( _tv_, )</h1>
<p>The following steps are performed:</p>
<emu-alg>
1. Assert: Type(_tv_) is Number.
1. Assert: _tv_ is not *NaN*.
1. Let _offset_ be (LocalTZA + DaylightSavingTA(_tv_)) / msPerSecond.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be in conflict with #778 that drops DaylightSavingTA(tv) and change LocalTZA to take two params. We have to sort that out somehow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right; this is written against the current spec, but needs to be updated against the other one (based on whichever lands second). I guess rather than LocalTZA, we'd use LocalTimeZoneAdjustment(tz, true), right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. this one was landed first. Then, the other one (#778) has to revise this part as well.

1. Assert: _offset_ is an integer, and -100000 &lt; _offset_ &lt; 100000.
1. If _offset_ &ge; 0, let _offsetSign_ be `"+"`; otherwise, let _offsetSign_ be `"-"`.
1. Let _offsetString_ be abs(_offset_) formatted as a four-digit number, padded to the left with zeros if necessary.
1. Let _tzName_ be an implementation-defined string, either `""` or a string of the form `" ("` _name_ `")"` where _name_ is an implementation-defined timezone name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to give a recommendation while leaving it still up to an implementation about tzName?
If it does, it can be recommended to use the canonicalized timezone in Ecma402. Perhaps, cross-referencing is not a good idea?
Just my 2 cents.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant for this first patch to be purely 100% descriptive. Maybe a change like this could be in a follow-on patch?

As for making that recommendation: I don't know whether we can make it in good faith in the spec yet, as we don't know whether it's web-compatible yet. Maybe the right thing to do would be to try it out in one browser and see if it works. A good thing to know from the committee beforehand would be--would everyone be up for specifying this behavior, assuming it's web-compatible?

1. Return the String value formed by concatenating _result_, _offsetSign_, _offsetString_, and _tzName_.
</emu-alg>
</emu-clause>

<!-- es6num="20.3.4.41.1" -->
<emu-clause id="sec-todatestring" aoid="ToDateString">
<h1>Runtime Semantics: ToDateString( _tv_ )</h1>
<p>The following steps are performed:</p>
<emu-alg>
1. Assert: Type(_tv_) is Number.
1. If _tv_ is *NaN*, return `"Invalid Date"`.
1. Return an implementation-dependent String value that represents _tv_ as a date and time in the current time zone using a convenient, human-readable form.
1. Let _t_ be LocalTime(_tv_).
1. Return the String value formed by concatenating DateString(_t_), `" "`, and TimeString(_t_), TimeZoneString(_tv_).
</emu-alg>
</emu-clause>
</emu-clause>

<!-- es6num="20.3.4.42" -->
<emu-clause id="sec-date.prototype.totimestring">
<h1>Date.prototype.toTimeString ( )</h1>
<p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the &ldquo;time&rdquo; portion of the Date in the current time zone in a convenient, human-readable form.</p>
<emu-alg>
1. Let _O_ be this Date object.
1. Let _tv_ be ? thisTimeValue(_O_).
1. If _tv_ is *NaN*, return `"Invalid Date"`.
1. Let _t_ be LocalTime(_tv_).
1. Return the String value formed by concatenating TimeString(_t_) and TimeZoneString(_tv_).
</emu-alg>
</emu-clause>

<!-- es6num="20.3.4.43" -->
<emu-clause id="sec-date.prototype.toutcstring">
<h1>Date.prototype.toUTCString ( )</h1>
<p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent this time value in a convenient, human-readable form in UTC.</p>
<emu-note>
<p>The intent is to produce a String representation of a date that is more readable than the format specified in <emu-xref href="#sec-date-time-string-format"></emu-xref>. It is not essential that the chosen format be unambiguous or easily machine parsable. If an implementation does not have a preferred human-readable format it is recommended to use the format defined in <emu-xref href="#sec-date-time-string-format"></emu-xref> but with a space rather than a `"T"` used to separate the date and time elements.</p>
</emu-note>
<emu-alg>
1. Let _O_ be this Date object.
1. Let _tv_ be ? thisTimeValue(_O_).
1. If _tv_ is *NaN*, return `"Invalid Date"`.
1. Return the String value formed by concatenating DateString(_tv_), `" "`, and TimeString(_tv_).
</emu-alg>
</emu-clause>

<!-- es6num="20.3.4.44" -->
Expand Down