OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "package:expect/expect.dart"; |
| 6 |
| 7 // Test fromString with 6 digits after the decimal point. |
| 8 |
| 9 bool get supportsMicroseconds => |
| 10 new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1; |
| 11 |
| 12 |
| 13 main() { |
| 14 if (supportsMicroseconds) { |
| 15 testMicrosecondPrecision(); |
| 16 } else { |
| 17 testMillisecondPrecision(); |
| 18 } |
| 19 } |
| 20 |
| 21 void testMillisecondPrecision() { |
| 22 // We only support milliseconds. If the user supplies more data (the "51" |
| 23 // here), we round. |
| 24 DateTime dt1 = DateTime.parse("1999-01-02 23:59:59.999519"); |
| 25 Expect.equals(1999, dt1.year); |
| 26 Expect.equals(1, dt1.month); |
| 27 Expect.equals(3, dt1.day); |
| 28 Expect.equals(0, dt1.hour); |
| 29 Expect.equals(0, dt1.minute); |
| 30 Expect.equals(0, dt1.second); |
| 31 Expect.equals(0, dt1.millisecond); |
| 32 Expect.equals(false, dt1.isUtc); |
| 33 dt1 = DateTime.parse("1999-01-02 23:58:59.999519Z"); |
| 34 Expect.equals(1999, dt1.year); |
| 35 Expect.equals(1, dt1.month); |
| 36 Expect.equals(2, dt1.day); |
| 37 Expect.equals(23, dt1.hour); |
| 38 Expect.equals(59, dt1.minute); |
| 39 Expect.equals(0, dt1.second); |
| 40 Expect.equals(0, dt1.millisecond); |
| 41 Expect.equals(true, dt1.isUtc); |
| 42 dt1 = DateTime.parse("0009-09-09 09:09:09.009411Z"); |
| 43 Expect.equals(9, dt1.year); |
| 44 Expect.equals(9, dt1.month); |
| 45 Expect.equals(9, dt1.day); |
| 46 Expect.equals(9, dt1.hour); |
| 47 Expect.equals(9, dt1.minute); |
| 48 Expect.equals(9, dt1.second); |
| 49 Expect.equals(9, dt1.millisecond); |
| 50 Expect.equals(true, dt1.isUtc); |
| 51 String svnDate = "2012-03-30T04:28:13.752341Z"; |
| 52 dt1 = DateTime.parse(svnDate); |
| 53 Expect.equals(2012, dt1.year); |
| 54 Expect.equals(3, dt1.month); |
| 55 Expect.equals(30, dt1.day); |
| 56 Expect.equals(4, dt1.hour); |
| 57 Expect.equals(28, dt1.minute); |
| 58 Expect.equals(13, dt1.second); |
| 59 Expect.equals(752, dt1.millisecond); |
| 60 Expect.equals(true, dt1.isUtc); |
| 61 } |
| 62 |
| 63 void testMicrosecondPrecision() { |
| 64 DateTime dt1 = DateTime.parse("1999-01-02 23:59:59.999519"); |
| 65 Expect.equals(1999, dt1.year); |
| 66 Expect.equals(1, dt1.month); |
| 67 Expect.equals(2, dt1.day); |
| 68 Expect.equals(23, dt1.hour); |
| 69 Expect.equals(59, dt1.minute); |
| 70 Expect.equals(59, dt1.second); |
| 71 Expect.equals(999, dt1.millisecond); |
| 72 Expect.equals(519, dt1.microsecond); |
| 73 Expect.equals(false, dt1.isUtc); |
| 74 dt1 = DateTime.parse("1999-01-02 23:58:59.999519Z"); |
| 75 Expect.equals(1999, dt1.year); |
| 76 Expect.equals(1, dt1.month); |
| 77 Expect.equals(2, dt1.day); |
| 78 Expect.equals(23, dt1.hour); |
| 79 Expect.equals(58, dt1.minute); |
| 80 Expect.equals(59, dt1.second); |
| 81 Expect.equals(999, dt1.millisecond); |
| 82 Expect.equals(519, dt1.microsecond); |
| 83 Expect.equals(true, dt1.isUtc); |
| 84 dt1 = DateTime.parse("0009-09-09 09:09:09.009411Z"); |
| 85 Expect.equals(9, dt1.year); |
| 86 Expect.equals(9, dt1.month); |
| 87 Expect.equals(9, dt1.day); |
| 88 Expect.equals(9, dt1.hour); |
| 89 Expect.equals(9, dt1.minute); |
| 90 Expect.equals(9, dt1.second); |
| 91 Expect.equals(9, dt1.millisecond); |
| 92 Expect.equals(411, dt1.microsecond); |
| 93 Expect.equals(true, dt1.isUtc); |
| 94 String svnDate = "2012-03-30T04:28:13.752341Z"; |
| 95 dt1 = DateTime.parse(svnDate); |
| 96 Expect.equals(2012, dt1.year); |
| 97 Expect.equals(3, dt1.month); |
| 98 Expect.equals(30, dt1.day); |
| 99 Expect.equals(4, dt1.hour); |
| 100 Expect.equals(28, dt1.minute); |
| 101 Expect.equals(13, dt1.second); |
| 102 Expect.equals(752, dt1.millisecond); |
| 103 Expect.equals(341, dt1.microsecond); |
| 104 Expect.equals(true, dt1.isUtc); |
| 105 } |
OLD | NEW |