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

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

Issue 1493033003: Add microsecond support to DateTime. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comment. Created 5 years 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
« no previous file with comments | « sdk/lib/core/date_time.dart ('k') | tests/corelib/date_time_parse_test.dart » ('j') | 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) 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 // Test fromString with 6 digits after the decimal point. 7 // Test fromString with 6 digits after the decimal point.
8 8
9 bool get supportsMicroseconds =>
10 new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1;
11
12
9 main() { 13 main() {
14 if (supportsMicroseconds) {
15 testMicrosecondPrecision();
16 } else {
17 testMillisecondPrecision();
18 }
19 }
20
21 void testMillisecondPrecision() {
10 // We only support milliseconds. If the user supplies more data (the "51" 22 // We only support milliseconds. If the user supplies more data (the "51"
11 // here), we round. 23 // here), we round.
12 // If (eventually) we support more than just milliseconds this test could
13 // fail. Please update the test in this case.
14 DateTime dt1 = DateTime.parse("1999-01-02 23:59:59.999519"); 24 DateTime dt1 = DateTime.parse("1999-01-02 23:59:59.999519");
15 Expect.equals(1999, dt1.year); 25 Expect.equals(1999, dt1.year);
16 Expect.equals(1, dt1.month); 26 Expect.equals(1, dt1.month);
17 Expect.equals(3, dt1.day); 27 Expect.equals(3, dt1.day);
18 Expect.equals(0, dt1.hour); 28 Expect.equals(0, dt1.hour);
19 Expect.equals(0, dt1.minute); 29 Expect.equals(0, dt1.minute);
20 Expect.equals(0, dt1.second); 30 Expect.equals(0, dt1.second);
21 Expect.equals(0, dt1.millisecond); 31 Expect.equals(0, dt1.millisecond);
22 Expect.equals(false, dt1.isUtc); 32 Expect.equals(false, dt1.isUtc);
23 dt1 = DateTime.parse("1999-01-02 23:58:59.999519Z"); 33 dt1 = DateTime.parse("1999-01-02 23:58:59.999519Z");
(...skipping 17 matching lines...) Expand all
41 String svnDate = "2012-03-30T04:28:13.752341Z"; 51 String svnDate = "2012-03-30T04:28:13.752341Z";
42 dt1 = DateTime.parse(svnDate); 52 dt1 = DateTime.parse(svnDate);
43 Expect.equals(2012, dt1.year); 53 Expect.equals(2012, dt1.year);
44 Expect.equals(3, dt1.month); 54 Expect.equals(3, dt1.month);
45 Expect.equals(30, dt1.day); 55 Expect.equals(30, dt1.day);
46 Expect.equals(4, dt1.hour); 56 Expect.equals(4, dt1.hour);
47 Expect.equals(28, dt1.minute); 57 Expect.equals(28, dt1.minute);
48 Expect.equals(13, dt1.second); 58 Expect.equals(13, dt1.second);
49 Expect.equals(752, dt1.millisecond); 59 Expect.equals(752, dt1.millisecond);
50 Expect.equals(true, dt1.isUtc); 60 Expect.equals(true, dt1.isUtc);
51
52 } 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 }
OLDNEW
« no previous file with comments | « sdk/lib/core/date_time.dart ('k') | tests/corelib/date_time_parse_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698