Commit dd3f1ecf authored by ulan's avatar ulan Committed by Commit bot

Revert of Make dates default to the local timezone if none specified ...

Revert of Make dates default to the local timezone if none specified  (https://codereview.chromium.org/1229903004/)

Even though the change is ES6 spec compliant, we decided to revert
to be consistent with other browsers and work on fixing the spec.

Original issue's description:
> Make dates default to the local timezone if none specified
>
> In ES5, dates were supposed to default to UTC if no timezone was specified. However, this changed in ES6, which specified that dates should be in the local timezone if no timezone was specified. This CL updates our behavior to match that part of the ES6 spec.

> BUG=chromium:391730, v8:4242
> LOG=Y

> Committed: https://crrev.com/f06754a8e1d305a43560705f6c167d85d40e602d
> Cr-Commit-Position: refs/heads/master@{#29854}

BUG=chromium:543320,chromium:539813
LOG=NO

Review URL: https://codereview.chromium.org/1403153003

Cr-Commit-Position: refs/heads/master@{#31295}
parent e6a923ab
...@@ -24,9 +24,9 @@ bool DateParser::Parse(Vector<Char> str, ...@@ -24,9 +24,9 @@ bool DateParser::Parse(Vector<Char> str,
DayComposer day; DayComposer day;
// Specification: // Specification:
// Accept ES6 ISO 8601 date-time-strings or legacy dates compatible // Accept ES5 ISO 8601 date-time-strings or legacy dates compatible
// with Safari. // with Safari.
// ES6 ISO 8601 dates: // ES5 ISO 8601 dates:
// [('-'|'+')yy]yyyy[-MM[-DD]][THH:mm[:ss[.sss]][Z|(+|-)hh:mm]] // [('-'|'+')yy]yyyy[-MM[-DD]][THH:mm[:ss[.sss]][Z|(+|-)hh:mm]]
// where yyyy is in the range 0000..9999 and // where yyyy is in the range 0000..9999 and
// +/-yyyyyy is in the range -999999..+999999 - // +/-yyyyyy is in the range -999999..+999999 -
...@@ -41,7 +41,8 @@ bool DateParser::Parse(Vector<Char> str, ...@@ -41,7 +41,8 @@ bool DateParser::Parse(Vector<Char> str,
// sss is in the range 000..999, // sss is in the range 000..999,
// hh is in the range 00..23, // hh is in the range 00..23,
// mm, ss, and sss default to 00 if missing, and // mm, ss, and sss default to 00 if missing, and
// timezone defaults to local time if missing. // timezone defaults to Z if missing
// (following Safari, ISO actually demands local time).
// Extensions: // Extensions:
// We also allow sss to have more or less than three digits (but at // We also allow sss to have more or less than three digits (but at
// least one). // least one).
...@@ -63,13 +64,15 @@ bool DateParser::Parse(Vector<Char> str, ...@@ -63,13 +64,15 @@ bool DateParser::Parse(Vector<Char> str,
// is allowed). // is allowed).
// Intersection of the two: // Intersection of the two:
// A string that matches both formats (e.g. 1970-01-01) will be // A string that matches both formats (e.g. 1970-01-01) will be
// parsed as an ES6 date-time string. // parsed as an ES5 date-time string - which means it will default
// After a valid "T" has been read while scanning an ES6 datetime string, // to UTC time-zone. That's unavoidable if following the ES5
// specification.
// After a valid "T" has been read while scanning an ES5 datetime string,
// the input can no longer be a valid legacy date, since the "T" is a // the input can no longer be a valid legacy date, since the "T" is a
// garbage string after a number has been read. // garbage string after a number has been read.
// First try getting as far as possible with as ES6 Date Time String. // First try getting as far as possible with as ES5 Date Time String.
DateToken next_unhandled_token = ParseES6DateTime(&scanner, &day, &time, &tz); DateToken next_unhandled_token = ParseES5DateTime(&scanner, &day, &time, &tz);
if (next_unhandled_token.IsInvalid()) return false; if (next_unhandled_token.IsInvalid()) return false;
bool has_read_number = !day.IsEmpty(); bool has_read_number = !day.IsEmpty();
// If there's anything left, continue with the legacy parser. // If there's anything left, continue with the legacy parser.
...@@ -217,10 +220,8 @@ bool DateParser::InputReader<Char>::SkipParentheses() { ...@@ -217,10 +220,8 @@ bool DateParser::InputReader<Char>::SkipParentheses() {
template <typename Char> template <typename Char>
DateParser::DateToken DateParser::ParseES6DateTime( DateParser::DateToken DateParser::ParseES5DateTime(
DateStringTokenizer<Char>* scanner, DateStringTokenizer<Char>* scanner, DayComposer* day, TimeComposer* time,
DayComposer* day,
TimeComposer* time,
TimeZoneComposer* tz) { TimeZoneComposer* tz) {
DCHECK(day->IsEmpty()); DCHECK(day->IsEmpty());
DCHECK(time->IsEmpty()); DCHECK(time->IsEmpty());
...@@ -255,7 +256,7 @@ DateParser::DateToken DateParser::ParseES6DateTime( ...@@ -255,7 +256,7 @@ DateParser::DateToken DateParser::ParseES6DateTime(
if (!scanner->Peek().IsKeywordType(TIME_SEPARATOR)) { if (!scanner->Peek().IsKeywordType(TIME_SEPARATOR)) {
if (!scanner->Peek().IsEndOfInput()) return scanner->Next(); if (!scanner->Peek().IsEndOfInput()) return scanner->Next();
} else { } else {
// ES6 Date Time String time part is present. // ES5 Date Time String time part is present.
scanner->Next(); scanner->Next();
if (!scanner->Peek().IsFixedLengthNumber(2) || if (!scanner->Peek().IsFixedLengthNumber(2) ||
!Between(scanner->Peek().number(), 0, 24)) { !Between(scanner->Peek().number(), 0, 24)) {
...@@ -321,7 +322,8 @@ DateParser::DateToken DateParser::ParseES6DateTime( ...@@ -321,7 +322,8 @@ DateParser::DateToken DateParser::ParseES6DateTime(
} }
if (!scanner->Peek().IsEndOfInput()) return DateToken::Invalid(); if (!scanner->Peek().IsEndOfInput()) return DateToken::Invalid();
} }
// Successfully parsed ES6 Date Time String. // Successfully parsed ES5 Date Time String. Default to UTC if no TZ given.
if (tz->IsEmpty()) tz->Set(0);
day->set_iso_date(); day->set_iso_date();
return DateToken::EndOfInput(); return DateToken::EndOfInput();
} }
......
...@@ -352,16 +352,14 @@ class DateParser : public AllStatic { ...@@ -352,16 +352,14 @@ class DateParser : public AllStatic {
bool is_iso_date_; bool is_iso_date_;
}; };
// Tries to parse an ES6 Date Time String. Returns the next token // Tries to parse an ES5 Date Time String. Returns the next token
// to continue with in the legacy date string parser. If parsing is // to continue with in the legacy date string parser. If parsing is
// complete, returns DateToken::EndOfInput(). If terminally unsuccessful, // complete, returns DateToken::EndOfInput(). If terminally unsuccessful,
// returns DateToken::Invalid(). Otherwise parsing continues in the // returns DateToken::Invalid(). Otherwise parsing continues in the
// legacy parser. // legacy parser.
template <typename Char> template <typename Char>
static DateParser::DateToken ParseES6DateTime( static DateParser::DateToken ParseES5DateTime(
DateStringTokenizer<Char>* scanner, DateStringTokenizer<Char>* scanner, DayComposer* day, TimeComposer* time,
DayComposer* day,
TimeComposer* time,
TimeZoneComposer* tz); TimeZoneComposer* tz);
}; };
......
...@@ -245,9 +245,9 @@ var testCasesES5Misc = [ ...@@ -245,9 +245,9 @@ var testCasesES5Misc = [
['2000-01T08:00:00.099Z', 946713600099], ['2000-01T08:00:00.099Z', 946713600099],
['2000-01T08:00:00.999Z', 946713600999], ['2000-01T08:00:00.999Z', 946713600999],
['2000-01T00:00:00.001-08:00', 946713600001], ['2000-01T00:00:00.001-08:00', 946713600001],
['2000-01-01T24:00Z', 946771200000], ['2000-01-01T24:00', 946771200000],
['2000-01-01T24:00:00Z', 946771200000], ['2000-01-01T24:00:00', 946771200000],
['2000-01-01T24:00:00.000Z', 946771200000], ['2000-01-01T24:00:00.000', 946771200000],
['2000-01-01T24:00:00.000Z', 946771200000]]; ['2000-01-01T24:00:00.000Z', 946771200000]];
var testCasesES5MiscNegative = [ var testCasesES5MiscNegative = [
......
...@@ -203,110 +203,110 @@ assertEquals(-8640000000000000, Date.UTC(1970, 0, 1 - 100000001, 24)); ...@@ -203,110 +203,110 @@ assertEquals(-8640000000000000, Date.UTC(1970, 0, 1 - 100000001, 24));
// Parsing ES5 ISO-8601 dates. // Parsing ES5 ISO-8601 dates.
// When TZ is omitted, it defaults to the local timezone // When TZ is omitted, it defaults to 'Z' meaning UTC.
// Check epoch. // Check epoch.
assertEquals(0, Date.parse("1970-01-01T00:00:00.000+00:00")); assertEquals(0, Date.parse("1970-01-01T00:00:00.000+00:00"));
assertEquals(0, Date.parse("1970-01-01T00:00:00.000-00:00")); assertEquals(0, Date.parse("1970-01-01T00:00:00.000-00:00"));
assertEquals(0, Date.parse("1970-01-01T00:00:00.000Z")); assertEquals(0, Date.parse("1970-01-01T00:00:00.000Z"));
assertEquals(0, Date.parse("1970-01-01T00:00:00.000Z")); assertEquals(0, Date.parse("1970-01-01T00:00:00.000"));
assertEquals(0, Date.parse("1970-01-01T00:00:00Z")); assertEquals(0, Date.parse("1970-01-01T00:00:00"));
assertEquals(0, Date.parse("1970-01-01T00:00Z")); assertEquals(0, Date.parse("1970-01-01T00:00"));
assertEquals(0, Date.parse("1970-01-01Z")); assertEquals(0, Date.parse("1970-01-01"));
assertEquals(0, Date.parse("1970-01T00:00:00.000+00:00")); assertEquals(0, Date.parse("1970-01T00:00:00.000+00:00"));
assertEquals(0, Date.parse("1970-01T00:00:00.000-00:00")); assertEquals(0, Date.parse("1970-01T00:00:00.000-00:00"));
assertEquals(0, Date.parse("1970-01T00:00:00.000Z")); assertEquals(0, Date.parse("1970-01T00:00:00.000Z"));
assertEquals(0, Date.parse("1970-01T00:00:00.000Z")); assertEquals(0, Date.parse("1970-01T00:00:00.000"));
assertEquals(0, Date.parse("1970-01T00:00:00Z")); assertEquals(0, Date.parse("1970-01T00:00:00"));
assertEquals(0, Date.parse("1970-01T00:00Z")); assertEquals(0, Date.parse("1970-01T00:00"));
assertEquals(0, Date.parse("1970-01Z")); assertEquals(0, Date.parse("1970-01"));
assertEquals(0, Date.parse("1970T00:00:00.000+00:00")); assertEquals(0, Date.parse("1970T00:00:00.000+00:00"));
assertEquals(0, Date.parse("1970T00:00:00.000-00:00")); assertEquals(0, Date.parse("1970T00:00:00.000-00:00"));
assertEquals(0, Date.parse("1970T00:00:00.000Z")); assertEquals(0, Date.parse("1970T00:00:00.000Z"));
assertEquals(0, Date.parse("1970T00:00:00.000Z")); assertEquals(0, Date.parse("1970T00:00:00.000"));
assertEquals(0, Date.parse("1970T00:00:00Z")); assertEquals(0, Date.parse("1970T00:00:00"));
assertEquals(0, Date.parse("1970T00:00Z")); assertEquals(0, Date.parse("1970T00:00"));
assertEquals(0, Date.parse("1970Z")); assertEquals(0, Date.parse("1970"));
assertEquals(0, Date.parse("+001970-01-01T00:00:00.000+00:00")); assertEquals(0, Date.parse("+001970-01-01T00:00:00.000+00:00"));
assertEquals(0, Date.parse("+001970-01-01T00:00:00.000-00:00")); assertEquals(0, Date.parse("+001970-01-01T00:00:00.000-00:00"));
assertEquals(0, Date.parse("+001970-01-01T00:00:00.000Z")); assertEquals(0, Date.parse("+001970-01-01T00:00:00.000Z"));
assertEquals(0, Date.parse("+001970-01-01T00:00:00.000Z")); assertEquals(0, Date.parse("+001970-01-01T00:00:00.000"));
assertEquals(0, Date.parse("+001970-01-01T00:00:00Z")); assertEquals(0, Date.parse("+001970-01-01T00:00:00"));
assertEquals(0, Date.parse("+001970-01-01T00:00Z")); assertEquals(0, Date.parse("+001970-01-01T00:00"));
assertEquals(0, Date.parse("+001970-01-01Z")); assertEquals(0, Date.parse("+001970-01-01"));
assertEquals(0, Date.parse("+001970-01T00:00:00.000+00:00")); assertEquals(0, Date.parse("+001970-01T00:00:00.000+00:00"));
assertEquals(0, Date.parse("+001970-01T00:00:00.000-00:00")); assertEquals(0, Date.parse("+001970-01T00:00:00.000-00:00"));
assertEquals(0, Date.parse("+001970-01T00:00:00.000Z")); assertEquals(0, Date.parse("+001970-01T00:00:00.000Z"));
assertEquals(0, Date.parse("+001970-01T00:00:00.000Z")); assertEquals(0, Date.parse("+001970-01T00:00:00.000"));
assertEquals(0, Date.parse("+001970-01T00:00:00Z")); assertEquals(0, Date.parse("+001970-01T00:00:00"));
assertEquals(0, Date.parse("+001970-01T00:00Z")); assertEquals(0, Date.parse("+001970-01T00:00"));
assertEquals(0, Date.parse("+001970-01Z")); assertEquals(0, Date.parse("+001970-01"));
assertEquals(0, Date.parse("+001970T00:00:00.000+00:00")); assertEquals(0, Date.parse("+001970T00:00:00.000+00:00"));
assertEquals(0, Date.parse("+001970T00:00:00.000-00:00")); assertEquals(0, Date.parse("+001970T00:00:00.000-00:00"));
assertEquals(0, Date.parse("+001970T00:00:00.000Z")); assertEquals(0, Date.parse("+001970T00:00:00.000Z"));
assertEquals(0, Date.parse("+001970T00:00:00.000Z")); assertEquals(0, Date.parse("+001970T00:00:00.000"));
assertEquals(0, Date.parse("+001970T00:00:00Z")); assertEquals(0, Date.parse("+001970T00:00:00"));
assertEquals(0, Date.parse("+001970T00:00Z")); assertEquals(0, Date.parse("+001970T00:00"));
assertEquals(0, Date.parse("+001970Z")); assertEquals(0, Date.parse("+001970"));
// Check random date. // Check random date.
assertEquals(70671003500, Date.parse("1972-03-28T23:50:03.500+01:00")); assertEquals(70671003500, Date.parse("1972-03-28T23:50:03.500+01:00"));
assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z"));
assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500"));
assertEquals(70674603000, Date.parse("1972-03-28T23:50:03Z")); assertEquals(70674603000, Date.parse("1972-03-28T23:50:03"));
assertEquals(70674600000, Date.parse("1972-03-28T23:50Z")); assertEquals(70674600000, Date.parse("1972-03-28T23:50"));
assertEquals(70588800000, Date.parse("1972-03-28Z")); assertEquals(70588800000, Date.parse("1972-03-28"));
assertEquals(68338203500, Date.parse("1972-03T23:50:03.500+01:00")); assertEquals(68338203500, Date.parse("1972-03T23:50:03.500+01:00"));
assertEquals(68341803500, Date.parse("1972-03T23:50:03.500Z")); assertEquals(68341803500, Date.parse("1972-03T23:50:03.500Z"));
assertEquals(68341803500, Date.parse("1972-03T23:50:03.500Z")); assertEquals(68341803500, Date.parse("1972-03T23:50:03.500"));
assertEquals(68341803000, Date.parse("1972-03T23:50:03Z")); assertEquals(68341803000, Date.parse("1972-03T23:50:03"));
assertEquals(68341800000, Date.parse("1972-03T23:50Z")); assertEquals(68341800000, Date.parse("1972-03T23:50"));
assertEquals(68256000000, Date.parse("1972-03Z")); assertEquals(68256000000, Date.parse("1972-03"));
assertEquals(63154203500, Date.parse("1972T23:50:03.500+01:00")); assertEquals(63154203500, Date.parse("1972T23:50:03.500+01:00"));
assertEquals(63157803500, Date.parse("1972T23:50:03.500Z")); assertEquals(63157803500, Date.parse("1972T23:50:03.500Z"));
assertEquals(63157803500, Date.parse("1972T23:50:03.500Z")); assertEquals(63157803500, Date.parse("1972T23:50:03.500"));
assertEquals(63157803000, Date.parse("1972T23:50:03Z")); assertEquals(63157803000, Date.parse("1972T23:50:03"));
assertEquals(63072000000, Date.parse("1972Z")); assertEquals(63072000000, Date.parse("1972"));
assertEquals(70671003500, Date.parse("+001972-03-28T23:50:03.500+01:00")); assertEquals(70671003500, Date.parse("+001972-03-28T23:50:03.500+01:00"));
assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500Z")); assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500Z"));
assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500Z")); assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500"));
assertEquals(70674603000, Date.parse("+001972-03-28T23:50:03Z")); assertEquals(70674603000, Date.parse("+001972-03-28T23:50:03"));
assertEquals(70674600000, Date.parse("+001972-03-28T23:50Z")); assertEquals(70674600000, Date.parse("+001972-03-28T23:50"));
assertEquals(70588800000, Date.parse("+001972-03-28Z")); assertEquals(70588800000, Date.parse("+001972-03-28"));
assertEquals(68338203500, Date.parse("+001972-03T23:50:03.500+01:00")); assertEquals(68338203500, Date.parse("+001972-03T23:50:03.500+01:00"));
assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500Z")); assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500Z"));
assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500Z")); assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500"));
assertEquals(68341803000, Date.parse("+001972-03T23:50:03Z")); assertEquals(68341803000, Date.parse("+001972-03T23:50:03"));
assertEquals(68341800000, Date.parse("+001972-03T23:50Z")); assertEquals(68341800000, Date.parse("+001972-03T23:50"));
assertEquals(68256000000, Date.parse("+001972-03Z")); assertEquals(68256000000, Date.parse("+001972-03"));
assertEquals(63154203500, Date.parse("+001972T23:50:03.500+01:00")); assertEquals(63154203500, Date.parse("+001972T23:50:03.500+01:00"));
assertEquals(63157803500, Date.parse("+001972T23:50:03.500Z")); assertEquals(63157803500, Date.parse("+001972T23:50:03.500Z"));
assertEquals(63157803500, Date.parse("+001972T23:50:03.500Z")); assertEquals(63157803500, Date.parse("+001972T23:50:03.500"));
assertEquals(63157803000, Date.parse("+001972T23:50:03Z")); assertEquals(63157803000, Date.parse("+001972T23:50:03"));
assertEquals(63072000000, Date.parse("+001972Z")); assertEquals(63072000000, Date.parse("+001972"));
// Ensure that ISO-years in the range 00-99 aren't translated to the range // Ensure that ISO-years in the range 00-99 aren't translated to the range
// 1950..2049. // 1950..2049.
assertEquals(-60904915200000, Date.parse("0040-01-01T00:00Z")); assertEquals(-60904915200000, Date.parse("0040-01-01"));
assertEquals(-60273763200000, Date.parse("0060-01-01T00:00Z")); assertEquals(-60273763200000, Date.parse("0060-01-01"));
assertEquals(-62167219200000, Date.parse("0000-01-01T00:00Z")); assertEquals(-62167219200000, Date.parse("0000-01-01"));
assertEquals(-62167219200000, Date.parse("+000000-01-01T00:00Z")); assertEquals(-62167219200000, Date.parse("+000000-01-01"));
// Test negative years. // Test negative years.
assertEquals(-63429523200000, Date.parse("-000040-01-01Z")); assertEquals(-63429523200000, Date.parse("-000040-01-01"));
assertEquals(-64060675200000, Date.parse("-000060-01-01Z")); assertEquals(-64060675200000, Date.parse("-000060-01-01"));
assertEquals(-124397510400000, Date.parse("-001972-01-01Z")); assertEquals(-124397510400000, Date.parse("-001972-01-01"));
// Check time-zones. // Check time-zones.
assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z"));
......
...@@ -245,6 +245,9 @@ ...@@ -245,6 +245,9 @@
'built-ins/Symbol/species/builtin-getter-name': [FAIL], 'built-ins/Symbol/species/builtin-getter-name': [FAIL],
'built-ins/Symbol/species/subclassing': [FAIL], 'built-ins/Symbol/species/subclassing': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4242
'built-ins/Date/15.9.1.15-1': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4002 # https://code.google.com/p/v8/issues/detail?id=4002
'built-ins/Error/prototype/S15.11.4_A2': [FAIL], 'built-ins/Error/prototype/S15.11.4_A2': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment