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

Side by Side Diff: tests/corelib/date_time_test.dart

Issue 10894009: Revert "Updated VM and JS versions of Date to allow underflow and overflow." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | « runtime/lib/date_patch.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) 2012, 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();
11 bool timeMovedForward = false; 11 bool timeMovedForward = false;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 isUtc: true)); 258 isUtc: true));
259 Expect.throws(() => new Date.fromMillisecondsSinceEpoch(-8640000000000001, 259 Expect.throws(() => new Date.fromMillisecondsSinceEpoch(-8640000000000001,
260 isUtc: true)); 260 isUtc: true));
261 Expect.throws(() => new Date.fromMillisecondsSinceEpoch(8640000000000001)); 261 Expect.throws(() => new Date.fromMillisecondsSinceEpoch(8640000000000001));
262 Expect.throws( 262 Expect.throws(
263 () => new Date.fromMillisecondsSinceEpoch(-8640000000000001)); 263 () => new Date.fromMillisecondsSinceEpoch(-8640000000000001));
264 dt = new Date.fromMillisecondsSinceEpoch(8640000000000000); 264 dt = new Date.fromMillisecondsSinceEpoch(8640000000000000);
265 Expect.throws(() => new Date(dt.year, dt.month, dt.day, 265 Expect.throws(() => new Date(dt.year, dt.month, dt.day,
266 dt.hour, dt.minute, 0, 1)); 266 dt.hour, dt.minute, 0, 1));
267 dt = new Date.fromMillisecondsSinceEpoch(-8640000000000000); 267 dt = new Date.fromMillisecondsSinceEpoch(-8640000000000000);
268 // TODO(floitsch): Update comment after refactoring.
269 // This test currently fails because the arguments must not be negative.
270 // However we are going to allow negative (and overflowing) arguments and
271 // this line will then throw for the correct reason.
268 Expect.throws(() => new Date(dt.year, dt.month, dt.day, 272 Expect.throws(() => new Date(dt.year, dt.month, dt.day,
269 dt.hour, dt.minute, 0, -1, isUtc: true)); 273 dt.hour, dt.minute, 0, -1));
270 } 274 }
271 275
272 static void testUTCGetters() { 276 static void testUTCGetters() {
273 var dt = new Date.fromMillisecondsSinceEpoch(1305140315000, isUtc: true); 277 var dt = new Date.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
274 Expect.equals(2011, dt.year); 278 Expect.equals(2011, dt.year);
275 Expect.equals(5, dt.month); 279 Expect.equals(5, dt.month);
276 Expect.equals(11, dt.day); 280 Expect.equals(11, dt.day);
277 Expect.equals(18, dt.hour); 281 Expect.equals(18, dt.hour);
278 Expect.equals(58, dt.minute); 282 Expect.equals(58, dt.minute);
279 Expect.equals(35, dt.second); 283 Expect.equals(35, dt.second);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 Expect.equals(dt1.hour, dt2.hour); 420 Expect.equals(dt1.hour, dt2.hour);
417 Expect.equals(dt1.minute, dt2.minute); 421 Expect.equals(dt1.minute, dt2.minute);
418 Expect.equals(dt1.second + 3, dt2.second); 422 Expect.equals(dt1.second + 3, dt2.second);
419 Expect.equals(dt1.millisecond + 5, dt2.millisecond); 423 Expect.equals(dt1.millisecond + 5, dt2.millisecond);
420 var dt3 = dt2.subtract(new Duration(milliseconds: 424 var dt3 = dt2.subtract(new Duration(milliseconds:
421 3 * Duration.MILLISECONDS_PER_SECOND + 5)); 425 3 * Duration.MILLISECONDS_PER_SECOND + 5));
422 Expect.equals(true, dt1 == dt3); 426 Expect.equals(true, dt1 == dt3);
423 Expect.equals(false, dt1 == dt2); 427 Expect.equals(false, dt1 == dt2);
424 } 428 }
425 429
426 static void testUnderflowAndOverflow() {
427 final dtBase = new Date(2012, 6, 20, 12, 30, 30, 500);
428
429 // Millisecond
430 print(" >>> Millisecond+");
431 var dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
432 dtBase.minute, dtBase.second, 1000);
433 Expect.equals(dtBase.year, dt.year);
434 Expect.equals(dtBase.month, dt.month);
435 Expect.equals(dtBase.day, dt.day);
436 Expect.equals(dtBase.hour, dt.hour);
437 Expect.equals(dtBase.minute, dt.minute);
438 Expect.equals(dtBase.second + 1, dt.second);
439 Expect.equals(0, dt.millisecond);
440
441 print(" >>> Millisecond-");
442 dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
443 dtBase.minute, dtBase.second, -1000);
444 Expect.equals(dtBase.year, dt.year);
445 Expect.equals(dtBase.month, dt.month);
446 Expect.equals(dtBase.day, dt.day);
447 Expect.equals(dtBase.hour, dt.hour);
448 Expect.equals(dtBase.minute, dt.minute);
449 Expect.equals(dtBase.second - 1, dt.second);
450 Expect.equals(0, dt.millisecond);
451
452 // Second
453 print(" >>> Second+");
454 dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
455 dtBase.minute, 60, dtBase.millisecond);
456 Expect.equals(dtBase.year, dt.year);
457 Expect.equals(dtBase.month, dt.month);
458 Expect.equals(dtBase.day, dt.day);
459 Expect.equals(dtBase.hour, dt.hour);
460 Expect.equals(dtBase.minute + 1, dt.minute);
461 Expect.equals(0, dt.second);
462 Expect.equals(dtBase.millisecond, dt.millisecond);
463
464 print(" >>> Second-");
465 dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
466 dtBase.minute, -60, dtBase.millisecond);
467 Expect.equals(dtBase.year, dt.year);
468 Expect.equals(dtBase.month, dt.month);
469 Expect.equals(dtBase.day, dt.day);
470 Expect.equals(dtBase.hour, dt.hour);
471 Expect.equals(dtBase.minute - 1, dt.minute);
472 Expect.equals(0, dt.second);
473 Expect.equals(dtBase.millisecond, dt.millisecond);
474
475 // Minute
476 print(" >>> Minute+");
477 dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 60,
478 dtBase.second, dtBase.millisecond);
479 Expect.equals(dtBase.year, dt.year);
480 Expect.equals(dtBase.month, dt.month);
481 Expect.equals(dtBase.day, dt.day);
482 Expect.equals(dtBase.hour + 1, dt.hour);
483 Expect.equals(0, dt.minute);
484 Expect.equals(dtBase.second, dt.second);
485 Expect.equals(dtBase.millisecond, dt.millisecond);
486
487 print(" >>> Minute-");
488 dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, -60,
489 dtBase.second, dtBase.millisecond);
490 Expect.equals(dtBase.year, dt.year);
491 Expect.equals(dtBase.month, dt.month);
492 Expect.equals(dtBase.day, dt.day);
493 Expect.equals(dtBase.hour - 1, dt.hour);
494 Expect.equals(0, dt.minute);
495 Expect.equals(dtBase.second, dt.second);
496 Expect.equals(dtBase.millisecond, dt.millisecond);
497
498 // Hour
499 print(" >>> Hour+");
500 dt = new Date(dtBase.year, dtBase.month, dtBase.day, 24, dtBase.minute,
501 dtBase.second, dtBase.millisecond);
502 Expect.equals(dtBase.year, dt.year);
503 Expect.equals(dtBase.month, dt.month);
504 Expect.equals(dtBase.day + 1, dt.day);
505 Expect.equals(0, dt.hour);
506 Expect.equals(dtBase.minute, dt.minute);
507 Expect.equals(dtBase.second, dt.second);
508 Expect.equals(dtBase.millisecond, dt.millisecond);
509
510 print(" >>> Hour-");
511 dt = new Date(dtBase.year, dtBase.month, dtBase.day, -24, dtBase.minute,
512 dtBase.second, dtBase.millisecond);
513 Expect.equals(dtBase.year, dt.year);
514 Expect.equals(dtBase.month, dt.month);
515 Expect.equals(dtBase.day - 1, dt.day);
516 Expect.equals(0, dt.hour);
517 Expect.equals(dtBase.minute, dt.minute);
518 Expect.equals(dtBase.second, dt.second);
519 Expect.equals(dtBase.millisecond, dt.millisecond);
520
521 // Day
522 print(" >>> Day+");
523 dt = new Date(dtBase.year, dtBase.month, 31, dtBase.hour, dtBase.minute,
524 dtBase.second, dtBase.millisecond);
525 Expect.equals(dtBase.year, dt.year);
526 Expect.equals(dtBase.month + 1, dt.month);
527 Expect.equals(1, dt.day);
528 Expect.equals(dtBase.hour, dt.hour);
529 Expect.equals(dtBase.minute, dt.minute);
530 Expect.equals(dtBase.second, dt.second);
531 Expect.equals(dtBase.millisecond, dt.millisecond);
532
533 print(" >>> Day-");
534 dt = new Date(dtBase.year, dtBase.month, -30, dtBase.hour, dtBase.minute,
535 dtBase.second, dtBase.millisecond);
536 Expect.equals(dtBase.year, dt.year);
537 Expect.equals(dtBase.month - 1, dt.month);
538 Expect.equals(1, dt.day);
539 Expect.equals(dtBase.hour, dt.hour);
540 Expect.equals(dtBase.minute, dt.minute);
541 Expect.equals(dtBase.second, dt.second);
542 Expect.equals(dtBase.millisecond, dt.millisecond);
543
544 // Month
545 print(" >>> Month+");
546 dt = new Date(dtBase.year, 13, dtBase.day, dtBase.hour, dtBase.minute,
547 dtBase.second, dtBase.millisecond);
548 Expect.equals(dtBase.year + 1, dt.year);
549 Expect.equals(1, dt.month);
550 Expect.equals(dtBase.day, dt.day);
551 Expect.equals(dtBase.hour, dt.hour);
552 Expect.equals(dtBase.minute, dt.minute);
553 Expect.equals(dtBase.second, dt.second);
554 Expect.equals(dtBase.millisecond, dt.millisecond);
555
556 print(" >>> Month-");
557 dt = new Date(dtBase.year, -11, dtBase.day, dtBase.hour, dtBase.minute,
558 dtBase.second, dtBase.millisecond);
559 Expect.equals(dtBase.year - 1, dt.year);
560 Expect.equals(1, dt.month);
561 Expect.equals(dtBase.day, dt.day);
562 Expect.equals(dtBase.hour, dt.hour);
563 Expect.equals(dtBase.minute, dt.minute);
564 Expect.equals(dtBase.second, dt.second);
565 Expect.equals(dtBase.millisecond, dt.millisecond);
566
567 // Flowing all the way up the chain.
568 print(" >>> Flow+");
569 var dtBase1 = new Date(2012, 12, 31, 23, 59, 59, 999);
570 var dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day,
571 dtBase1.hour, dtBase1.minute, dtBase1.second,
572 dtBase1.millisecond + 1);
573 Expect.equals(dtBase1.year + 1, dtTick.year);
574 Expect.equals(1, dtTick.month);
575 Expect.equals(1, dtTick.day);
576 Expect.equals(0, dtTick.hour);
577 Expect.equals(0, dtTick.minute);
578 Expect.equals(0, dtTick.second);
579 Expect.equals(0, dtTick.millisecond);
580
581 print(" >>> Flow-");
582 dtBase1 = new Date(2012, 1, 1, 0, 0, 0, 0);
583 dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day, dtBase1.hour,
584 dtBase1.minute, dtBase1.second, dtBase1.millisecond - 1);
585 Expect.equals(dtBase1.year - 1, dtTick.year);
586 Expect.equals(12, dtTick.month);
587 Expect.equals(31, dtTick.day);
588 Expect.equals(23, dtTick.hour);
589 Expect.equals(59, dtTick.minute);
590 Expect.equals(59, dtTick.second);
591 Expect.equals(999, dtTick.millisecond);
592
593 print(" >>> extra underflow");
594 dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day, -17520,
595 dtBase1.minute, dtBase1.second, dtBase1.millisecond);
596 Expect.equals(dtBase1.year - 2, dtTick.year);
597 Expect.equals(dtBase1.month, dtTick.month);
598 Expect.equals(dtBase1.day, dtTick.day);
599 Expect.equals(dtBase1.hour, dtTick.hour);
600 Expect.equals(dtBase1.minute, dtTick.minute);
601 Expect.equals(dtBase1.second, dtTick.second);
602 Expect.equals(dtBase1.millisecond, dtTick.millisecond);
603 }
604
605 static void testDateStrings() { 430 static void testDateStrings() {
606 // TODO(floitsch): Clean up the Date API that deals with strings. 431 // TODO(floitsch): Clean up the Date API that deals with strings.
607 var dt1 = new Date.fromString("2011-05-11 18:58:35Z"); 432 var dt1 = new Date.fromString("2011-05-11 18:58:35Z");
608 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch); 433 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch);
609 Expect.isTrue(dt1.isUtc); 434 Expect.isTrue(dt1.isUtc);
610 dt1 = new Date.fromString("20110511 18:58:35z"); 435 dt1 = new Date.fromString("20110511 18:58:35z");
611 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch); 436 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch);
612 Expect.isTrue(dt1.isUtc); 437 Expect.isTrue(dt1.isUtc);
613 dt1 = new Date.fromString("+20110511 18:58:35z"); 438 dt1 = new Date.fromString("+20110511 18:58:35z");
614 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch); 439 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 629 }
805 630
806 static void testMain() { 631 static void testMain() {
807 testNow(); 632 testNow();
808 testValue(); 633 testValue();
809 testConstructors(); 634 testConstructors();
810 testUTCGetters(); 635 testUTCGetters();
811 testLocalGetters(); 636 testLocalGetters();
812 testChangeTimeZone(); 637 testChangeTimeZone();
813 testSubAdd(); 638 testSubAdd();
814 testUnderflowAndOverflow();
815 testDateStrings(); 639 testDateStrings();
816 testEquivalentYears(); 640 testEquivalentYears();
817 testExtremes(); 641 testExtremes();
818 testFarAwayDates(); 642 testFarAwayDates();
819 testWeekday(); 643 testWeekday();
820 } 644 }
821 } 645 }
822 646
823 main() { 647 main() {
824 DateTest.testMain(); 648 DateTest.testMain();
825 } 649 }
OLDNEW
« no previous file with comments | « runtime/lib/date_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698