Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: src/dateparser-inl.h

Issue 1557053002: Accept time zones like GMT-8 in the legacy date parser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Test hours Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-422858.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/dateparser-inl.h
diff --git a/src/dateparser-inl.h b/src/dateparser-inl.h
index c1afb7d1b6e4352a3a547dc7bb9b65725b474cf6..7e5c4e355e1a9d6122241ddf7158048cea61c0cb 100644
--- a/src/dateparser-inl.h
+++ b/src/dateparser-inl.h
@@ -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) {
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-422858.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698