OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Mocks of classes and interfaces that Leg cannot read directly. | 5 // Mocks of classes and interfaces that Leg cannot read directly. |
6 | 6 |
7 // TODO(ahe): Remove this file. | 7 // TODO(ahe): Remove this file. |
8 | 8 |
9 class JSSyntaxRegExp implements RegExp { | 9 class JSSyntaxRegExp implements RegExp { |
10 final String pattern; | 10 final String pattern; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 timeZone.isUtc) { | 228 timeZone.isUtc) { |
229 _asJs(); | 229 _asJs(); |
230 } | 230 } |
231 | 231 |
232 DateImplementation.now() | 232 DateImplementation.now() |
233 : timeZone = new TimeZone.local(), | 233 : timeZone = new TimeZone.local(), |
234 value = Primitives.dateNow() { | 234 value = Primitives.dateNow() { |
235 _asJs(); | 235 _asJs(); |
236 } | 236 } |
237 | 237 |
238 DateImplementation.fromString(String formattedString) | 238 factory DateImplementation.fromString(String formattedString) { |
239 : timeZone = new TimeZone.local(), | 239 // JavaScript's parse function is not specified and there are differences |
240 value = Primitives.valueFromDateString(formattedString) { | 240 // between the different implementations. Make sure we can at least read in |
241 _asJs(); | 241 // Dart's output: try to read in (a subset of) ISO 8601 first. If that fails |
| 242 // fall back to JavaScript's implementation. |
| 243 final RegExp re = |
| 244 const RegExp(@'^([+-]?\d?\d\d\d\d)-?(\d\d)-?(\d\d) (\d\d):(\d\d):(\d\d)(
?:.(\d{1,3}))? ?([zZ]?)$'); |
| 245 Match match = re.firstMatch(formattedString); |
| 246 if (match !== null) { |
| 247 int years = Math.parseInt(match[1]); |
| 248 int month = Math.parseInt(match[2]); |
| 249 int day = Math.parseInt(match[3]); |
| 250 int hours = Math.parseInt(match[4]); |
| 251 int minutes = Math.parseInt(match[5]); |
| 252 int seconds = Math.parseInt(match[6]); |
| 253 int milliseconds = 0; |
| 254 if (match[7] !== null) { |
| 255 milliseconds = Math.parseInt(match[7]); |
| 256 if (match[7].length == 1) { |
| 257 milliseconds *= 100; |
| 258 } else if (match[7].length == 2) { |
| 259 milliseconds *= 10; |
| 260 } else { |
| 261 assert(match[7].length == 3); |
| 262 } |
| 263 } |
| 264 bool isUtc = match[8] !== null; |
| 265 TimeZone timezone = isUtc ? const TimeZone.utc() : new TimeZone.local(); |
| 266 return new DateImplementation.withTimeZone( |
| 267 years, month, day, hours, minutes, seconds, milliseconds, timezone); |
| 268 } else { |
| 269 return new DateImplementation.fromEpoch(formattedString, |
| 270 new TimeZone.local()); |
| 271 } |
242 } | 272 } |
243 | 273 |
244 const DateImplementation.fromEpoch(this.value, this.timeZone); | 274 const DateImplementation.fromEpoch(this.value, this.timeZone); |
245 | 275 |
246 bool operator ==(other) { | 276 bool operator ==(other) { |
247 if (!(other is DateImplementation)) return false; | 277 if (!(other is DateImplementation)) return false; |
248 return (value == other.value) && (timeZone == other.timeZone); | 278 return (value == other.value) && (timeZone == other.timeZone); |
249 } | 279 } |
250 | 280 |
251 int compareTo(Date other) { | 281 int compareTo(Date other) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 420 } |
391 String twoDigitMinutes = | 421 String twoDigitMinutes = |
392 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); | 422 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); |
393 String twoDigitSeconds = | 423 String twoDigitSeconds = |
394 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); | 424 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); |
395 String threeDigitMs = | 425 String threeDigitMs = |
396 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); | 426 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); |
397 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}"; | 427 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}"; |
398 } | 428 } |
399 } | 429 } |
OLD | NEW |