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

Side by Side Diff: frog/leg/lib/mockimpl.dart

Issue 9466048: Implement (subset of) ISO 8601 for date-reading. Fix other bugs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add assert. Created 8 years, 9 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
« no previous file with comments | « no previous file | frog/lib/date_implementation.dart » ('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 (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
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 // Always try to read in (a subset of) ISO 8601 first. If that fails fall
240 value = Primitives.valueFromDateString(formattedString) { 240 // back to JavaScript's implementation.
ngeoffray 2012/02/27 17:05:41 Please explain why you're doing this.
floitsch 2012/02/27 18:05:27 Done.
241 _asJs(); 241 final RegExp re =
242 const RegExp(@'^([+-]?\d?\d\d\d\d)-?(\d\d)-?(\d\d) (\d\d):(\d\d):(\d\d)( ?:.(\d{1,3}))? ?([zZ]?)$');
243 Match match = re.firstMatch(formattedString);
244 if (match !== null) {
245 int years = Math.parseInt(match[1]);
246 int month = Math.parseInt(match[2]);
247 int day = Math.parseInt(match[3]);
248 int hours = Math.parseInt(match[4]);
249 int minutes = Math.parseInt(match[5]);
250 int seconds = Math.parseInt(match[6]);
251 int milliseconds = 0;
252 if (match[7] !== null) {
253 milliseconds = Math.parseInt(match[7]);
254 if (match[7].length == 1) {
255 milliseconds *= 100;
256 } else if (match[7].length == 2) {
257 milliseconds *= 10;
258 } else {
259 assert(match[7].length == 3);
260 }
261 }
262 bool isUtc = match[8] !== null;
263 TimeZone timezone = isUtc ? const TimeZone.utc() : new TimeZone.local();
264 return new DateImplementation.withTimeZone(
265 years, month, day, hours, minutes, seconds, milliseconds, timezone);
266 } else {
267 return new DateImplementation.fromEpoch(formattedString,
268 new TimeZone.local());
269 }
242 } 270 }
243 271
244 const DateImplementation.fromEpoch(this.value, this.timeZone); 272 const DateImplementation.fromEpoch(this.value, this.timeZone);
245 273
246 bool operator ==(other) { 274 bool operator ==(other) {
247 if (!(other is DateImplementation)) return false; 275 if (!(other is DateImplementation)) return false;
248 return (value == other.value) && (timeZone == other.timeZone); 276 return (value == other.value) && (timeZone == other.timeZone);
249 } 277 }
250 278
251 int compareTo(Date other) { 279 int compareTo(Date other) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 418 }
391 String twoDigitMinutes = 419 String twoDigitMinutes =
392 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); 420 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR));
393 String twoDigitSeconds = 421 String twoDigitSeconds =
394 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); 422 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE));
395 String threeDigitMs = 423 String threeDigitMs =
396 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); 424 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND));
397 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}"; 425 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}";
398 } 426 }
399 } 427 }
OLDNEW
« no previous file with comments | « no previous file | frog/lib/date_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698