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

Side by Side Diff: src/dateparser-inl.h

Issue 1229903004: Make dates default to the local timezone if none specified (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test Created 5 years, 5 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/date.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/dateparser.h" 8 #include "src/dateparser.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 template <typename Char> 13 template <typename Char>
14 bool DateParser::Parse(Vector<Char> str, 14 bool DateParser::Parse(Vector<Char> str,
15 FixedArray* out, 15 FixedArray* out,
16 UnicodeCache* unicode_cache) { 16 UnicodeCache* unicode_cache) {
17 DCHECK(out->length() >= OUTPUT_SIZE); 17 DCHECK(out->length() >= OUTPUT_SIZE);
18 InputReader<Char> in(unicode_cache, str); 18 InputReader<Char> in(unicode_cache, str);
19 DateStringTokenizer<Char> scanner(&in); 19 DateStringTokenizer<Char> scanner(&in);
20 TimeZoneComposer tz; 20 TimeZoneComposer tz;
21 TimeComposer time; 21 TimeComposer time;
22 DayComposer day; 22 DayComposer day;
23 23
24 // Specification: 24 // Specification:
25 // Accept ES5 ISO 8601 date-time-strings or legacy dates compatible 25 // Accept ES5 ISO 8601 date-time-strings or legacy dates compatible
ulan 2015/07/24 13:56:25 Please update this comment to ES6.
hichris123 2015/07/24 15:10:04 Done.
26 // with Safari. 26 // with Safari.
27 // ES5 ISO 8601 dates: 27 // ES5 ISO 8601 dates:
28 // [('-'|'+')yy]yyyy[-MM[-DD]][THH:mm[:ss[.sss]][Z|(+|-)hh:mm]] 28 // [('-'|'+')yy]yyyy[-MM[-DD]][THH:mm[:ss[.sss]][Z|(+|-)hh:mm]]
29 // where yyyy is in the range 0000..9999 and 29 // where yyyy is in the range 0000..9999 and
30 // +/-yyyyyy is in the range -999999..+999999 - 30 // +/-yyyyyy is in the range -999999..+999999 -
31 // but -000000 is invalid (year zero must be positive), 31 // but -000000 is invalid (year zero must be positive),
32 // MM is in the range 01..12, 32 // MM is in the range 01..12,
33 // DD is in the range 01..31, 33 // DD is in the range 01..31,
34 // MM and DD defaults to 01 if missing,, 34 // MM and DD defaults to 01 if missing,,
35 // HH is generally in the range 00..23, but can be 24 if mm, ss 35 // HH is generally in the range 00..23, but can be 24 if mm, ss
36 // and sss are zero (or missing), representing midnight at the 36 // and sss are zero (or missing), representing midnight at the
37 // end of a day, 37 // end of a day,
38 // mm and ss are in the range 00..59, 38 // mm and ss are in the range 00..59,
39 // sss is in the range 000..999, 39 // sss is in the range 000..999,
40 // hh is in the range 00..23, 40 // hh is in the range 00..23,
41 // mm, ss, and sss default to 00 if missing, and 41 // mm, ss, and sss default to 00 if missing, and
42 // timezone defaults to Z if missing 42 // timezone defaults to local time if missing
43 // (following Safari, ISO actually demands local time). 43 // (following the ES6 standard vs. ES5).
ulan 2015/07/24 13:56:25 We can now drop the part in parenthesis.
hichris123 2015/07/24 15:10:04 Done.
44 // Extensions: 44 // Extensions:
45 // We also allow sss to have more or less than three digits (but at 45 // We also allow sss to have more or less than three digits (but at
46 // least one). 46 // least one).
47 // We allow hh:mm to be specified as hhmm. 47 // We allow hh:mm to be specified as hhmm.
48 // Legacy dates: 48 // Legacy dates:
49 // Any unrecognized word before the first number is ignored. 49 // Any unrecognized word before the first number is ignored.
50 // Parenthesized text is ignored. 50 // Parenthesized text is ignored.
51 // An unsigned number followed by ':' is a time value, and is 51 // An unsigned number followed by ':' is a time value, and is
52 // added to the TimeComposer. A number followed by '::' adds a second 52 // added to the TimeComposer. A number followed by '::' adds a second
53 // zero as well. A number followed by '.' is also a time and must be 53 // zero as well. A number followed by '.' is also a time and must be
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (!scanner->SkipSymbol(':')) return DateToken::Invalid(); 292 if (!scanner->SkipSymbol(':')) return DateToken::Invalid();
293 if (!scanner->Peek().IsFixedLengthNumber(2) || 293 if (!scanner->Peek().IsFixedLengthNumber(2) ||
294 !TimeComposer::IsMinute(scanner->Peek().number())) { 294 !TimeComposer::IsMinute(scanner->Peek().number())) {
295 return DateToken::Invalid(); 295 return DateToken::Invalid();
296 } 296 }
297 tz->SetAbsoluteMinute(scanner->Next().number()); 297 tz->SetAbsoluteMinute(scanner->Next().number());
298 } 298 }
299 } 299 }
300 if (!scanner->Peek().IsEndOfInput()) return DateToken::Invalid(); 300 if (!scanner->Peek().IsEndOfInput()) return DateToken::Invalid();
301 } 301 }
302 // Successfully parsed ES5 Date Time String. Default to UTC if no TZ given. 302 // Successfully parsed ES5 Date Time String.
303 if (tz->IsEmpty()) tz->Set(0);
304 day->set_iso_date(); 303 day->set_iso_date();
305 return DateToken::EndOfInput(); 304 return DateToken::EndOfInput();
306 } 305 }
307 306
308 307
309 } } // namespace v8::internal 308 } } // namespace v8::internal
310 309
311 #endif // V8_DATEPARSER_INL_H_ 310 #endif // V8_DATEPARSER_INL_H_
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/date.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698