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

Side by Side Diff: tests/corelib/src/DateTimeTest.dart

Issue 9568011: Unify Date.fromString and support more Iso 8601. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve parseInt. 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
« runtime/lib/date.dart ('K') | « runtime/lib/date.dart ('k') | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Dart test program for Date. 5 // Dart test program for Date.
6 6
7 class DateTest { 7 class DateTest {
8 // Tests if the time moves eventually forward. 8 // Tests if the time moves eventually forward.
9 static void testNow() { 9 static void testNow() {
10 var t1 = new Date.now(); 10 var t1 = new Date.now();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 dt3 = new Date.withTimeZone(2011, 5, dt1.day, 270 dt3 = new Date.withTimeZone(2011, 5, dt1.day,
271 dt1.hours, dt1.minutes, 35, 0, 271 dt1.hours, dt1.minutes, 35, 0,
272 new TimeZone.local()); 272 new TimeZone.local());
273 Expect.equals(dt2.value, dt3.value); 273 Expect.equals(dt2.value, dt3.value);
274 Expect.equals(true, dt2 == dt3); 274 Expect.equals(true, dt2 == dt3);
275 dt1 = new Date.fromEpoch(-9999999, const TimeZone.utc()); 275 dt1 = new Date.fromEpoch(-9999999, const TimeZone.utc());
276 dt3 = new Date.withTimeZone( 276 dt3 = new Date.withTimeZone(
277 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 277 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
278 dt1.seconds, dt1.milliseconds, const TimeZone.utc()); 278 dt1.seconds, dt1.milliseconds, const TimeZone.utc());
279 Expect.equals(dt1.value, dt3.value); 279 Expect.equals(dt1.value, dt3.value);
280 dt3 = new Date.withTimeZone(99, 1, 2, 10, 11, 12, 0,
281 const TimeZone.utc());
282 Expect.equals(99, dt3.year);
283 Expect.equals(1, dt3.month);
284 Expect.equals(2, dt3.day);
285 Expect.equals(10, dt3.hours);
286 Expect.equals(11, dt3.minutes);
287 Expect.equals(12, dt3.seconds);
288 Expect.equals(0, dt3.milliseconds);
289 Expect.equals(true, dt3.isUtc());
280 } 290 }
281 291
282 static void testChangeTimeZone() { 292 static void testChangeTimeZone() {
283 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local()); 293 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local());
284 var dt2 = dt1.changeTimeZone(const TimeZone.utc()); 294 var dt2 = dt1.changeTimeZone(const TimeZone.utc());
285 Expect.equals(dt1.value, dt2.value); 295 Expect.equals(dt1.value, dt2.value);
286 var dt3 = new Date.fromEpoch(1305140315000, const TimeZone.utc()); 296 var dt3 = new Date.fromEpoch(1305140315000, const TimeZone.utc());
287 Expect.equals(dt1.value, dt3.value); 297 Expect.equals(dt1.value, dt3.value);
288 Expect.equals(dt2.year, dt3.year); 298 Expect.equals(dt2.year, dt3.year);
289 Expect.equals(dt2.month, dt3.month); 299 Expect.equals(dt2.month, dt3.month);
(...skipping 27 matching lines...) Expand all
317 3 * Duration.MILLISECONDS_PER_SECOND + 5)); 327 3 * Duration.MILLISECONDS_PER_SECOND + 5));
318 Expect.equals(true, dt1 == dt3); 328 Expect.equals(true, dt1 == dt3);
319 Expect.equals(false, dt1 == dt2); 329 Expect.equals(false, dt1 == dt2);
320 } 330 }
321 331
322 static void testDateStrings() { 332 static void testDateStrings() {
323 // TODO(floitsch): Clean up the Date API that deals with strings. 333 // TODO(floitsch): Clean up the Date API that deals with strings.
324 var dt1 = new Date.fromString("2011-05-11 18:58:35Z"); 334 var dt1 = new Date.fromString("2011-05-11 18:58:35Z");
325 Expect.equals(1305140315000, dt1.value); 335 Expect.equals(1305140315000, dt1.value);
326 Expect.isTrue(dt1.isUtc()); 336 Expect.isTrue(dt1.isUtc());
337 dt1 = new Date.fromString("20110511 18:58:35z");
338 Expect.equals(1305140315000, dt1.value);
339 Expect.isTrue(dt1.isUtc());
340 dt1 = new Date.fromString("+20110511 18:58:35z");
341 Expect.equals(1305140315000, dt1.value);
342 Expect.isTrue(dt1.isUtc());
327 var str = dt1.toString(); 343 var str = dt1.toString();
328 var dt2 = new Date.fromString(str); 344 var dt2 = new Date.fromString(str);
329 Expect.equals(true, dt1 == dt2); 345 Expect.equals(true, dt1 == dt2);
330 var dt3 = dt1.changeTimeZone(const TimeZone.utc()); 346 var dt3 = dt1.changeTimeZone(const TimeZone.utc());
331 str = dt3.toString(); 347 str = dt3.toString();
332 Expect.equals("2011-05-11 18:58:35.000Z", str); 348 Expect.equals("2011-05-11 18:58:35.000Z", str);
349 var dt4 = new Date.fromString("-1234-01-01 00:00:00Z");
350 Expect.equals(-1234, dt4.year);
351 Expect.equals(1, dt4.month);
352 Expect.equals(1, dt4.day);
353 Expect.equals(0, dt4.hours);
354 Expect.equals(0, dt4.minutes);
355 Expect.equals(0, dt4.seconds);
356 Expect.equals(0, dt4.milliseconds);
357 Expect.isTrue(dt4.isUtc());
358 var dt5 = new Date.fromString("0099-01-02");
359 Expect.equals(99, dt5.year);
360 Expect.equals(1, dt5.month);
361 Expect.equals(2, dt5.day);
362 Expect.equals(0, dt5.hours);
363 Expect.equals(0, dt5.minutes);
364 Expect.equals(0, dt5.seconds);
365 Expect.equals(0, dt5.milliseconds);
366 Expect.isFalse(dt5.isUtc());
367 var dt6 = new Date.fromString("2012-01-01 00:00:10.012");
368 Expect.equals(12, dt6.milliseconds);
369 dt6 = new Date.fromString("2012-01-01 00:00:10.003");
370 Expect.equals(3, dt6.milliseconds);
371 dt6 = new Date.fromString("2012-01-01 00:00:10.5");
372 Expect.equals(500, dt6.milliseconds);
373 dt6 = new Date.fromString("2012-01-01 00:00:10.003Z");
374 Expect.equals(3, dt6.milliseconds);
375 dt6 = new Date.fromString("2012-01-01 00:00:10.5z");
376 Expect.equals(500, dt6.milliseconds);
377 var dt7 = new Date.fromString("2011-05-11T18:58:35Z");
378 Expect.equals(1305140315000, dt7.value);
379 var dt8 = new Date.fromString("-1234-01-01T00:00:00Z");
380 Expect.equals(-1234, dt8.year);
381 Expect.equals(1, dt8.month);
382 Expect.equals(1, dt8.day);
383 Expect.equals(0, dt8.hours);
384 Expect.equals(0, dt8.minutes);
385 Expect.equals(0, dt8.seconds);
386 Expect.equals(0, dt8.milliseconds);
387 Expect.isTrue(dt8.isUtc());
388 var dt9 = new Date.fromString("-1234-01-01T00:00:00");
389 Expect.equals(-1234, dt9.year);
390 Expect.equals(1, dt9.month);
391 Expect.equals(1, dt9.day);
392 Expect.equals(0, dt9.hours);
393 Expect.equals(0, dt9.minutes);
394 Expect.equals(0, dt9.seconds);
395 Expect.equals(0, dt9.milliseconds);
396 Expect.isFalse(dt9.isUtc());
397 var dt10 = new Date.fromString("-12340101");
398 Expect.equals(-1234, dt10.year);
399 Expect.equals(1, dt10.month);
400 Expect.equals(1, dt10.day);
401 Expect.equals(0, dt10.hours);
402 Expect.equals(0, dt10.minutes);
403 Expect.equals(0, dt10.seconds);
404 Expect.equals(0, dt10.milliseconds);
405 Expect.isFalse(dt10.isUtc());
406 dt1 = new Date.fromString("2012-02-27 13:27:00");
407 Expect.equals(2012, dt1.year);
408 Expect.equals(2, dt1.month);
409 Expect.equals(27, dt1.day);
410 Expect.equals(13, dt1.hours);
411 Expect.equals(27, dt1.minutes);
412 Expect.equals(0, dt1.seconds);
413 Expect.equals(0, dt1.milliseconds);
414 Expect.equals(false, dt1.isUtc());
415 dt1 = new Date.fromString("2012-02-27 13:27:00.423z");
416 Expect.equals(2012, dt1.year);
417 Expect.equals(2, dt1.month);
418 Expect.equals(27, dt1.day);
419 Expect.equals(13, dt1.hours);
420 Expect.equals(27, dt1.minutes);
421 Expect.equals(0, dt1.seconds);
422 Expect.equals(423, dt1.milliseconds);
423 Expect.equals(true, dt1.isUtc());
424 dt1 = new Date.fromString("20120227 13:27:00");
425 Expect.equals(2012, dt1.year);
426 Expect.equals(2, dt1.month);
427 Expect.equals(27, dt1.day);
428 Expect.equals(13, dt1.hours);
429 Expect.equals(27, dt1.minutes);
430 Expect.equals(0, dt1.seconds);
431 Expect.equals(0, dt1.milliseconds);
432 Expect.equals(false, dt1.isUtc());
433 dt1 = new Date.fromString("20120227T132700");
434 Expect.equals(2012, dt1.year);
435 Expect.equals(2, dt1.month);
436 Expect.equals(27, dt1.day);
437 Expect.equals(13, dt1.hours);
438 Expect.equals(27, dt1.minutes);
439 Expect.equals(0, dt1.seconds);
440 Expect.equals(0, dt1.milliseconds);
441 Expect.equals(false, dt1.isUtc());
442 dt1 = new Date.fromString("20120227");
443 Expect.equals(2012, dt1.year);
444 Expect.equals(2, dt1.month);
445 Expect.equals(27, dt1.day);
446 Expect.equals(0, dt1.hours);
447 Expect.equals(0, dt1.minutes);
448 Expect.equals(0, dt1.seconds);
449 Expect.equals(0, dt1.milliseconds);
450 Expect.equals(false, dt1.isUtc());
451 dt1 = new Date.fromString("2012-02-27T14Z");
452 Expect.equals(2012, dt1.year);
453 Expect.equals(2, dt1.month);
454 Expect.equals(27, dt1.day);
455 Expect.equals(14, dt1.hours);
456 Expect.equals(0, dt1.minutes);
457 Expect.equals(0, dt1.seconds);
458 Expect.equals(0, dt1.milliseconds);
459 Expect.equals(true, dt1.isUtc());
460 dt1 = new Date.fromString("-123450101 00:00:00 Z");
461 Expect.equals(-12345, dt1.year);
462 Expect.equals(1, dt1.month);
463 Expect.equals(1, dt1.day);
464 Expect.equals(0, dt1.hours);
465 Expect.equals(0, dt1.minutes);
466 Expect.equals(0, dt1.seconds);
467 Expect.equals(0, dt1.milliseconds);
468 Expect.equals(true, dt1.isUtc());
469 // We only support milliseconds. If the user supplies more data (the "51"
470 // here), we round.
471 // If (eventually) we support more than just milliseconds this test could
472 // fail. Please update the test in this case.
473 dt1 = new Date.fromString("1999-01-02 23:59:59.99951");
474 Expect.equals(1999, dt1.year);
475 Expect.equals(1, dt1.month);
476 Expect.equals(3, dt1.day);
477 Expect.equals(0, dt1.hours);
478 Expect.equals(0, dt1.minutes);
479 Expect.equals(0, dt1.seconds);
480 Expect.equals(0, dt1.milliseconds);
481 Expect.equals(false, dt1.isUtc());
482 dt1 = new Date.fromString("1999-01-02 23:58:59.99951Z");
483 Expect.equals(1999, dt1.year);
484 Expect.equals(1, dt1.month);
485 Expect.equals(2, dt1.day);
486 Expect.equals(23, dt1.hours);
487 Expect.equals(59, dt1.minutes);
488 Expect.equals(0, dt1.seconds);
489 Expect.equals(0, dt1.milliseconds);
490 Expect.equals(true, dt1.isUtc());
333 } 491 }
334 492
335 static void testWeekday() { 493 static void testWeekday() {
336 // 2011-10-06 is Summertime. 494 // 2011-10-06 is Summertime.
337 var d = new Date(2011, 10, 6, 0, 45, 37, 0); 495 var d = new Date(2011, 10, 6, 0, 45, 37, 0);
338 Expect.equals(Date.THU, d.weekday); 496 Expect.equals(Date.THU, d.weekday);
339 d = new Date.withTimeZone(2011, 10, 6, 0, 45, 37, 0, const TimeZone.utc()); 497 d = new Date.withTimeZone(2011, 10, 6, 0, 45, 37, 0, const TimeZone.utc());
340 Expect.equals(Date.THU, d.weekday); 498 Expect.equals(Date.THU, d.weekday);
341 d = new Date(2011, 10, 5, 23, 45, 37, 0); 499 d = new Date(2011, 10, 5, 23, 45, 37, 0);
342 Expect.equals(Date.WED, d.weekday); 500 Expect.equals(Date.WED, d.weekday);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 testDateStrings(); 533 testDateStrings();
376 testEquivalentYears(); 534 testEquivalentYears();
377 testFarAwayDates(); 535 testFarAwayDates();
378 testWeekday(); 536 testWeekday();
379 } 537 }
380 } 538 }
381 539
382 main() { 540 main() {
383 DateTest.testMain(); 541 DateTest.testMain();
384 } 542 }
OLDNEW
« runtime/lib/date.dart ('K') | « runtime/lib/date.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698