| Index: tests/corelib/date_time_test.dart
|
| diff --git a/tests/corelib/date_time_test.dart b/tests/corelib/date_time_test.dart
|
| index 7524ef3b7a85bf57268aa8f4d6be42d05c43889a..df39524abae9ad92a98fe4cfd971ec1bc84978a6 100644
|
| --- a/tests/corelib/date_time_test.dart
|
| +++ b/tests/corelib/date_time_test.dart
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| @@ -265,12 +265,6 @@ class DateTest {
|
| Expect.throws(() => new Date(dt.year, dt.month, dt.day,
|
| dt.hour, dt.minute, 0, 1));
|
| dt = new Date.fromMillisecondsSinceEpoch(-8640000000000000);
|
| - // TODO(floitsch): Update comment after refactoring.
|
| - // This test currently fails because the arguments must not be negative.
|
| - // However we are going to allow negative (and overflowing) arguments and
|
| - // this line will then throw for the correct reason.
|
| - Expect.throws(() => new Date(dt.year, dt.month, dt.day,
|
| - dt.hour, dt.minute, 0, -1));
|
| }
|
|
|
| static void testUTCGetters() {
|
| @@ -427,6 +421,174 @@ class DateTest {
|
| Expect.equals(false, dt1 == dt2);
|
| }
|
|
|
| + static void testUnderflowAndOverflow() {
|
| + final dtBase = new Date(2012, 6, 20, 12, 30, 30, 500);
|
| +
|
| + // Millisecond
|
| + print(" >>> Millisecond+");
|
| + var dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
|
| + dtBase.minute, dtBase.second, 1000);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second + 1);
|
| + Expect.equals(dt.millisecond, 0);
|
| +
|
| + print(" >>> Millisecond-");
|
| + dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
|
| + dtBase.minute, dtBase.second, -1000);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second - 1);
|
| + Expect.equals(dt.millisecond, 0);
|
| +
|
| + // Second
|
| + print(" >>> Second+");
|
| + dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
|
| + dtBase.minute, 60, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute + 1);
|
| + Expect.equals(dt.second, 0);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + print(" >>> Second-");
|
| + dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
|
| + dtBase.minute, -60, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute - 1);
|
| + Expect.equals(dt.second, 0);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + // Minute
|
| + print(" >>> Minute+");
|
| + dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 60,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour + 1);
|
| + Expect.equals(dt.minute, 0);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + print(" >>> Minute-");
|
| + dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, -60,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour - 1);
|
| + Expect.equals(dt.minute, 0);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + // Hour
|
| + print(" >>> Hour+");
|
| + dt = new Date(dtBase.year, dtBase.month, dtBase.day, 24, dtBase.minute,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day + 1);
|
| + Expect.equals(dt.hour, 0);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + print(" >>> Hour-");
|
| + dt = new Date(dtBase.year, dtBase.month, dtBase.day, -24, dtBase.minute,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month);
|
| + Expect.equals(dt.day, dtBase.day - 1);
|
| + Expect.equals(dt.hour, 0);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + // Day
|
| + print(" >>> Day+");
|
| + dt = new Date(dtBase.year, dtBase.month, 31, dtBase.hour, dtBase.minute,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month + 1);
|
| + Expect.equals(dt.day, 1);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + print(" >>> Day-");
|
| + dt = new Date(dtBase.year, dtBase.month, -30, dtBase.hour, dtBase.minute,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year);
|
| + Expect.equals(dt.month, dtBase.month - 1);
|
| + Expect.equals(dt.day, 1);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + // Month
|
| + print(" >>> Month+");
|
| + dt = new Date(dtBase.year, 13, dtBase.day, dtBase.hour, dtBase.minute,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year + 1);
|
| + Expect.equals(dt.month, 1);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + print(" >>> Month-");
|
| + dt = new Date(dtBase.year, -11, dtBase.day, dtBase.hour, dtBase.minute,
|
| + dtBase.second, dtBase.millisecond);
|
| + Expect.equals(dt.year, dtBase.year - 1);
|
| + Expect.equals(dt.month, 1);
|
| + Expect.equals(dt.day, dtBase.day);
|
| + Expect.equals(dt.hour, dtBase.hour);
|
| + Expect.equals(dt.minute, dtBase.minute);
|
| + Expect.equals(dt.second, dtBase.second);
|
| + Expect.equals(dt.millisecond, dtBase.millisecond);
|
| +
|
| + // Flowing all the way up the chain.
|
| + print(" >>> Flow+");
|
| + var dtBase1 = new Date(2012, 12, 31, 23, 59, 59, 999);
|
| + var dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day,
|
| + dtBase1.hour, dtBase1.minute, dtBase1.second,
|
| + dtBase1.millisecond + 1);
|
| + Expect.equals(dtTick.year, dtBase1.year + 1);
|
| + Expect.equals(dtTick.month, 1);
|
| + Expect.equals(dtTick.day, 1);
|
| + Expect.equals(dtTick.hour, 0);
|
| + Expect.equals(dtTick.minute, 0);
|
| + Expect.equals(dtTick.second, 0);
|
| + Expect.equals(dtTick.millisecond, 0);
|
| +
|
| + print(" >>> Flow-");
|
| + dtBase1 = new Date(2012, 1, 1, 0, 0, 0, 0);
|
| + dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day, dtBase1.hour,
|
| + dtBase1.minute, dtBase1.second, dtBase1.millisecond - 1);
|
| + Expect.equals(dtTick.year, dtBase1.year - 1);
|
| + Expect.equals(dtTick.month, 12);
|
| + Expect.equals(dtTick.day, 31);
|
| + Expect.equals(dtTick.hour, 23);
|
| + Expect.equals(dtTick.minute, 59);
|
| + Expect.equals(dtTick.second, 59);
|
| + Expect.equals(dtTick.millisecond, 999);
|
| + }
|
| +
|
| static void testDateStrings() {
|
| // TODO(floitsch): Clean up the Date API that deals with strings.
|
| var dt1 = new Date.fromString("2011-05-11 18:58:35Z");
|
| @@ -636,6 +798,7 @@ class DateTest {
|
| testLocalGetters();
|
| testChangeTimeZone();
|
| testSubAdd();
|
| + testUnderflowAndOverflow();
|
| testDateStrings();
|
| testEquivalentYears();
|
| testExtremes();
|
|
|