| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Dart test program for DateTime. | 7 // Dart test program for DateTime. |
| 8 | 8 |
| 9 bool get supportsMicroseconds => | 9 bool get supportsMicroseconds => |
| 10 new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1; | 10 new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 | 31 |
| 32 void testMillisecondsSinceEpoch() { | 32 void testMillisecondsSinceEpoch() { |
| 33 var dt1 = new DateTime.now(); | 33 var dt1 = new DateTime.now(); |
| 34 var millisecondsSinceEpoch = dt1.millisecondsSinceEpoch; | 34 var millisecondsSinceEpoch = dt1.millisecondsSinceEpoch; |
| 35 var dt2 = new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch); | 35 var dt2 = new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch); |
| 36 Expect.equals(millisecondsSinceEpoch, dt2.millisecondsSinceEpoch); | 36 Expect.equals(millisecondsSinceEpoch, dt2.millisecondsSinceEpoch); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void testMicrosecondsSinceEpoch() { | 39 void testMicrosecondsSinceEpoch() { |
| 40 // We chose a millisecondSinceEpoch that is guaranteed to fit into 53 |
| 41 // bits when expressed as microseconds. Furthermore the microsecond part |
| 42 // is equal to 0, which means that an implementation that discards (or |
| 43 // rounds) microseconds should yield correct results for the following |
| 44 // test. |
| 40 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1); | 45 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1); |
| 41 var microsecondsSinceEpoch = dt1.microsecondsSinceEpoch; | 46 var microsecondsSinceEpoch = dt1.microsecondsSinceEpoch; |
| 42 var dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); | 47 var dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); |
| 43 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); | 48 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); |
| 44 | 49 |
| 45 if (!supportsMicroseconds) return; | 50 if (!supportsMicroseconds) return; |
| 46 dt1 = new DateTime.now(); | 51 dt1 = new DateTime.now(); |
| 47 microsecondsSinceEpoch = dt1.millisecondsSinceEpoch; | 52 microsecondsSinceEpoch = dt1.microsecondsSinceEpoch; |
| 48 dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); | 53 dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); |
| 49 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); | 54 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); |
| 50 } | 55 } |
| 51 | 56 |
| 52 void testFarAwayDates() { | 57 void testFarAwayDates() { |
| 53 DateTime dt = | 58 DateTime dt = |
| 54 new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true); | 59 new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true); |
| 55 Expect.equals(33658, dt.year); | 60 Expect.equals(33658, dt.year); |
| 56 Expect.equals(9, dt.month); | 61 Expect.equals(9, dt.month); |
| 57 Expect.equals(27, dt.day); | 62 Expect.equals(27, dt.day); |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 testSubAdd(); | 1341 testSubAdd(); |
| 1337 testUnderflowAndOverflow(); | 1342 testUnderflowAndOverflow(); |
| 1338 testDateStrings(); | 1343 testDateStrings(); |
| 1339 testEquivalentYears(); | 1344 testEquivalentYears(); |
| 1340 testExtremes(); | 1345 testExtremes(); |
| 1341 testFarAwayDates(); | 1346 testFarAwayDates(); |
| 1342 testWeekday(); | 1347 testWeekday(); |
| 1343 testToStrings(); | 1348 testToStrings(); |
| 1344 testIsoString(); | 1349 testIsoString(); |
| 1345 } | 1350 } |
| OLD | NEW |