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

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

Issue 1704016: Added support for ES5 date time string format to Date.parse. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 int n = in.ReadUnsignedNumber(); 47 int n = in.ReadUnsignedNumber();
48 if (in.Skip(':')) { 48 if (in.Skip(':')) {
49 if (in.Skip(':')) { 49 if (in.Skip(':')) {
50 // n + "::" 50 // n + "::"
51 if (!time.IsEmpty()) return false; 51 if (!time.IsEmpty()) return false;
52 time.Add(n); 52 time.Add(n);
53 time.Add(0); 53 time.Add(0);
54 } else { 54 } else {
55 // n + ":" 55 // n + ":"
56 if (!time.Add(n)) return false; 56 if (!time.Add(n)) return false;
57 in.Skip('.');
57 } 58 }
59 } else if (in.Skip('.') && time.IsExpecting(n)) {
60 time.Add(n);
61 if (!in.IsAsciiDigit()) return false;
62 int n = in.ReadUnsignedNumber();
63 time.AddFinal(n);
58 } else if (tz.IsExpecting(n)) { 64 } else if (tz.IsExpecting(n)) {
59 tz.SetAbsoluteMinute(n); 65 tz.SetAbsoluteMinute(n);
60 } else if (time.IsExpecting(n)) { 66 } else if (time.IsExpecting(n)) {
61 time.AddFinal(n); 67 time.AddFinal(n);
62 // Require end or white space immediately after finalizing time. 68 // Require end, white space or Z immediately after finalizing time.
63 if (!in.IsEnd() && !in.SkipWhiteSpace()) return false; 69 if (!in.IsEnd() && !in.SkipWhiteSpace() && !in.Is('Z')) return false;
64 } else { 70 } else {
65 if (!day.Add(n)) return false; 71 if (!day.Add(n)) return false;
66 in.Skip('-'); // Ignore suffix '-' for year, month, or day. 72 in.Skip('-'); // Ignore suffix '-' for year, month, or day.
73 // Skip trailing 'T' for ECMAScript 5 date string format but make
74 // sure that it is followed by a digit (for the time).
75 if (in.Skip('T') && !in.IsAsciiDigit()) return false;
67 } 76 }
68 } else if (in.IsAsciiAlphaOrAbove()) { 77 } else if (in.IsAsciiAlphaOrAbove()) {
69 // Parse a "word" (sequence of chars. >= 'A'). 78 // Parse a "word" (sequence of chars. >= 'A').
70 uint32_t pre[KeywordTable::kPrefixLength]; 79 uint32_t pre[KeywordTable::kPrefixLength];
71 int len = in.ReadWord(pre, KeywordTable::kPrefixLength); 80 int len = in.ReadWord(pre, KeywordTable::kPrefixLength);
72 int index = KeywordTable::Lookup(pre, len); 81 int index = KeywordTable::Lookup(pre, len);
73 KeywordType type = KeywordTable::GetType(index); 82 KeywordType type = KeywordTable::GetType(index);
74 83
75 if (type == AM_PM && !time.IsEmpty()) { 84 if (type == AM_PM && !time.IsEmpty()) {
76 time.SetHourOffset(KeywordTable::GetValue(index)); 85 time.SetHourOffset(KeywordTable::GetValue(index));
(...skipping 28 matching lines...) Expand all
105 // Ignore other characters. 114 // Ignore other characters.
106 in.Next(); 115 in.Next();
107 } 116 }
108 } 117 }
109 return day.Write(out) && time.Write(out) && tz.Write(out); 118 return day.Write(out) && time.Write(out) && tz.Write(out);
110 } 119 }
111 120
112 } } // namespace v8::internal 121 } } // namespace v8::internal
113 122
114 #endif // V8_DATEPARSER_INL_H_ 123 #endif // V8_DATEPARSER_INL_H_
OLDNEW
« no previous file with comments | « src/dateparser.cc ('k') | test/mjsunit/date-parse.js » ('j') | test/mjsunit/date-parse.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698