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

Side by Side 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, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-422858.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_DATEPARSER_INL_H_ 5 #ifndef V8_DATEPARSER_INL_H_
6 #define V8_DATEPARSER_INL_H_ 6 #define V8_DATEPARSER_INL_H_
7 7
8 #include "src/char-predicates-inl.h" 8 #include "src/char-predicates-inl.h"
9 #include "src/dateparser.h" 9 #include "src/dateparser.h"
10 #include "src/unicode-cache-inl.h" 10 #include "src/unicode-cache-inl.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (has_read_number) return false; 130 if (has_read_number) return false;
131 // The first number has to be separated from garbage words by 131 // The first number has to be separated from garbage words by
132 // whitespace or other separators. 132 // whitespace or other separators.
133 if (scanner.Peek().IsNumber()) return false; 133 if (scanner.Peek().IsNumber()) return false;
134 } 134 }
135 } else if (token.IsAsciiSign() && (tz.IsUTC() || !time.IsEmpty())) { 135 } else if (token.IsAsciiSign() && (tz.IsUTC() || !time.IsEmpty())) {
136 // Parse UTC offset (only after UTC or time). 136 // Parse UTC offset (only after UTC or time).
137 tz.SetSign(token.ascii_sign()); 137 tz.SetSign(token.ascii_sign());
138 // The following number may be empty. 138 // The following number may be empty.
139 int n = 0; 139 int n = 0;
140 int length = 0;
140 if (scanner.Peek().IsNumber()) { 141 if (scanner.Peek().IsNumber()) {
141 n = scanner.Next().number(); 142 DateToken token = scanner.Next();
143 length = token.length();
144 n = token.number();
142 } 145 }
143 has_read_number = true; 146 has_read_number = true;
144 147
145 if (scanner.Peek().IsSymbol(':')) { 148 if (scanner.Peek().IsSymbol(':')) {
146 tz.SetAbsoluteHour(n); 149 tz.SetAbsoluteHour(n);
150 // TODO(littledan): Use minutes as part of timezone?
147 tz.SetAbsoluteMinute(kNone); 151 tz.SetAbsoluteMinute(kNone);
148 } else { 152 } else if (length == 2 || length == 1) {
153 // Handle time zones like GMT-8
154 tz.SetAbsoluteHour(n);
155 tz.SetAbsoluteMinute(0);
156 } else if (length == 4 || length == 3) {
157 // Looks like the hhmm format
149 tz.SetAbsoluteHour(n / 100); 158 tz.SetAbsoluteHour(n / 100);
150 tz.SetAbsoluteMinute(n % 100); 159 tz.SetAbsoluteMinute(n % 100);
160 } else {
161 // No need to accept time zones like GMT-12345
162 return false;
151 } 163 }
152 } else if ((token.IsAsciiSign() || token.IsSymbol(')')) && 164 } else if ((token.IsAsciiSign() || token.IsSymbol(')')) &&
153 has_read_number) { 165 has_read_number) {
154 // Extra sign or ')' is illegal if a number has been read. 166 // Extra sign or ')' is illegal if a number has been read.
155 return false; 167 return false;
156 } else { 168 } else {
157 // Ignore other characters and whitespace. 169 // Ignore other characters and whitespace.
158 } 170 }
159 } 171 }
160 172
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 if (tz->IsEmpty()) tz->Set(0); 338 if (tz->IsEmpty()) tz->Set(0);
327 day->set_iso_date(); 339 day->set_iso_date();
328 return DateToken::EndOfInput(); 340 return DateToken::EndOfInput();
329 } 341 }
330 342
331 343
332 } // namespace internal 344 } // namespace internal
333 } // namespace v8 345 } // namespace v8
334 346
335 #endif // V8_DATEPARSER_INL_H_ 347 #endif // V8_DATEPARSER_INL_H_
OLDNEW
« 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