Commit acbd64be authored by littledan's avatar littledan Committed by Commit bot

Accept time zones like GMT-8 in the legacy date parser

In the Date constructor or Date.parse, other browsers will accept time
zones like GMT-8, but before this patch, Chrome would interpret 8 as
8 minutes. This patch interprets GMT-+ a one or two digit number as hours,
not minutes.

R=adamk,jshin@chromium.org
LOG=Y
BUG=chromium:422858

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

Cr-Commit-Position: refs/heads/master@{#33100}
parent 918e66d5
......@@ -137,17 +137,29 @@ bool DateParser::Parse(Vector<Char> str,
tz.SetSign(token.ascii_sign());
// The following number may be empty.
int n = 0;
int length = 0;
if (scanner.Peek().IsNumber()) {
n = scanner.Next().number();
DateToken token = scanner.Next();
length = token.length();
n = token.number();
}
has_read_number = true;
if (scanner.Peek().IsSymbol(':')) {
tz.SetAbsoluteHour(n);
// TODO(littledan): Use minutes as part of timezone?
tz.SetAbsoluteMinute(kNone);
} else {
} else if (length == 2 || length == 1) {
// Handle time zones like GMT-8
tz.SetAbsoluteHour(n);
tz.SetAbsoluteMinute(0);
} else if (length == 4 || length == 3) {
// Looks like the hhmm format
tz.SetAbsoluteHour(n / 100);
tz.SetAbsoluteMinute(n % 100);
} else {
// No need to accept time zones like GMT-12345
return false;
}
} else if ((token.IsAsciiSign() || token.IsSymbol(')')) &&
has_read_number) {
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var date = new Date("2016/01/02 10:00 GMT-8")
assertEquals(0, date.getMinutes());
assertEquals(18, date.getUTCHours());
date = new Date("2016/01/02 10:00 GMT-12")
assertEquals(0, date.getMinutes());
assertEquals(22, date.getUTCHours());
date = new Date("2016/01/02 10:00 GMT-123")
assertEquals(23, date.getMinutes());
assertEquals(11, date.getUTCHours());
date = new Date("2016/01/02 10:00 GMT-0856")
assertEquals(56, date.getMinutes());
assertEquals(18, date.getUTCHours());
date = new Date("2016/01/02 10:00 GMT-08000")
assertEquals(NaN, date.getMinutes());
assertEquals(NaN, date.getUTCHours());
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