| 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. | |
| 45 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1); | 40 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1); |
| 46 var microsecondsSinceEpoch = dt1.microsecondsSinceEpoch; | 41 var microsecondsSinceEpoch = dt1.microsecondsSinceEpoch; |
| 47 var dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); | 42 var dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); |
| 48 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); | 43 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); |
| 49 | 44 |
| 50 if (!supportsMicroseconds) return; | |
| 51 dt1 = new DateTime.now(); | 45 dt1 = new DateTime.now(); |
| 52 microsecondsSinceEpoch = dt1.microsecondsSinceEpoch; | 46 microsecondsSinceEpoch = dt1.microsecondsSinceEpoch; |
| 53 dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); | 47 dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch); |
| 54 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); | 48 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); |
| 55 } | 49 } |
| 56 | 50 |
| 57 void testFarAwayDates() { | 51 void testFarAwayDates() { |
| 58 DateTime dt = | 52 DateTime dt = |
| 59 new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true); | 53 new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true); |
| 60 Expect.equals(33658, dt.year); | 54 Expect.equals(33658, dt.year); |
| (...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 testSubAdd(); | 1335 testSubAdd(); |
| 1342 testUnderflowAndOverflow(); | 1336 testUnderflowAndOverflow(); |
| 1343 testDateStrings(); | 1337 testDateStrings(); |
| 1344 testEquivalentYears(); | 1338 testEquivalentYears(); |
| 1345 testExtremes(); | 1339 testExtremes(); |
| 1346 testFarAwayDates(); | 1340 testFarAwayDates(); |
| 1347 testWeekday(); | 1341 testWeekday(); |
| 1348 testToStrings(); | 1342 testToStrings(); |
| 1349 testIsoString(); | 1343 testIsoString(); |
| 1350 } | 1344 } |
| OLD | NEW |