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

Side by Side Diff: tests/corelib_strong/date_time_test.dart

Issue 2984063002: Migrate test block 5 to Dart 2.0. (Closed)
Patch Set: merge with head Created 3 years, 5 months 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 | « tests/corelib_strong/date_time_parse_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Dart test program for DateTime.
8
9 bool get supportsMicroseconds =>
10 new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1;
11
12 // Identical to _MAX_MILLISECONDS_SINCE_EPOCH in date_time.dart
13 const int _MAX_MILLISECONDS = 8640000000000000;
14
15 // Tests if the time moves eventually forward.
16 void testNow() {
17 var t1 = new DateTime.now();
18 bool timeMovedForward = false;
19 const int N = 1000000;
20 outer:
21 while (true) {
22 for (int i = N; i > 0; i--) {
23 var t2 = new DateTime.now();
24 if (t1.millisecondsSinceEpoch < t2.millisecondsSinceEpoch) {
25 break outer;
26 }
27 }
28 print("testNow: No Date.now() progress in $N loops. Time: $t1");
29 }
30 Expect.isFalse(t1.isUtc);
31 }
32
33 void testMillisecondsSinceEpoch() {
34 var dt1 = new DateTime.now();
35 var millisecondsSinceEpoch = dt1.millisecondsSinceEpoch;
36 var dt2 = new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch);
37 Expect.equals(millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
38 }
39
40 void testMicrosecondsSinceEpoch() {
41 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1);
42 var microsecondsSinceEpoch = dt1.microsecondsSinceEpoch;
43 var dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch);
44 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch);
45
46 dt1 = new DateTime.now();
47 microsecondsSinceEpoch = dt1.microsecondsSinceEpoch;
48 dt2 = new DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch);
49 Expect.equals(microsecondsSinceEpoch, dt2.microsecondsSinceEpoch);
50 }
51
52 void testFarAwayDates() {
53 DateTime dt =
54 new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true);
55 Expect.equals(33658, dt.year);
56 Expect.equals(9, dt.month);
57 Expect.equals(27, dt.day);
58 Expect.equals(1, dt.hour);
59 Expect.equals(46, dt.minute);
60 Expect.equals(40, dt.second);
61 Expect.equals(1, dt.millisecond);
62 Expect.equals(0, dt.microsecond);
63 dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001, isUtc: true);
64 Expect.equals(-29719, dt.year);
65 Expect.equals(4, dt.month);
66 Expect.equals(5, dt.day);
67 Expect.equals(22, dt.hour);
68 Expect.equals(13, dt.minute);
69 Expect.equals(19, dt.second);
70 Expect.equals(999, dt.millisecond);
71 Expect.equals(0, dt.microsecond);
72 // Same with local zone.
73 dt = new DateTime.fromMillisecondsSinceEpoch(1000000000000001);
74 Expect.equals(33658, dt.year);
75 Expect.equals(9, dt.month);
76 Expect.equals(true, dt.day == 27 || dt.day == 26);
77 // Not much we can test for local hour.
78 Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
79 // Timezones can have offsets down to 15 minute.
80 Expect.equals(true, dt.minute % 15 == 46 % 15);
81 Expect.equals(40, dt.second);
82 Expect.equals(1, dt.millisecond);
83 Expect.equals(0, dt.microsecond);
84 dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001);
85 Expect.equals(-29719, dt.year);
86 Expect.equals(4, dt.month);
87 Expect.equals(true, 5 == dt.day || 6 == dt.day);
88 // Not much we can test for local hour.
89 Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
90 // Timezones can have offsets down to 15 minute.
91 Expect.equals(true, dt.minute % 15 == 13);
92 Expect.equals(19, dt.second);
93 Expect.equals(999, dt.millisecond);
94 Expect.equals(0, dt.microsecond);
95
96 if (!supportsMicroseconds) return;
97 dt =
98 new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001, isUtc: true);
99 Expect.equals(33658, dt.year);
100 Expect.equals(9, dt.month);
101 Expect.equals(27, dt.day);
102 Expect.equals(1, dt.hour);
103 Expect.equals(46, dt.minute);
104 Expect.equals(40, dt.second);
105 Expect.equals(0, dt.millisecond);
106 Expect.equals(1, dt.microsecond);
107 dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001,
108 isUtc: true);
109 Expect.equals(-29719, dt.year);
110 Expect.equals(4, dt.month);
111 Expect.equals(5, dt.day);
112 Expect.equals(22, dt.hour);
113 Expect.equals(13, dt.minute);
114 Expect.equals(19, dt.second);
115 Expect.equals(999, dt.millisecond);
116 Expect.equals(999, dt.microsecond);
117 // Same with local zone.
118 dt = new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001);
119 Expect.equals(33658, dt.year);
120 Expect.equals(9, dt.month);
121 Expect.equals(true, dt.day == 27 || dt.day == 26);
122 // Not much we can test for local hour.
123 Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
124 // Timezones can have offsets down to 15 minute.
125 Expect.equals(true, dt.minute % 15 == 46 % 15);
126 Expect.equals(40, dt.second);
127 Expect.equals(0, dt.millisecond);
128 Expect.equals(1, dt.microsecond);
129 dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001);
130 Expect.equals(-29719, dt.year);
131 Expect.equals(4, dt.month);
132 Expect.equals(true, 5 == dt.day || 6 == dt.day);
133 // Not much we can test for local hour.
134 Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
135 // Timezones can have offsets down to 15 minute.
136 Expect.equals(true, dt.minute % 15 == 13);
137 Expect.equals(19, dt.second);
138 Expect.equals(999, dt.millisecond);
139 Expect.equals(999, dt.microsecond);
140 }
141
142 void testEquivalentYears() {
143 // All hardcoded values come from V8. This means that the values are not
144 // necessarily correct (see limitations of DateTime object in
145 // EcmaScript 15.9.1 and in particular 15.9.1.8/9).
146 DateTime dt =
147 new DateTime.fromMillisecondsSinceEpoch(-31485600000, isUtc: true);
148 Expect.equals(1969, dt.year);
149 Expect.equals(1, dt.month);
150 Expect.equals(1, dt.day);
151 Expect.equals(14, dt.hour);
152 Expect.equals(0, dt.minute);
153 Expect.equals(0, dt.second);
154 Expect.equals(0, dt.millisecond);
155 Expect.equals(0, dt.microsecond);
156 dt = new DateTime.fromMillisecondsSinceEpoch(-63108000000, isUtc: true);
157 Expect.equals(1968, dt.year);
158 Expect.equals(1, dt.month);
159 Expect.equals(1, dt.day);
160 Expect.equals(14, dt.hour);
161 Expect.equals(0, dt.minute);
162 Expect.equals(0, dt.second);
163 Expect.equals(0, dt.millisecond);
164 Expect.equals(0, dt.microsecond);
165 dt = new DateTime.fromMillisecondsSinceEpoch(-94644000000, isUtc: true);
166 Expect.equals(1967, dt.year);
167 Expect.equals(1, dt.month);
168 Expect.equals(1, dt.day);
169 Expect.equals(14, dt.hour);
170 Expect.equals(0, dt.minute);
171 Expect.equals(0, dt.second);
172 Expect.equals(0, dt.millisecond);
173 Expect.equals(0, dt.microsecond);
174 dt = new DateTime.fromMillisecondsSinceEpoch(-126180000000, isUtc: true);
175 Expect.equals(1966, dt.year);
176 Expect.equals(1, dt.month);
177 Expect.equals(1, dt.day);
178 Expect.equals(14, dt.hour);
179 Expect.equals(0, dt.minute);
180 Expect.equals(0, dt.second);
181 Expect.equals(0, dt.millisecond);
182 Expect.equals(0, dt.microsecond);
183 dt = new DateTime.fromMillisecondsSinceEpoch(-157716000000, isUtc: true);
184 Expect.equals(1965, dt.year);
185 Expect.equals(1, dt.month);
186 Expect.equals(1, dt.day);
187 Expect.equals(14, dt.hour);
188 Expect.equals(0, dt.minute);
189 Expect.equals(0, dt.second);
190 Expect.equals(0, dt.millisecond);
191 Expect.equals(0, dt.microsecond);
192 dt = new DateTime.fromMillisecondsSinceEpoch(-2177402400000, isUtc: true);
193 Expect.equals(1901, dt.year);
194 Expect.equals(1, dt.month);
195 Expect.equals(1, dt.day);
196 Expect.equals(14, dt.hour);
197 Expect.equals(0, dt.minute);
198 Expect.equals(0, dt.second);
199 Expect.equals(0, dt.millisecond);
200 Expect.equals(0, dt.microsecond);
201 dt = new DateTime.fromMillisecondsSinceEpoch(-5333076000000, isUtc: true);
202 Expect.equals(1801, dt.year);
203 Expect.equals(1, dt.month);
204 Expect.equals(1, dt.day);
205 Expect.equals(14, dt.hour);
206 Expect.equals(0, dt.minute);
207 Expect.equals(0, dt.second);
208 Expect.equals(0, dt.millisecond);
209 Expect.equals(0, dt.microsecond);
210 dt = new DateTime.fromMillisecondsSinceEpoch(-8520285600000, isUtc: true);
211 Expect.equals(1700, dt.year);
212 Expect.equals(1, dt.month);
213 Expect.equals(1, dt.day);
214 Expect.equals(14, dt.hour);
215 Expect.equals(0, dt.minute);
216 Expect.equals(0, dt.second);
217 Expect.equals(0, dt.millisecond);
218 Expect.equals(0, dt.microsecond);
219 dt = new DateTime.fromMillisecondsSinceEpoch(-14831719200000, isUtc: true);
220 Expect.equals(1500, dt.year);
221 Expect.equals(1, dt.month);
222 Expect.equals(1, dt.day);
223 Expect.equals(14, dt.hour);
224 Expect.equals(0, dt.minute);
225 Expect.equals(0, dt.second);
226 Expect.equals(0, dt.millisecond);
227 Expect.equals(0, dt.microsecond);
228 dt = new DateTime.fromMillisecondsSinceEpoch(-59011408800000, isUtc: true);
229 Expect.equals(100, dt.year);
230 Expect.equals(1, dt.month);
231 Expect.equals(1, dt.day);
232 Expect.equals(14, dt.hour);
233 Expect.equals(0, dt.minute);
234 Expect.equals(0, dt.second);
235 Expect.equals(0, dt.millisecond);
236 Expect.equals(0, dt.microsecond);
237 dt = new DateTime.fromMillisecondsSinceEpoch(-62011408800000, isUtc: true);
238 Expect.equals(4, dt.year);
239 Expect.equals(12, dt.month);
240 Expect.equals(8, dt.day);
241 Expect.equals(8, dt.hour);
242 Expect.equals(40, dt.minute);
243 Expect.equals(0, dt.second);
244 Expect.equals(0, dt.millisecond);
245 Expect.equals(0, dt.microsecond);
246 dt = new DateTime.fromMillisecondsSinceEpoch(-64011408800000, isUtc: true);
247 Expect.equals(-59, dt.year);
248 Expect.equals(7, dt.month);
249 Expect.equals(24, dt.day);
250 Expect.equals(5, dt.hour);
251 Expect.equals(6, dt.minute);
252 Expect.equals(40, dt.second);
253 Expect.equals(0, dt.millisecond);
254 Expect.equals(0, dt.microsecond);
255 final int SECONDS_YEAR_2035 = 2051222400;
256 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 + 1,
257 isUtc: true);
258 Expect.equals(2035, dt.year);
259 Expect.equals(1, dt.month);
260 Expect.equals(1, dt.day);
261 Expect.equals(0, dt.hour);
262 Expect.equals(0, dt.minute);
263 Expect.equals(0, dt.second);
264 Expect.equals(1, dt.millisecond);
265 Expect.equals(0, dt.microsecond);
266 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 - 1,
267 isUtc: true);
268 Expect.equals(2034, dt.year);
269 Expect.equals(12, dt.month);
270 Expect.equals(31, dt.day);
271 Expect.equals(23, dt.hour);
272 Expect.equals(59, dt.minute);
273 Expect.equals(59, dt.second);
274 Expect.equals(999, dt.millisecond);
275 Expect.equals(0, dt.microsecond);
276
277 dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 1);
278 Expect.equals(SECONDS_YEAR_2035 * 1000 + 1, dt.millisecondsSinceEpoch);
279 dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999);
280 Expect.equals(SECONDS_YEAR_2035 * 1000 - 1, dt.millisecondsSinceEpoch);
281 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 + 1);
282 Expect.equals(
283 true,
284 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
285 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
286 Expect.equals(0, dt.second);
287 Expect.equals(1, dt.millisecond);
288 DateTime dt2 = new DateTime(
289 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.millisecond);
290 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
291 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 - 1);
292 Expect.equals(
293 true,
294 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
295 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
296 Expect.equals(59, dt.second);
297 Expect.equals(999, dt.millisecond);
298 Expect.equals(0, dt.microsecond);
299
300 dt2 = new DateTime(
301 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.millisecond);
302 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
303 dt = new DateTime.fromMillisecondsSinceEpoch(2100000000 * 1000, isUtc: true);
304 Expect.equals(2036, dt.year);
305 Expect.equals(7, dt.month);
306 Expect.equals(18, dt.day);
307 Expect.equals(13, dt.hour);
308 Expect.equals(20, dt.minute);
309 Expect.equals(0, dt.second);
310 Expect.equals(0, dt.millisecond);
311 Expect.equals(0, dt.microsecond);
312
313 // Internally this will use the maximum value for the native calls.
314 dt = new DateTime(2036, 7, 18, 13, 20);
315 Expect.equals(2036, dt.year);
316 Expect.equals(7, dt.month);
317 Expect.equals(18, dt.day);
318 Expect.equals(13, dt.hour);
319 Expect.equals(20, dt.minute);
320 Expect.equals(0, dt.second);
321 Expect.equals(0, dt.millisecond);
322 Expect.equals(0, dt.microsecond);
323 Expect.equals("2036-07-18 13:20:00.000", dt.toString());
324
325 if (!supportsMicroseconds) return;
326
327 dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 0, 1);
328 Expect.equals(SECONDS_YEAR_2035 * 1000000 + 1, dt.microsecondsSinceEpoch);
329 dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999, 999);
330 Expect.equals(SECONDS_YEAR_2035 * 1000000 - 1, dt.microsecondsSinceEpoch);
331 dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 + 1);
332 Expect.equals(
333 true,
334 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
335 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
336 Expect.equals(0, dt.second);
337 Expect.equals(0, dt.millisecond);
338 Expect.equals(1, dt.microsecond);
339 dt2 = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
340 dt.millisecond, dt.microsecond);
341 Expect.equals(dt.microsecondsSinceEpoch, dt2.microsecondsSinceEpoch);
342 dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 - 1);
343 Expect.equals(
344 true,
345 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
346 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
347 Expect.equals(59, dt.second);
348 Expect.equals(999, dt.millisecond);
349 Expect.equals(999, dt.microsecond);
350
351 dt2 = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
352 dt.millisecond, dt.microsecond);
353 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
354 dt = new DateTime.fromMicrosecondsSinceEpoch(2100000000 * 1000000,
355 isUtc: true);
356 Expect.equals(2036, dt.year);
357 Expect.equals(7, dt.month);
358 Expect.equals(18, dt.day);
359 Expect.equals(13, dt.hour);
360 Expect.equals(20, dt.minute);
361 Expect.equals(0, dt.second);
362 Expect.equals(0, dt.millisecond);
363 Expect.equals(0, dt.microsecond);
364 }
365
366 void testExtremes() {
367 var dt =
368 new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
369 Expect.equals(275760, dt.year);
370 Expect.equals(9, dt.month);
371 Expect.equals(13, dt.day);
372 Expect.equals(0, dt.hour);
373 Expect.equals(0, dt.minute);
374 Expect.equals(0, dt.second);
375 Expect.equals(0, dt.millisecond);
376 Expect.equals(0, dt.microsecond);
377 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
378 Expect.equals(-271821, dt.year);
379 Expect.equals(4, dt.month);
380 Expect.equals(20, dt.day);
381 Expect.equals(0, dt.hour);
382 Expect.equals(0, dt.minute);
383 Expect.equals(0, dt.second);
384 Expect.equals(0, dt.millisecond);
385 Expect.equals(0, dt.microsecond);
386 // Make sure that we can build the extreme dates in local too.
387 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
388 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
389 Expect.equals(_MAX_MILLISECONDS, dt.millisecondsSinceEpoch);
390 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
391 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
392 Expect.equals(-_MAX_MILLISECONDS, dt.millisecondsSinceEpoch);
393 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch(
394 _MAX_MILLISECONDS + 1,
395 isUtc: true));
396 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch(
397 -_MAX_MILLISECONDS - 1,
398 isUtc: true));
399 Expect.throws(
400 () => new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS + 1));
401 Expect.throws(
402 () => new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS - 1));
403 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
404 Expect.throws(
405 () => new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 1));
406 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
407 Expect.throws(() =>
408 new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 1));
409 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
410 Expect.throws(
411 () => new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, -1));
412 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
413 Expect.throws(() =>
414 new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, -1));
415
416 if (!supportsMicroseconds) return;
417
418 dt = new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000);
419 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
420 Expect.equals(_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
421 dt = new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000);
422 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
423 Expect.equals(-_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
424 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
425 _MAX_MILLISECONDS * 1000 + 1,
426 isUtc: true));
427 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
428 -_MAX_MILLISECONDS * 1000 - 1,
429 isUtc: true));
430 Expect.throws(() =>
431 new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000 + 1));
432 Expect.throws(() =>
433 new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000 - 1));
434 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
435 Expect.throws(() =>
436 new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, 1));
437 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
438 Expect.throws(() =>
439 new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, 1));
440 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
441 Expect.throws(() =>
442 new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, -1));
443 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
444 Expect.throws(() => new DateTime.utc(
445 dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, -1));
446 }
447
448 void testUTCGetters() {
449 var dt = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
450 Expect.equals(2011, dt.year);
451 Expect.equals(5, dt.month);
452 Expect.equals(11, dt.day);
453 Expect.equals(18, dt.hour);
454 Expect.equals(58, dt.minute);
455 Expect.equals(35, dt.second);
456 Expect.equals(0, dt.millisecond);
457 Expect.equals(0, dt.microsecond);
458 Expect.equals(true, dt.isUtc);
459 Expect.equals(1305140315000, dt.millisecondsSinceEpoch);
460 dt = new DateTime.fromMillisecondsSinceEpoch(-9999999, isUtc: true);
461 Expect.equals(1969, dt.year);
462 Expect.equals(12, dt.month);
463 Expect.equals(31, dt.day);
464 Expect.equals(21, dt.hour);
465 Expect.equals(13, dt.minute);
466 Expect.equals(20, dt.second);
467 Expect.equals(1, dt.millisecond);
468 Expect.equals(0, dt.microsecond);
469
470 if (!supportsMicroseconds) return;
471
472 dt = new DateTime.fromMicrosecondsSinceEpoch(-9999999999, isUtc: true);
473 Expect.equals(1969, dt.year);
474 Expect.equals(12, dt.month);
475 Expect.equals(31, dt.day);
476 Expect.equals(21, dt.hour);
477 Expect.equals(13, dt.minute);
478 Expect.equals(20, dt.second);
479 Expect.equals(0, dt.millisecond);
480 Expect.equals(1, dt.microsecond);
481 }
482
483 void testLocalGetters() {
484 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000);
485 var dt2 = new DateTime.utc(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
486 dt1.second, dt1.millisecond, dt1.microsecond);
487 Duration zoneOffset = dt1.difference(dt2);
488 Expect.equals(true, zoneOffset.inDays == 0);
489 Expect.equals(true, zoneOffset.inHours.abs() <= 12);
490 Expect.equals(dt1.year, dt2.year);
491 Expect.equals(dt1.month, dt2.month);
492 Expect.equals(true, (dt1.day - dt2.day).abs() <= 1);
493 Expect.equals(true, dt1.hour < 24);
494 // There are timezones with 0.5 or 0.25 hour offsets.
495 Expect.equals(
496 true,
497 (dt1.minute == dt2.minute) ||
498 ((dt1.minute - dt2.minute).abs() == 30) ||
499 ((dt1.minute - dt2.minute).abs() == 15));
500 Expect.equals(dt1.second, dt2.second);
501 Expect.equals(dt1.millisecond, dt2.millisecond);
502 Expect.equals(dt1.microsecond, dt2.microsecond);
503 }
504
505 void testConstructors() {
506 var dt0 = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0);
507 var dt0b = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0).toLocal();
508 Expect.equals(1305140315000, dt0.millisecondsSinceEpoch);
509 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000);
510 Expect.equals(dt1.millisecondsSinceEpoch, dt0.millisecondsSinceEpoch);
511 Expect.equals(dt1.microsecondsSinceEpoch, dt0.microsecondsSinceEpoch);
512 Expect.equals(false, dt1 == dt0);
513 Expect.equals(true, dt1 == dt0b);
514 var dt3 = new DateTime(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
515 dt1.second, dt1.millisecond, dt1.microsecond);
516 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
517 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
518 Expect.equals(false, dt3 == dt0);
519 Expect.equals(true, dt1 == dt3);
520 dt3 = new DateTime(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
521 dt1.second, dt1.millisecond, dt1.microsecond);
522 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
523 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
524 Expect.equals(true, dt1 == dt3);
525 var dt2 = dt1.toLocal();
526 dt3 = new DateTime(2011, 5, dt1.day, dt1.hour, dt1.minute, 35, 0, 0);
527 Expect.equals(dt2.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
528 Expect.equals(dt2.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
529 Expect.equals(true, dt2 == dt3);
530 dt1 = new DateTime.fromMillisecondsSinceEpoch(-9999999, isUtc: true);
531 dt3 = new DateTime.utc(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
532 dt1.second, dt1.millisecond);
533 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
534 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
535 dt3 = new DateTime.utc(99, 1, 2, 10, 11, 12, 0);
536 Expect.equals(99, dt3.year);
537 Expect.equals(1, dt3.month);
538 Expect.equals(2, dt3.day);
539 Expect.equals(10, dt3.hour);
540 Expect.equals(11, dt3.minute);
541 Expect.equals(12, dt3.second);
542 Expect.equals(0, dt3.millisecond);
543 Expect.equals(0, dt3.microsecond);
544 Expect.equals(true, dt3.isUtc);
545 var dt4 = new DateTime(99, 1, 2);
546 Expect.equals(99, dt4.year);
547 Expect.equals(1, dt4.month);
548 Expect.equals(2, dt4.day);
549 Expect.equals(0, dt4.hour);
550 Expect.equals(0, dt4.minute);
551 Expect.equals(0, dt4.second);
552 Expect.equals(0, dt4.millisecond);
553 Expect.equals(0, dt4.microsecond);
554 Expect.isFalse(dt4.isUtc);
555 var dt5 = new DateTime.utc(99, 1, 2);
556 Expect.equals(99, dt5.year);
557 Expect.equals(1, dt5.month);
558 Expect.equals(2, dt5.day);
559 Expect.equals(0, dt5.hour);
560 Expect.equals(0, dt5.minute);
561 Expect.equals(0, dt5.second);
562 Expect.equals(0, dt5.millisecond);
563 Expect.equals(0, dt5.microsecond);
564 Expect.isTrue(dt5.isUtc);
565 var dt6 = new DateTime(2012, 2, 27, 13, 27, 0);
566 Expect.equals(2012, dt6.year);
567 Expect.equals(2, dt6.month);
568 Expect.equals(27, dt6.day);
569 Expect.equals(13, dt6.hour);
570 Expect.equals(27, dt6.minute);
571 Expect.equals(0, dt6.second);
572 Expect.equals(0, dt6.millisecond);
573 Expect.equals(0, dt6.microsecond);
574 Expect.isFalse(dt6.isUtc);
575 var dt7 = new DateTime.utc(2012, 2, 27, 13, 27, 0);
576 Expect.equals(2012, dt7.year);
577 Expect.equals(2, dt7.month);
578 Expect.equals(27, dt7.day);
579 Expect.equals(13, dt7.hour);
580 Expect.equals(27, dt7.minute);
581 Expect.equals(0, dt7.second);
582 Expect.equals(0, dt7.millisecond);
583 Expect.equals(0, dt7.microsecond);
584 Expect.isTrue(dt7.isUtc);
585 }
586
587 void testChangeTimeZone() {
588 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000);
589 var dt2 = dt1.toUtc();
590 Expect.equals(dt1.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
591 var dt3 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
592 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
593 Expect.equals(dt2.year, dt3.year);
594 Expect.equals(dt2.month, dt3.month);
595 Expect.equals(dt2.day, dt3.day);
596 Expect.equals(dt2.hour, dt3.hour);
597 Expect.equals(dt2.minute, dt3.minute);
598 Expect.equals(dt2.second, dt3.second);
599 Expect.equals(dt2.millisecond, dt3.millisecond);
600 Expect.equals(dt2.microsecond, dt3.microsecond);
601 var dt4 = dt3.toLocal();
602 Expect.equals(dt1.year, dt4.year);
603 Expect.equals(dt1.month, dt4.month);
604 Expect.equals(dt1.day, dt4.day);
605 Expect.equals(dt1.hour, dt4.hour);
606 Expect.equals(dt1.minute, dt4.minute);
607 Expect.equals(dt1.second, dt4.second);
608 Expect.equals(dt1.millisecond, dt4.millisecond);
609 Expect.equals(dt1.microsecond, dt4.microsecond);
610 }
611
612 void testSubAdd() {
613 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
614 var dt2 = dt1.add(
615 new Duration(milliseconds: 3 * Duration.MILLISECONDS_PER_SECOND + 5));
616 Expect.equals(dt1.year, dt2.year);
617 Expect.equals(dt1.month, dt2.month);
618 Expect.equals(dt1.day, dt2.day);
619 Expect.equals(dt1.hour, dt2.hour);
620 Expect.equals(dt1.minute, dt2.minute);
621 Expect.equals(dt1.second + 3, dt2.second);
622 Expect.equals(dt1.millisecond + 5, dt2.millisecond);
623 Expect.equals(dt1.microsecond, dt2.microsecond);
624 var dt3 = dt2.subtract(
625 new Duration(milliseconds: 3 * Duration.MILLISECONDS_PER_SECOND + 5));
626 Expect.equals(true, dt1 == dt3);
627 Expect.equals(false, dt1 == dt2);
628
629 if (!supportsMicroseconds) return;
630
631 dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
632 dt2 = dt1.add(
633 new Duration(microseconds: 3 * Duration.MICROSECONDS_PER_SECOND + 5));
634 Expect.equals(dt1.year, dt2.year);
635 Expect.equals(dt1.month, dt2.month);
636 Expect.equals(dt1.day, dt2.day);
637 Expect.equals(dt1.hour, dt2.hour);
638 Expect.equals(dt1.minute, dt2.minute);
639 Expect.equals(dt1.second + 3, dt2.second);
640 Expect.equals(dt1.millisecond, dt2.millisecond);
641 Expect.equals(dt1.microsecond + 5, dt2.microsecond);
642 dt3 = dt2.subtract(
643 new Duration(microseconds: 3 * Duration.MICROSECONDS_PER_SECOND + 5));
644 Expect.equals(true, dt1 == dt3);
645 Expect.equals(false, dt1 == dt2);
646 }
647
648 void testUnderflowAndOverflow() {
649 int microsecond = supportsMicroseconds ? 499 : 0;
650 final dtBase = new DateTime(2012, 6, 20, 12, 30, 30, 500, microsecond);
651
652 // Millisecond
653 print(" >>> Millisecond+");
654 var dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
655 dtBase.minute, dtBase.second, 1000, dtBase.microsecond);
656 Expect.equals(dtBase.year, dt.year);
657 Expect.equals(dtBase.month, dt.month);
658 Expect.equals(dtBase.day, dt.day);
659 Expect.equals(dtBase.hour, dt.hour);
660 Expect.equals(dtBase.minute, dt.minute);
661 Expect.equals(dtBase.second + 1, dt.second);
662 Expect.equals(0, dt.millisecond);
663 Expect.equals(dtBase.microsecond, dt.microsecond);
664
665 print(" >>> Millisecond-");
666 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
667 dtBase.minute, dtBase.second, -1000, dtBase.microsecond);
668 Expect.equals(dtBase.year, dt.year);
669 Expect.equals(dtBase.month, dt.month);
670 Expect.equals(dtBase.day, dt.day);
671 Expect.equals(dtBase.hour, dt.hour);
672 Expect.equals(dtBase.minute, dt.minute);
673 Expect.equals(dtBase.second - 1, dt.second);
674 Expect.equals(0, dt.millisecond);
675 Expect.equals(dtBase.microsecond, dt.microsecond);
676
677 // Second
678 print(" >>> Second+");
679 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
680 dtBase.minute, 60, dtBase.millisecond, dtBase.microsecond);
681 Expect.equals(dtBase.year, dt.year);
682 Expect.equals(dtBase.month, dt.month);
683 Expect.equals(dtBase.day, dt.day);
684 Expect.equals(dtBase.hour, dt.hour);
685 Expect.equals(dtBase.minute + 1, dt.minute);
686 Expect.equals(0, dt.second);
687 Expect.equals(dtBase.millisecond, dt.millisecond);
688 Expect.equals(dtBase.microsecond, dt.microsecond);
689
690 print(" >>> Second-");
691 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
692 dtBase.minute, -60, dtBase.millisecond, dtBase.microsecond);
693 Expect.equals(dtBase.year, dt.year);
694 Expect.equals(dtBase.month, dt.month);
695 Expect.equals(dtBase.day, dt.day);
696 Expect.equals(dtBase.hour, dt.hour);
697 Expect.equals(dtBase.minute - 1, dt.minute);
698 Expect.equals(0, dt.second);
699 Expect.equals(dtBase.millisecond, dt.millisecond);
700 Expect.equals(dtBase.microsecond, dt.microsecond);
701
702 // Minute
703 print(" >>> Minute+");
704 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 60,
705 dtBase.second, dtBase.millisecond, dtBase.microsecond);
706 Expect.equals(dtBase.year, dt.year);
707 Expect.equals(dtBase.month, dt.month);
708 Expect.equals(dtBase.day, dt.day);
709 Expect.equals(dtBase.hour + 1, dt.hour);
710 Expect.equals(0, dt.minute);
711 Expect.equals(dtBase.second, dt.second);
712 Expect.equals(dtBase.millisecond, dt.millisecond);
713 Expect.equals(dtBase.microsecond, dt.microsecond);
714
715 print(" >>> Minute-");
716 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, -60,
717 dtBase.second, dtBase.millisecond, dtBase.microsecond);
718 Expect.equals(dtBase.year, dt.year);
719 Expect.equals(dtBase.month, dt.month);
720 Expect.equals(dtBase.day, dt.day);
721 Expect.equals(dtBase.hour - 1, dt.hour);
722 Expect.equals(0, dt.minute);
723 Expect.equals(dtBase.second, dt.second);
724 Expect.equals(dtBase.millisecond, dt.millisecond);
725 Expect.equals(dtBase.microsecond, dt.microsecond);
726
727 // Hour
728 print(" >>> Hour+");
729 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, 24, dtBase.minute,
730 dtBase.second, dtBase.millisecond, dtBase.microsecond);
731 Expect.equals(dtBase.year, dt.year);
732 Expect.equals(dtBase.month, dt.month);
733 Expect.equals(dtBase.day + 1, dt.day);
734 Expect.equals(0, dt.hour);
735 Expect.equals(dtBase.minute, dt.minute);
736 Expect.equals(dtBase.second, dt.second);
737 Expect.equals(dtBase.millisecond, dt.millisecond);
738 Expect.equals(dtBase.microsecond, dt.microsecond);
739
740 print(" >>> Hour-");
741 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, -24, dtBase.minute,
742 dtBase.second, dtBase.millisecond, dtBase.microsecond);
743 Expect.equals(dtBase.year, dt.year);
744 Expect.equals(dtBase.month, dt.month);
745 Expect.equals(dtBase.day - 1, dt.day);
746 Expect.equals(0, dt.hour);
747 Expect.equals(dtBase.minute, dt.minute);
748 Expect.equals(dtBase.second, dt.second);
749 Expect.equals(dtBase.millisecond, dt.millisecond);
750 Expect.equals(dtBase.microsecond, dt.microsecond);
751
752 // Day
753 print(" >>> Day+");
754 dt = new DateTime(dtBase.year, dtBase.month, 31, dtBase.hour, dtBase.minute,
755 dtBase.second, dtBase.millisecond, dtBase.microsecond);
756 Expect.equals(dtBase.year, dt.year);
757 Expect.equals(dtBase.month + 1, dt.month);
758 Expect.equals(1, dt.day);
759 Expect.equals(dtBase.hour, dt.hour);
760 Expect.equals(dtBase.minute, dt.minute);
761 Expect.equals(dtBase.second, dt.second);
762 Expect.equals(dtBase.millisecond, dt.millisecond);
763 Expect.equals(dtBase.microsecond, dt.microsecond);
764
765 print(" >>> Day-");
766 dt = new DateTime(dtBase.year, dtBase.month, -30, dtBase.hour, dtBase.minute,
767 dtBase.second, dtBase.millisecond, dtBase.microsecond);
768 Expect.equals(dtBase.year, dt.year);
769 Expect.equals(dtBase.month - 1, dt.month);
770 Expect.equals(1, dt.day);
771 Expect.equals(dtBase.hour, dt.hour);
772 Expect.equals(dtBase.minute, dt.minute);
773 Expect.equals(dtBase.second, dt.second);
774 Expect.equals(dtBase.millisecond, dt.millisecond);
775 Expect.equals(dtBase.microsecond, dt.microsecond);
776
777 // Month
778 print(" >>> Month+");
779 dt = new DateTime(dtBase.year, 13, dtBase.day, dtBase.hour, dtBase.minute,
780 dtBase.second, dtBase.millisecond, dtBase.microsecond);
781 Expect.equals(dtBase.year + 1, dt.year);
782 Expect.equals(1, dt.month);
783 Expect.equals(dtBase.day, dt.day);
784 Expect.equals(dtBase.hour, dt.hour);
785 Expect.equals(dtBase.minute, dt.minute);
786 Expect.equals(dtBase.second, dt.second);
787 Expect.equals(dtBase.millisecond, dt.millisecond);
788 Expect.equals(dtBase.microsecond, dt.microsecond);
789
790 print(" >>> Month-");
791 dt = new DateTime(dtBase.year, -11, dtBase.day, dtBase.hour, dtBase.minute,
792 dtBase.second, dtBase.millisecond, dtBase.microsecond);
793 Expect.equals(dtBase.year - 1, dt.year);
794 Expect.equals(1, dt.month);
795 Expect.equals(dtBase.day, dt.day);
796 Expect.equals(dtBase.hour, dt.hour);
797 Expect.equals(dtBase.minute, dt.minute);
798 Expect.equals(dtBase.second, dt.second);
799 Expect.equals(dtBase.millisecond, dt.millisecond);
800 Expect.equals(dtBase.microsecond, dt.microsecond);
801
802 // Flowing all the way up the chain.
803 print(" >>> Flow+");
804 var dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 000);
805 var dtTick = new DateTime(
806 dtBase1.year,
807 dtBase1.month,
808 dtBase1.day,
809 dtBase1.hour,
810 dtBase1.minute,
811 dtBase1.second,
812 dtBase1.millisecond + 1,
813 dtBase1.microsecond);
814 Expect.equals(dtBase1.year + 1, dtTick.year);
815 Expect.equals(1, dtTick.month);
816 Expect.equals(1, dtTick.day);
817 Expect.equals(0, dtTick.hour);
818 Expect.equals(0, dtTick.minute);
819 Expect.equals(0, dtTick.second);
820 Expect.equals(0, dtTick.millisecond);
821 Expect.equals(0, dtTick.microsecond);
822
823 print(" >>> Flow-");
824 dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0);
825 dtTick = new DateTime(
826 dtBase1.year,
827 dtBase1.month,
828 dtBase1.day,
829 dtBase1.hour,
830 dtBase1.minute,
831 dtBase1.second,
832 dtBase1.millisecond - 1,
833 dtBase1.microsecond);
834 Expect.equals(dtBase1.year - 1, dtTick.year);
835 Expect.equals(12, dtTick.month);
836 Expect.equals(31, dtTick.day);
837 Expect.equals(23, dtTick.hour);
838 Expect.equals(59, dtTick.minute);
839 Expect.equals(59, dtTick.second);
840 Expect.equals(999, dtTick.millisecond);
841 Expect.equals(0, dtTick.microsecond);
842
843 print(" >>> extra underflow");
844 dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, -17520,
845 dtBase1.minute, dtBase1.second, dtBase1.millisecond, dtBase1.microsecond);
846 Expect.equals(dtBase1.year - 2, dtTick.year);
847 Expect.equals(dtBase1.month, dtTick.month);
848 Expect.equals(dtBase1.day, dtTick.day);
849 Expect.equals(dtBase1.hour, dtTick.hour);
850 Expect.equals(dtBase1.minute, dtTick.minute);
851 Expect.equals(dtBase1.second, dtTick.second);
852 Expect.equals(dtBase1.millisecond, dtTick.millisecond);
853 Expect.equals(dtBase1.microsecond, dtTick.microsecond);
854
855 if (!supportsMicroseconds) return;
856
857 // Microsecond
858 print(" >>> Microsecond+");
859 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
860 dtBase.minute, dtBase.second, dtBase.millisecond, 1000);
861 Expect.equals(dtBase.year, dt.year);
862 Expect.equals(dtBase.month, dt.month);
863 Expect.equals(dtBase.day, dt.day);
864 Expect.equals(dtBase.hour, dt.hour);
865 Expect.equals(dtBase.minute, dt.minute);
866 Expect.equals(dtBase.second, dt.second);
867 Expect.equals(dtBase.millisecond + 1, dt.millisecond);
868 Expect.equals(0, dt.microsecond);
869
870 print(" >>> Microsecond-");
871 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
872 dtBase.minute, dtBase.second, dtBase.millisecond, -1000);
873 Expect.equals(dtBase.year, dt.year);
874 Expect.equals(dtBase.month, dt.month);
875 Expect.equals(dtBase.day, dt.day);
876 Expect.equals(dtBase.hour, dt.hour);
877 Expect.equals(dtBase.minute, dt.minute);
878 Expect.equals(dtBase.second, dt.second);
879 Expect.equals(dtBase.millisecond - 1, dt.millisecond);
880 Expect.equals(0, dt.microsecond);
881
882 // Flowing all the way up the chain.
883 print(" >>> Flow+ 2");
884 dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 999);
885 dtTick = new DateTime(
886 dtBase1.year,
887 dtBase1.month,
888 dtBase1.day,
889 dtBase1.hour,
890 dtBase1.minute,
891 dtBase1.second,
892 dtBase1.millisecond,
893 dtBase1.microsecond + 1);
894 Expect.equals(dtBase1.year + 1, dtTick.year);
895 Expect.equals(1, dtTick.month);
896 Expect.equals(1, dtTick.day);
897 Expect.equals(0, dtTick.hour);
898 Expect.equals(0, dtTick.minute);
899 Expect.equals(0, dtTick.second);
900 Expect.equals(0, dtTick.millisecond);
901 Expect.equals(0, dtTick.microsecond);
902
903 print(" >>> Flow- 2");
904 dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0, 0);
905 dtTick = new DateTime(
906 dtBase1.year,
907 dtBase1.month,
908 dtBase1.day,
909 dtBase1.hour,
910 dtBase1.minute,
911 dtBase1.second,
912 dtBase1.millisecond,
913 dtBase1.microsecond - 1);
914 Expect.equals(dtBase1.year - 1, dtTick.year);
915 Expect.equals(12, dtTick.month);
916 Expect.equals(31, dtTick.day);
917 Expect.equals(23, dtTick.hour);
918 Expect.equals(59, dtTick.minute);
919 Expect.equals(59, dtTick.second);
920 Expect.equals(999, dtTick.millisecond);
921 Expect.equals(999, dtTick.microsecond);
922 }
923
924 void testDateStrings() {
925 // TODO(floitsch): Clean up the DateTime API that deals with strings.
926 var dt1 = DateTime.parse("2011-05-11 18:58:35Z");
927 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch);
928 Expect.isTrue(dt1.isUtc);
929 dt1 = DateTime.parse("20110511 18:58:35z");
930 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch);
931 Expect.isTrue(dt1.isUtc);
932 dt1 = DateTime.parse("+20110511 18:58:35z");
933 Expect.equals(1305140315000, dt1.millisecondsSinceEpoch);
934 Expect.isTrue(dt1.isUtc);
935 var str = dt1.toString();
936 var dt2 = DateTime.parse(str);
937 Expect.equals(true, dt1 == dt2);
938 var dt3 = dt1.toUtc();
939 str = dt3.toString();
940 Expect.equals("2011-05-11 18:58:35.000Z", str);
941 var dt4 = DateTime.parse("-1234-01-01 00:00:00Z");
942 Expect.equals(-1234, dt4.year);
943 Expect.equals(1, dt4.month);
944 Expect.equals(1, dt4.day);
945 Expect.equals(0, dt4.hour);
946 Expect.equals(0, dt4.minute);
947 Expect.equals(0, dt4.second);
948 Expect.equals(0, dt4.millisecond);
949 Expect.equals(0, dt4.microsecond);
950 Expect.isTrue(dt4.isUtc);
951 var dt5 = DateTime.parse("0099-01-02");
952 Expect.equals(99, dt5.year);
953 Expect.equals(1, dt5.month);
954 Expect.equals(2, dt5.day);
955 Expect.equals(0, dt5.hour);
956 Expect.equals(0, dt5.minute);
957 Expect.equals(0, dt5.second);
958 Expect.equals(0, dt5.millisecond);
959 Expect.equals(0, dt5.microsecond);
960 Expect.isFalse(dt5.isUtc);
961 var dt6 = DateTime.parse("2012-01-01 00:00:10.012");
962 Expect.equals(12, dt6.millisecond);
963 Expect.equals(0, dt6.microsecond);
964 dt6 = DateTime.parse("2012-01-01 00:00:10.003");
965 Expect.equals(3, dt6.millisecond);
966 Expect.equals(0, dt6.microsecond);
967 dt6 = DateTime.parse("2012-01-01 00:00:10.5");
968 Expect.equals(500, dt6.millisecond);
969 Expect.equals(0, dt6.microsecond);
970 dt6 = DateTime.parse("2012-01-01 00:00:10.003Z");
971 Expect.equals(3, dt6.millisecond);
972 Expect.equals(0, dt6.microsecond);
973 dt6 = DateTime.parse("2012-01-01 00:00:10.5z");
974 Expect.equals(500, dt6.millisecond);
975 Expect.equals(0, dt6.microsecond);
976 var dt7 = DateTime.parse("2011-05-11T18:58:35Z");
977 Expect.equals(1305140315000, dt7.millisecondsSinceEpoch);
978 var dt8 = DateTime.parse("-1234-01-01T00:00:00Z");
979 Expect.equals(-1234, dt8.year);
980 Expect.equals(1, dt8.month);
981 Expect.equals(1, dt8.day);
982 Expect.equals(0, dt8.hour);
983 Expect.equals(0, dt8.minute);
984 Expect.equals(0, dt8.second);
985 Expect.equals(0, dt8.millisecond);
986 Expect.equals(0, dt8.microsecond);
987 Expect.isTrue(dt8.isUtc);
988 var dt9 = DateTime.parse("-1234-01-01T00:00:00");
989 Expect.equals(-1234, dt9.year);
990 Expect.equals(1, dt9.month);
991 Expect.equals(1, dt9.day);
992 Expect.equals(0, dt9.hour);
993 Expect.equals(0, dt9.minute);
994 Expect.equals(0, dt9.second);
995 Expect.equals(0, dt9.millisecond);
996 Expect.equals(0, dt9.microsecond);
997 Expect.isFalse(dt9.isUtc);
998 var dt10 = DateTime.parse("-12340101");
999 Expect.equals(-1234, dt10.year);
1000 Expect.equals(1, dt10.month);
1001 Expect.equals(1, dt10.day);
1002 Expect.equals(0, dt10.hour);
1003 Expect.equals(0, dt10.minute);
1004 Expect.equals(0, dt10.second);
1005 Expect.equals(0, dt10.millisecond);
1006 Expect.equals(0, dt10.microsecond);
1007 Expect.isFalse(dt10.isUtc);
1008 dt1 = DateTime.parse("2012-02-27 13:27:00");
1009 Expect.equals(2012, dt1.year);
1010 Expect.equals(2, dt1.month);
1011 Expect.equals(27, dt1.day);
1012 Expect.equals(13, dt1.hour);
1013 Expect.equals(27, dt1.minute);
1014 Expect.equals(0, dt1.second);
1015 Expect.equals(0, dt1.millisecond);
1016 Expect.equals(0, dt1.microsecond);
1017 Expect.equals(false, dt1.isUtc);
1018 dt1 = DateTime.parse("2012-02-27 13:27:00.423z");
1019 Expect.equals(2012, dt1.year);
1020 Expect.equals(2, dt1.month);
1021 Expect.equals(27, dt1.day);
1022 Expect.equals(13, dt1.hour);
1023 Expect.equals(27, dt1.minute);
1024 Expect.equals(0, dt1.second);
1025 Expect.equals(423, dt1.millisecond);
1026 Expect.equals(0, dt1.microsecond);
1027 Expect.equals(true, dt1.isUtc);
1028 dt1 = DateTime.parse("20120227 13:27:00");
1029 Expect.equals(2012, dt1.year);
1030 Expect.equals(2, dt1.month);
1031 Expect.equals(27, dt1.day);
1032 Expect.equals(13, dt1.hour);
1033 Expect.equals(27, dt1.minute);
1034 Expect.equals(0, dt1.second);
1035 Expect.equals(0, dt1.millisecond);
1036 Expect.equals(0, dt1.microsecond);
1037 Expect.equals(false, dt1.isUtc);
1038 dt1 = DateTime.parse("20120227T132700");
1039 Expect.equals(2012, dt1.year);
1040 Expect.equals(2, dt1.month);
1041 Expect.equals(27, dt1.day);
1042 Expect.equals(13, dt1.hour);
1043 Expect.equals(27, dt1.minute);
1044 Expect.equals(0, dt1.second);
1045 Expect.equals(0, dt1.millisecond);
1046 Expect.equals(0, dt1.microsecond);
1047 Expect.equals(false, dt1.isUtc);
1048 dt1 = DateTime.parse("20120227");
1049 Expect.equals(2012, dt1.year);
1050 Expect.equals(2, dt1.month);
1051 Expect.equals(27, dt1.day);
1052 Expect.equals(0, dt1.hour);
1053 Expect.equals(0, dt1.minute);
1054 Expect.equals(0, dt1.second);
1055 Expect.equals(0, dt1.millisecond);
1056 Expect.equals(0, dt1.microsecond);
1057 Expect.equals(false, dt1.isUtc);
1058 dt1 = DateTime.parse("2012-02-27T14Z");
1059 Expect.equals(2012, dt1.year);
1060 Expect.equals(2, dt1.month);
1061 Expect.equals(27, dt1.day);
1062 Expect.equals(14, dt1.hour);
1063 Expect.equals(0, dt1.minute);
1064 Expect.equals(0, dt1.second);
1065 Expect.equals(0, dt1.millisecond);
1066 Expect.equals(0, dt1.microsecond);
1067 Expect.equals(true, dt1.isUtc);
1068 dt1 = DateTime.parse("-123450101 00:00:00 Z");
1069 Expect.equals(-12345, dt1.year);
1070 Expect.equals(1, dt1.month);
1071 Expect.equals(1, dt1.day);
1072 Expect.equals(0, dt1.hour);
1073 Expect.equals(0, dt1.minute);
1074 Expect.equals(0, dt1.second);
1075 Expect.equals(0, dt1.millisecond);
1076 Expect.equals(0, dt1.microsecond);
1077 Expect.equals(true, dt1.isUtc);
1078 dt1 = DateTime.parse("1999-01-02 23:59:59.99951");
1079 if (supportsMicroseconds) {
1080 Expect.equals(1999, dt1.year);
1081 Expect.equals(1, dt1.month);
1082 Expect.equals(2, dt1.day);
1083 Expect.equals(23, dt1.hour);
1084 Expect.equals(59, dt1.minute);
1085 Expect.equals(59, dt1.second);
1086 Expect.equals(999, dt1.millisecond);
1087 Expect.equals(510, dt1.microsecond);
1088 } else {
1089 // We only support millisecond. If the user supplies more data (the "51"
1090 // here), we round.
1091 Expect.equals(1999, dt1.year);
1092 Expect.equals(1, dt1.month);
1093 Expect.equals(3, dt1.day);
1094 Expect.equals(0, dt1.hour);
1095 Expect.equals(0, dt1.minute);
1096 Expect.equals(0, dt1.second);
1097 Expect.equals(0, dt1.millisecond);
1098 Expect.equals(0, dt1.microsecond);
1099 }
1100 Expect.equals(false, dt1.isUtc);
1101 dt1 = DateTime.parse("1999-01-02 23:58:59.99951Z");
1102 if (supportsMicroseconds) {
1103 Expect.equals(1999, dt1.year);
1104 Expect.equals(1, dt1.month);
1105 Expect.equals(2, dt1.day);
1106 Expect.equals(23, dt1.hour);
1107 Expect.equals(58, dt1.minute);
1108 Expect.equals(59, dt1.second);
1109 Expect.equals(999, dt1.millisecond);
1110 Expect.equals(510, dt1.microsecond);
1111 } else {
1112 Expect.equals(1999, dt1.year);
1113 Expect.equals(1, dt1.month);
1114 Expect.equals(2, dt1.day);
1115 Expect.equals(23, dt1.hour);
1116 Expect.equals(59, dt1.minute);
1117 Expect.equals(0, dt1.second);
1118 Expect.equals(0, dt1.millisecond);
1119 Expect.equals(0, dt1.microsecond);
1120 }
1121 Expect.equals(true, dt1.isUtc);
1122 dt1 = DateTime.parse("0009-09-09 09:09:09.009Z");
1123 Expect.equals(9, dt1.year);
1124 Expect.equals(9, dt1.month);
1125 Expect.equals(9, dt1.day);
1126 Expect.equals(9, dt1.hour);
1127 Expect.equals(9, dt1.minute);
1128 Expect.equals(9, dt1.second);
1129 Expect.equals(9, dt1.millisecond);
1130 Expect.equals(true, dt1.isUtc);
1131 dt1 = DateTime.parse("0009-09-09 09:09:09.009-00");
1132 Expect.equals(9, dt1.year);
1133 Expect.equals(9, dt1.month);
1134 Expect.equals(9, dt1.day);
1135 Expect.equals(9, dt1.hour);
1136 Expect.equals(9, dt1.minute);
1137 Expect.equals(9, dt1.second);
1138 Expect.equals(9, dt1.millisecond);
1139 Expect.equals(true, dt1.isUtc);
1140 dt1 = DateTime.parse("0009-09-09 09:09:09.009-0000");
1141 Expect.equals(9, dt1.year);
1142 Expect.equals(9, dt1.month);
1143 Expect.equals(9, dt1.day);
1144 Expect.equals(9, dt1.hour);
1145 Expect.equals(9, dt1.minute);
1146 Expect.equals(9, dt1.second);
1147 Expect.equals(9, dt1.millisecond);
1148 Expect.equals(true, dt1.isUtc);
1149 dt1 = DateTime.parse("0009-09-09 09:09:09.009-02");
1150 Expect.equals(9, dt1.year);
1151 Expect.equals(9, dt1.month);
1152 Expect.equals(9, dt1.day);
1153 Expect.equals(11, dt1.hour);
1154 Expect.equals(9, dt1.minute);
1155 Expect.equals(9, dt1.second);
1156 Expect.equals(9, dt1.millisecond);
1157 Expect.equals(true, dt1.isUtc);
1158 dt1 = DateTime.parse("0009-09-09 09:09:09.009+0200");
1159 Expect.equals(9, dt1.year);
1160 Expect.equals(9, dt1.month);
1161 Expect.equals(9, dt1.day);
1162 Expect.equals(7, dt1.hour);
1163 Expect.equals(9, dt1.minute);
1164 Expect.equals(9, dt1.second);
1165 Expect.equals(9, dt1.millisecond);
1166 Expect.equals(true, dt1.isUtc);
1167 dt1 = DateTime.parse("0009-09-09 09:09:09.009+1200");
1168 Expect.equals(9, dt1.year);
1169 Expect.equals(9, dt1.month);
1170 Expect.equals(8, dt1.day);
1171 Expect.equals(21, dt1.hour);
1172 Expect.equals(9, dt1.minute);
1173 Expect.equals(9, dt1.second);
1174 Expect.equals(9, dt1.millisecond);
1175 Expect.equals(true, dt1.isUtc);
1176 dt1 = DateTime.parse("0009-09-09 09:09:09.009-1200");
1177 Expect.equals(9, dt1.year);
1178 Expect.equals(9, dt1.month);
1179 Expect.equals(9, dt1.day);
1180 Expect.equals(21, dt1.hour);
1181 Expect.equals(9, dt1.minute);
1182 Expect.equals(9, dt1.second);
1183 Expect.equals(9, dt1.millisecond);
1184 Expect.equals(true, dt1.isUtc);
1185 dt1 = DateTime.parse("0009-09-09 09:09:09.009-0230");
1186 Expect.equals(9, dt1.year);
1187 Expect.equals(9, dt1.month);
1188 Expect.equals(9, dt1.day);
1189 Expect.equals(11, dt1.hour);
1190 Expect.equals(39, dt1.minute);
1191 Expect.equals(9, dt1.second);
1192 Expect.equals(9, dt1.millisecond);
1193 Expect.equals(true, dt1.isUtc);
1194 dt1 = DateTime.parse("0009-09-09 09:09:09.009-2134");
1195 Expect.equals(9, dt1.year);
1196 Expect.equals(9, dt1.month);
1197 Expect.equals(10, dt1.day);
1198 Expect.equals(6, dt1.hour);
1199 Expect.equals(43, dt1.minute);
1200 Expect.equals(9, dt1.second);
1201 Expect.equals(9, dt1.millisecond);
1202 Expect.equals(true, dt1.isUtc);
1203
1204 Expect.throws(() => DateTime.parse("bad"), (e) => e is FormatException);
1205 var bad_year =
1206 1970 + (_MAX_MILLISECONDS ~/ (1000 * 60 * 60 * 24 * 365.2425)) + 1;
1207 Expect.throws(() => DateTime.parse(bad_year.toString() + "-01-01"),
1208 (e) => e is FormatException);
1209 // The last valid time; should not throw.
1210 dt1 = DateTime.parse("275760-09-13T00:00:00.000Z");
1211 Expect.throws(() => DateTime.parse("275760-09-14T00:00:00.000Z"),
1212 (e) => e is FormatException);
1213 Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.001Z"),
1214 (e) => e is FormatException);
1215 if (supportsMicroseconds) {
1216 Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.000001Z"),
1217 (e) => e is FormatException);
1218 } else {
1219 dt1 = DateTime.parse("275760-09-13T00:00:00.000001Z");
1220 }
1221
1222 // first valid time; should not throw.
1223 dt1 = DateTime.parse("-271821-04-20T00:00:00.000Z");
1224 Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999Z"),
1225 (e) => e is FormatException);
1226
1227 if (supportsMicroseconds) {
1228 Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999999Z"),
1229 (e) => e is FormatException);
1230 }
1231 }
1232
1233 void testWeekday() {
1234 // 2011-10-06 is Summertime.
1235 var d = new DateTime(2011, 10, 6, 0, 45, 37, 0);
1236 Expect.equals(DateTime.THURSDAY, d.weekday);
1237 d = new DateTime.utc(2011, 10, 6, 0, 45, 37, 0);
1238 Expect.equals(DateTime.THURSDAY, d.weekday);
1239 d = new DateTime(2011, 10, 5, 23, 45, 37, 0);
1240 Expect.equals(DateTime.WEDNESDAY, d.weekday);
1241 d = new DateTime.utc(2011, 10, 5, 23, 45, 37, 0);
1242 Expect.equals(DateTime.WEDNESDAY, d.weekday);
1243 // 1970-01-01 is Wintertime.
1244 d = new DateTime(1970, 1, 1, 0, 0, 0, 1);
1245 Expect.equals(DateTime.THURSDAY, d.weekday);
1246 d = new DateTime.utc(1970, 1, 1, 0, 0, 0, 1);
1247 Expect.equals(DateTime.THURSDAY, d.weekday);
1248 d = new DateTime.utc(1969, 12, 31, 23, 59, 59, 999);
1249 Expect.equals(DateTime.WEDNESDAY, d.weekday);
1250 d = new DateTime(1969, 12, 31, 23, 59, 59, 999);
1251 Expect.equals(DateTime.WEDNESDAY, d.weekday);
1252 d = new DateTime(2011, 10, 4, 23, 45, 37, 0);
1253 Expect.equals(DateTime.TUESDAY, d.weekday);
1254 d = new DateTime(2011, 10, 3, 23, 45, 37, 0);
1255 Expect.equals(DateTime.MONDAY, d.weekday);
1256 d = new DateTime(2011, 10, 2, 23, 45, 37, 0);
1257 Expect.equals(DateTime.SUNDAY, d.weekday);
1258 d = new DateTime(2011, 10, 1, 23, 45, 37, 0);
1259 Expect.equals(DateTime.SATURDAY, d.weekday);
1260 d = new DateTime(2011, 9, 30, 23, 45, 37, 0);
1261 Expect.equals(DateTime.FRIDAY, d.weekday);
1262 }
1263
1264 void testToStrings() {
1265 void test(date, time) {
1266 {
1267 // UTC time.
1268 String source1 = "$date ${time}Z";
1269 String source2 = "${date}T${time}Z";
1270 var utcTime1 = DateTime.parse(source1);
1271 var utcTime2 = DateTime.parse(source1);
1272 Expect.isTrue(utcTime1.isUtc);
1273 Expect.equals(utcTime1, utcTime2);
1274 Expect.equals(source1, utcTime1.toString());
1275 Expect.equals(source2, utcTime1.toIso8601String());
1276 }
1277 {
1278 // Local time
1279 String source1 = "$date $time";
1280 String source2 = "${date}T$time";
1281 var utcTime1 = DateTime.parse(source1);
1282 var utcTime2 = DateTime.parse(source1);
1283 Expect.isFalse(utcTime1.isUtc);
1284 Expect.equals(utcTime1, utcTime2);
1285 Expect.equals(source1, utcTime1.toString());
1286 Expect.equals(source2, utcTime1.toIso8601String());
1287 }
1288 }
1289
1290 test("2000-01-01", "12:00:00.000");
1291 test("-2000-01-01", "12:00:00.000");
1292 test("1970-01-01", "00:00:00.000");
1293 test("1969-12-31", "23:59:59.999");
1294 test("1969-09-09", "00:09:09.009");
1295
1296 if (supportsMicroseconds) {
1297 test("2000-01-01", "12:00:00.000001");
1298 test("-2000-01-01", "12:00:00.000001");
1299 test("1970-01-01", "00:00:00.000001");
1300 test("1969-12-31", "23:59:59.999999");
1301 test("1969-09-09", "00:09:09.009999");
1302 }
1303 }
1304
1305 void testIsoString() {
1306 var d = new DateTime(9999, 1, 1, 23, 59, 59, 999);
1307 Expect.equals("9999-01-01T23:59:59.999", d.toIso8601String());
1308 d = new DateTime(-9999, 1, 1, 23, 59, 59, 999);
1309 Expect.equals("-9999-01-01T23:59:59.999", d.toIso8601String());
1310 d = new DateTime.utc(9999, 1, 1, 23, 59, 59, 999);
1311 Expect.equals("9999-01-01T23:59:59.999Z", d.toIso8601String());
1312 d = new DateTime.utc(-9999, 1, 1, 23, 59, 59, 999);
1313 Expect.equals("-9999-01-01T23:59:59.999Z", d.toIso8601String());
1314
1315 d = new DateTime(10000, 1, 1, 23, 59, 59, 999);
1316 Expect.equals("+010000-01-01T23:59:59.999", d.toIso8601String());
1317 d = new DateTime(-10000, 1, 1, 23, 59, 59, 999);
1318 Expect.equals("-010000-01-01T23:59:59.999", d.toIso8601String());
1319 d = new DateTime.utc(10000, 1, 1, 23, 59, 59, 999);
1320 Expect.equals("+010000-01-01T23:59:59.999Z", d.toIso8601String());
1321 d = new DateTime.utc(-10000, 1, 1, 23, 59, 59, 999);
1322 Expect.equals("-010000-01-01T23:59:59.999Z", d.toIso8601String());
1323
1324 if (!supportsMicroseconds) return;
1325
1326 d = new DateTime(9999, 1, 1, 23, 59, 59, 999, 999);
1327 Expect.equals("9999-01-01T23:59:59.999999", d.toIso8601String());
1328 d = new DateTime(-9999, 1, 1, 23, 59, 59, 999, 999);
1329 Expect.equals("-9999-01-01T23:59:59.999999", d.toIso8601String());
1330 d = new DateTime.utc(9999, 1, 1, 23, 59, 59, 999, 999);
1331 Expect.equals("9999-01-01T23:59:59.999999Z", d.toIso8601String());
1332 d = new DateTime.utc(-9999, 1, 1, 23, 59, 59, 999, 999);
1333 Expect.equals("-9999-01-01T23:59:59.999999Z", d.toIso8601String());
1334
1335 d = new DateTime(10000, 1, 1, 23, 59, 59, 999, 999);
1336 Expect.equals("+010000-01-01T23:59:59.999999", d.toIso8601String());
1337 d = new DateTime(-10000, 1, 1, 23, 59, 59, 999, 999);
1338 Expect.equals("-010000-01-01T23:59:59.999999", d.toIso8601String());
1339 d = new DateTime.utc(10000, 1, 1, 23, 59, 59, 999, 999);
1340 Expect.equals("+010000-01-01T23:59:59.999999Z", d.toIso8601String());
1341 d = new DateTime.utc(-10000, 1, 1, 23, 59, 59, 999, 999);
1342 Expect.equals("-010000-01-01T23:59:59.999999Z", d.toIso8601String());
1343
1344 d = new DateTime(9999, 1, 1, 23, 49, 59, 989, 979);
1345 Expect.equals("9999-01-01T23:49:59.989979", d.toIso8601String());
1346 d = new DateTime(-9999, 1, 1, 23, 49, 59, 989, 979);
1347 Expect.equals("-9999-01-01T23:49:59.989979", d.toIso8601String());
1348 d = new DateTime.utc(9999, 1, 1, 23, 49, 59, 989, 979);
1349 Expect.equals("9999-01-01T23:49:59.989979Z", d.toIso8601String());
1350 d = new DateTime.utc(-9999, 1, 1, 23, 49, 59, 989, 979);
1351 Expect.equals("-9999-01-01T23:49:59.989979Z", d.toIso8601String());
1352
1353 d = new DateTime(10000, 1, 1, 23, 49, 59, 989, 979);
1354 Expect.equals("+010000-01-01T23:49:59.989979", d.toIso8601String());
1355 d = new DateTime(-10000, 1, 1, 23, 49, 59, 989, 979);
1356 Expect.equals("-010000-01-01T23:49:59.989979", d.toIso8601String());
1357 d = new DateTime.utc(10000, 1, 1, 23, 49, 59, 989, 979);
1358 Expect.equals("+010000-01-01T23:49:59.989979Z", d.toIso8601String());
1359 d = new DateTime.utc(-10000, 1, 1, 23, 49, 59, 989, 979);
1360 Expect.equals("-010000-01-01T23:49:59.989979Z", d.toIso8601String());
1361 }
1362
1363 void main() {
1364 testNow();
1365 testMillisecondsSinceEpoch();
1366 testMicrosecondsSinceEpoch();
1367 testConstructors();
1368 testUTCGetters();
1369 testLocalGetters();
1370 testChangeTimeZone();
1371 testSubAdd();
1372 testUnderflowAndOverflow();
1373 testDateStrings();
1374 testEquivalentYears();
1375 testExtremes();
1376 testFarAwayDates();
1377 testWeekday();
1378 testToStrings();
1379 testIsoString();
1380 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/date_time_parse_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698