OLD | NEW |
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 Loading... |
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 Loading... |
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_ |
OLD | NEW |