Index: src/dateparser-inl.h |
diff --git a/src/dateparser-inl.h b/src/dateparser-inl.h |
index 5b3ac46025f05b09ae944c0cac42f95d7b6e3809..c1afb7d1b6e4352a3a547dc7bb9b65725b474cf6 100644 |
--- a/src/dateparser-inl.h |
+++ b/src/dateparser-inl.h |
@@ -24,9 +24,9 @@ bool DateParser::Parse(Vector<Char> str, |
DayComposer day; |
// 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. |
- // ES6 ISO 8601 dates: |
+ // ES5 ISO 8601 dates: |
// [('-'|'+')yy]yyyy[-MM[-DD]][THH:mm[:ss[.sss]][Z|(+|-)hh:mm]] |
// where yyyy is in the range 0000..9999 and |
// +/-yyyyyy is in the range -999999..+999999 - |
@@ -41,7 +41,8 @@ bool DateParser::Parse(Vector<Char> str, |
// sss is in the range 000..999, |
// hh is in the range 00..23, |
// 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: |
// We also allow sss to have more or less than three digits (but at |
// least one). |
@@ -63,13 +64,15 @@ bool DateParser::Parse(Vector<Char> str, |
// is allowed). |
// Intersection of the two: |
// A string that matches both formats (e.g. 1970-01-01) will be |
- // parsed as an ES6 date-time string. |
- // After a valid "T" has been read while scanning an ES6 datetime string, |
+ // parsed as an ES5 date-time string - which means it will default |
+ // 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 |
// garbage string after a number has been read. |
- // First try getting as far as possible with as ES6 Date Time String. |
- DateToken next_unhandled_token = ParseES6DateTime(&scanner, &day, &time, &tz); |
+ // First try getting as far as possible with as ES5 Date Time String. |
+ DateToken next_unhandled_token = ParseES5DateTime(&scanner, &day, &time, &tz); |
if (next_unhandled_token.IsInvalid()) return false; |
bool has_read_number = !day.IsEmpty(); |
// If there's anything left, continue with the legacy parser. |
@@ -217,10 +220,8 @@ bool DateParser::InputReader<Char>::SkipParentheses() { |
template <typename Char> |
-DateParser::DateToken DateParser::ParseES6DateTime( |
- DateStringTokenizer<Char>* scanner, |
- DayComposer* day, |
- TimeComposer* time, |
+DateParser::DateToken DateParser::ParseES5DateTime( |
+ DateStringTokenizer<Char>* scanner, DayComposer* day, TimeComposer* time, |
TimeZoneComposer* tz) { |
DCHECK(day->IsEmpty()); |
DCHECK(time->IsEmpty()); |
@@ -255,7 +256,7 @@ DateParser::DateToken DateParser::ParseES6DateTime( |
if (!scanner->Peek().IsKeywordType(TIME_SEPARATOR)) { |
if (!scanner->Peek().IsEndOfInput()) return scanner->Next(); |
} else { |
- // ES6 Date Time String time part is present. |
+ // ES5 Date Time String time part is present. |
scanner->Next(); |
if (!scanner->Peek().IsFixedLengthNumber(2) || |
!Between(scanner->Peek().number(), 0, 24)) { |
@@ -321,7 +322,8 @@ DateParser::DateToken DateParser::ParseES6DateTime( |
} |
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(); |
return DateToken::EndOfInput(); |
} |