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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
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 // 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;
11 11
12 // Identical to _MAX_MILLISECONDS_SINCE_EPOCH in date_time.dart 12 // Identical to _MAX_MILLISECONDS_SINCE_EPOCH in date_time.dart
13 const int _MAX_MILLISECONDS = 8640000000000000; 13 const int _MAX_MILLISECONDS = 8640000000000000;
14 14
15 // Tests if the time moves eventually forward. 15 // Tests if the time moves eventually forward.
16 void testNow() { 16 void testNow() {
17 var t1 = new DateTime.now(); 17 var t1 = new DateTime.now();
18 bool timeMovedForward = false; 18 bool timeMovedForward = false;
19 const int N = 1000000; 19 const int N = 1000000;
20 outer: while (true) { 20 outer:
21 while (true) {
21 for (int i = N; i > 0; i--) { 22 for (int i = N; i > 0; i--) {
22 var t2 = new DateTime.now(); 23 var t2 = new DateTime.now();
23 if (t1.millisecondsSinceEpoch < t2.millisecondsSinceEpoch) { 24 if (t1.millisecondsSinceEpoch < t2.millisecondsSinceEpoch) {
24 break outer; 25 break outer;
25 } 26 }
26 } 27 }
27 print("testNow: No Date.now() progress in $N loops. Time: $t1"); 28 print("testNow: No Date.now() progress in $N loops. Time: $t1");
28 } 29 }
29 Expect.isFalse(t1.isUtc); 30 Expect.isFalse(t1.isUtc);
30 } 31 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 dt = 97 dt =
97 new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001, isUtc: true); 98 new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001, isUtc: true);
98 Expect.equals(33658, dt.year); 99 Expect.equals(33658, dt.year);
99 Expect.equals(9, dt.month); 100 Expect.equals(9, dt.month);
100 Expect.equals(27, dt.day); 101 Expect.equals(27, dt.day);
101 Expect.equals(1, dt.hour); 102 Expect.equals(1, dt.hour);
102 Expect.equals(46, dt.minute); 103 Expect.equals(46, dt.minute);
103 Expect.equals(40, dt.second); 104 Expect.equals(40, dt.second);
104 Expect.equals(0, dt.millisecond); 105 Expect.equals(0, dt.millisecond);
105 Expect.equals(1, dt.microsecond); 106 Expect.equals(1, dt.microsecond);
106 dt = new DateTime.fromMicrosecondsSinceEpoch( 107 dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001,
107 -1000000000000000001, isUtc: true); 108 isUtc: true);
108 Expect.equals(-29719, dt.year); 109 Expect.equals(-29719, dt.year);
109 Expect.equals(4, dt.month); 110 Expect.equals(4, dt.month);
110 Expect.equals(5, dt.day); 111 Expect.equals(5, dt.day);
111 Expect.equals(22, dt.hour); 112 Expect.equals(22, dt.hour);
112 Expect.equals(13, dt.minute); 113 Expect.equals(13, dt.minute);
113 Expect.equals(19, dt.second); 114 Expect.equals(19, dt.second);
114 Expect.equals(999, dt.millisecond); 115 Expect.equals(999, dt.millisecond);
115 Expect.equals(999, dt.microsecond); 116 Expect.equals(999, dt.microsecond);
116 // Same with local zone. 117 // Same with local zone.
117 dt = new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001); 118 dt = new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001);
(...skipping 17 matching lines...) Expand all
135 Expect.equals(true, dt.minute % 15 == 13); 136 Expect.equals(true, dt.minute % 15 == 13);
136 Expect.equals(19, dt.second); 137 Expect.equals(19, dt.second);
137 Expect.equals(999, dt.millisecond); 138 Expect.equals(999, dt.millisecond);
138 Expect.equals(999, dt.microsecond); 139 Expect.equals(999, dt.microsecond);
139 } 140 }
140 141
141 void testEquivalentYears() { 142 void testEquivalentYears() {
142 // All hardcoded values come from V8. This means that the values are not 143 // All hardcoded values come from V8. This means that the values are not
143 // necessarily correct (see limitations of DateTime object in 144 // necessarily correct (see limitations of DateTime object in
144 // EcmaScript 15.9.1 and in particular 15.9.1.8/9). 145 // EcmaScript 15.9.1 and in particular 15.9.1.8/9).
145 DateTime dt = new DateTime.fromMillisecondsSinceEpoch(-31485600000, isUtc: tru e); 146 DateTime dt =
147 new DateTime.fromMillisecondsSinceEpoch(-31485600000, isUtc: true);
146 Expect.equals(1969, dt.year); 148 Expect.equals(1969, dt.year);
147 Expect.equals(1, dt.month); 149 Expect.equals(1, dt.month);
148 Expect.equals(1, dt.day); 150 Expect.equals(1, dt.day);
149 Expect.equals(14, dt.hour); 151 Expect.equals(14, dt.hour);
150 Expect.equals(0, dt.minute); 152 Expect.equals(0, dt.minute);
151 Expect.equals(0, dt.second); 153 Expect.equals(0, dt.second);
152 Expect.equals(0, dt.millisecond); 154 Expect.equals(0, dt.millisecond);
153 Expect.equals(0, dt.microsecond); 155 Expect.equals(0, dt.microsecond);
154 dt = new DateTime.fromMillisecondsSinceEpoch(-63108000000, isUtc: true); 156 dt = new DateTime.fromMillisecondsSinceEpoch(-63108000000, isUtc: true);
155 Expect.equals(1968, dt.year); 157 Expect.equals(1968, dt.year);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 Expect.equals(-59, dt.year); 247 Expect.equals(-59, dt.year);
246 Expect.equals(7, dt.month); 248 Expect.equals(7, dt.month);
247 Expect.equals(24, dt.day); 249 Expect.equals(24, dt.day);
248 Expect.equals(5, dt.hour); 250 Expect.equals(5, dt.hour);
249 Expect.equals(6, dt.minute); 251 Expect.equals(6, dt.minute);
250 Expect.equals(40, dt.second); 252 Expect.equals(40, dt.second);
251 Expect.equals(0, dt.millisecond); 253 Expect.equals(0, dt.millisecond);
252 Expect.equals(0, dt.microsecond); 254 Expect.equals(0, dt.microsecond);
253 final int SECONDS_YEAR_2035 = 2051222400; 255 final int SECONDS_YEAR_2035 = 2051222400;
254 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 + 1, 256 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 + 1,
255 isUtc: true); 257 isUtc: true);
256 Expect.equals(2035, dt.year); 258 Expect.equals(2035, dt.year);
257 Expect.equals(1, dt.month); 259 Expect.equals(1, dt.month);
258 Expect.equals(1, dt.day); 260 Expect.equals(1, dt.day);
259 Expect.equals(0, dt.hour); 261 Expect.equals(0, dt.hour);
260 Expect.equals(0, dt.minute); 262 Expect.equals(0, dt.minute);
261 Expect.equals(0, dt.second); 263 Expect.equals(0, dt.second);
262 Expect.equals(1, dt.millisecond); 264 Expect.equals(1, dt.millisecond);
263 Expect.equals(0, dt.microsecond); 265 Expect.equals(0, dt.microsecond);
264 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 - 1, 266 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 - 1,
265 isUtc: true); 267 isUtc: true);
266 Expect.equals(2034, dt.year); 268 Expect.equals(2034, dt.year);
267 Expect.equals(12, dt.month); 269 Expect.equals(12, dt.month);
268 Expect.equals(31, dt.day); 270 Expect.equals(31, dt.day);
269 Expect.equals(23, dt.hour); 271 Expect.equals(23, dt.hour);
270 Expect.equals(59, dt.minute); 272 Expect.equals(59, dt.minute);
271 Expect.equals(59, dt.second); 273 Expect.equals(59, dt.second);
272 Expect.equals(999, dt.millisecond); 274 Expect.equals(999, dt.millisecond);
273 Expect.equals(0, dt.microsecond); 275 Expect.equals(0, dt.microsecond);
274 276
275 dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 1); 277 dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 1);
276 Expect.equals(SECONDS_YEAR_2035 * 1000 + 1, dt.millisecondsSinceEpoch); 278 Expect.equals(SECONDS_YEAR_2035 * 1000 + 1, dt.millisecondsSinceEpoch);
277 dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999); 279 dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999);
278 Expect.equals(SECONDS_YEAR_2035 * 1000 - 1, dt.millisecondsSinceEpoch); 280 Expect.equals(SECONDS_YEAR_2035 * 1000 - 1, dt.millisecondsSinceEpoch);
279 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 + 1); 281 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 + 1);
280 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) || 282 Expect.equals(
281 (2034 == dt.year && 12 == dt.month && 31 == dt.day)); 283 true,
284 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
285 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
282 Expect.equals(0, dt.second); 286 Expect.equals(0, dt.second);
283 Expect.equals(1, dt.millisecond); 287 Expect.equals(1, dt.millisecond);
284 DateTime dt2 = new DateTime( 288 DateTime dt2 = new DateTime(
285 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, 289 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.millisecond);
286 dt.millisecond);
287 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch); 290 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
288 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 - 1); 291 dt = new DateTime.fromMillisecondsSinceEpoch(SECONDS_YEAR_2035 * 1000 - 1);
289 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) || 292 Expect.equals(
290 (2034 == dt.year && 12 == dt.month && 31 == dt.day)); 293 true,
294 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
295 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
291 Expect.equals(59, dt.second); 296 Expect.equals(59, dt.second);
292 Expect.equals(999, dt.millisecond); 297 Expect.equals(999, dt.millisecond);
293 Expect.equals(0, dt.microsecond); 298 Expect.equals(0, dt.microsecond);
294 299
295 dt2 = new DateTime( 300 dt2 = new DateTime(
296 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, 301 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.millisecond);
297 dt.millisecond);
298 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch); 302 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
299 dt = new DateTime.fromMillisecondsSinceEpoch(2100000000 * 1000, isUtc: true); 303 dt = new DateTime.fromMillisecondsSinceEpoch(2100000000 * 1000, isUtc: true);
300 Expect.equals(2036, dt.year); 304 Expect.equals(2036, dt.year);
301 Expect.equals(7, dt.month); 305 Expect.equals(7, dt.month);
302 Expect.equals(18, dt.day); 306 Expect.equals(18, dt.day);
303 Expect.equals(13, dt.hour); 307 Expect.equals(13, dt.hour);
304 Expect.equals(20, dt.minute); 308 Expect.equals(20, dt.minute);
305 Expect.equals(0, dt.second); 309 Expect.equals(0, dt.second);
306 Expect.equals(0, dt.millisecond); 310 Expect.equals(0, dt.millisecond);
307 Expect.equals(0, dt.microsecond); 311 Expect.equals(0, dt.microsecond);
(...skipping 10 matching lines...) Expand all
318 Expect.equals(0, dt.microsecond); 322 Expect.equals(0, dt.microsecond);
319 Expect.equals("2036-07-18 13:20:00.000", dt.toString()); 323 Expect.equals("2036-07-18 13:20:00.000", dt.toString());
320 324
321 if (!supportsMicroseconds) return; 325 if (!supportsMicroseconds) return;
322 326
323 dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 0, 1); 327 dt = new DateTime.utc(2035, 1, 1, 0, 0, 0, 0, 1);
324 Expect.equals(SECONDS_YEAR_2035 * 1000000 + 1, dt.microsecondsSinceEpoch); 328 Expect.equals(SECONDS_YEAR_2035 * 1000000 + 1, dt.microsecondsSinceEpoch);
325 dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999, 999); 329 dt = new DateTime.utc(2034, 12, 31, 23, 59, 59, 999, 999);
326 Expect.equals(SECONDS_YEAR_2035 * 1000000 - 1, dt.microsecondsSinceEpoch); 330 Expect.equals(SECONDS_YEAR_2035 * 1000000 - 1, dt.microsecondsSinceEpoch);
327 dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 + 1); 331 dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 + 1);
328 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) || 332 Expect.equals(
329 (2034 == dt.year && 12 == dt.month && 31 == dt.day)); 333 true,
334 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
335 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
330 Expect.equals(0, dt.second); 336 Expect.equals(0, dt.second);
331 Expect.equals(0, dt.millisecond); 337 Expect.equals(0, dt.millisecond);
332 Expect.equals(1, dt.microsecond); 338 Expect.equals(1, dt.microsecond);
333 dt2 = new DateTime( 339 dt2 = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
334 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
335 dt.millisecond, dt.microsecond); 340 dt.millisecond, dt.microsecond);
336 Expect.equals(dt.microsecondsSinceEpoch, dt2.microsecondsSinceEpoch); 341 Expect.equals(dt.microsecondsSinceEpoch, dt2.microsecondsSinceEpoch);
337 dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 - 1); 342 dt = new DateTime.fromMicrosecondsSinceEpoch(SECONDS_YEAR_2035 * 1000000 - 1);
338 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) || 343 Expect.equals(
339 (2034 == dt.year && 12 == dt.month && 31 == dt.day)); 344 true,
345 (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
346 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
340 Expect.equals(59, dt.second); 347 Expect.equals(59, dt.second);
341 Expect.equals(999, dt.millisecond); 348 Expect.equals(999, dt.millisecond);
342 Expect.equals(999, dt.microsecond); 349 Expect.equals(999, dt.microsecond);
343 350
344 dt2 = new DateTime( 351 dt2 = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
345 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
346 dt.millisecond, dt.microsecond); 352 dt.millisecond, dt.microsecond);
347 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch); 353 Expect.equals(dt.millisecondsSinceEpoch, dt2.millisecondsSinceEpoch);
348 dt = new DateTime.fromMicrosecondsSinceEpoch(2100000000 * 1000000, 354 dt = new DateTime.fromMicrosecondsSinceEpoch(2100000000 * 1000000,
349 isUtc: true); 355 isUtc: true);
350 Expect.equals(2036, dt.year); 356 Expect.equals(2036, dt.year);
351 Expect.equals(7, dt.month); 357 Expect.equals(7, dt.month);
352 Expect.equals(18, dt.day); 358 Expect.equals(18, dt.day);
353 Expect.equals(13, dt.hour); 359 Expect.equals(13, dt.hour);
354 Expect.equals(20, dt.minute); 360 Expect.equals(20, dt.minute);
355 Expect.equals(0, dt.second); 361 Expect.equals(0, dt.second);
(...skipping 22 matching lines...) Expand all
378 Expect.equals(0, dt.millisecond); 384 Expect.equals(0, dt.millisecond);
379 Expect.equals(0, dt.microsecond); 385 Expect.equals(0, dt.microsecond);
380 // Make sure that we can build the extreme dates in local too. 386 // Make sure that we can build the extreme dates in local too.
381 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS); 387 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
382 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute); 388 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
383 Expect.equals(_MAX_MILLISECONDS, dt.millisecondsSinceEpoch); 389 Expect.equals(_MAX_MILLISECONDS, dt.millisecondsSinceEpoch);
384 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS); 390 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
385 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute); 391 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
386 Expect.equals(-_MAX_MILLISECONDS, dt.millisecondsSinceEpoch); 392 Expect.equals(-_MAX_MILLISECONDS, dt.millisecondsSinceEpoch);
387 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch( 393 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch(
388 _MAX_MILLISECONDS + 1, isUtc: true)); 394 _MAX_MILLISECONDS + 1,
395 isUtc: true));
389 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch( 396 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch(
390 -_MAX_MILLISECONDS - 1, isUtc: true)); 397 -_MAX_MILLISECONDS - 1,
391 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch( 398 isUtc: true));
392 _MAX_MILLISECONDS + 1)); 399 Expect.throws(
393 Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch( 400 () => new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS + 1));
394 -_MAX_MILLISECONDS - 1)); 401 Expect.throws(
402 () => new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS - 1));
395 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS); 403 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
396 Expect.throws(() => new DateTime(dt.year, dt.month, dt.day, 404 Expect.throws(
397 dt.hour, dt.minute, 0, 1)); 405 () => new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 1));
398 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true); 406 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
399 Expect.throws(() => new DateTime.utc(dt.year, dt.month, dt.day, 407 Expect.throws(() =>
400 dt.hour, dt.minute, 0, 1)); 408 new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 1));
401 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS); 409 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
402 Expect.throws(() => new DateTime(dt.year, dt.month, dt.day, 410 Expect.throws(
403 dt.hour, dt.minute, 0, -1)); 411 () => new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, -1));
404 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true); 412 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
405 Expect.throws(() => new DateTime.utc(dt.year, dt.month, dt.day, 413 Expect.throws(() =>
406 dt.hour, dt.minute, 0, -1)); 414 new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, -1));
407 415
408 if (!supportsMicroseconds) return; 416 if (!supportsMicroseconds) return;
409 417
410 dt = new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000); 418 dt = new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000);
411 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute); 419 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
412 Expect.equals(_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch); 420 Expect.equals(_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
413 dt = new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000); 421 dt = new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000);
414 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute); 422 dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
415 Expect.equals(-_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch); 423 Expect.equals(-_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
416 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch( 424 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
417 _MAX_MILLISECONDS * 1000 + 1, isUtc: true)); 425 _MAX_MILLISECONDS * 1000 + 1,
426 isUtc: true));
418 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch( 427 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
419 -_MAX_MILLISECONDS * 1000 - 1, isUtc: true)); 428 -_MAX_MILLISECONDS * 1000 - 1,
420 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch( 429 isUtc: true));
421 _MAX_MILLISECONDS * 1000 + 1)); 430 Expect.throws(() =>
422 Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch( 431 new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000 + 1));
423 -_MAX_MILLISECONDS * 1000 - 1)); 432 Expect.throws(() =>
433 new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000 - 1));
424 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS); 434 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
425 Expect.throws(() => new DateTime(dt.year, dt.month, dt.day, 435 Expect.throws(() =>
426 dt.hour, dt.minute, 0, 0, 1)); 436 new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, 1));
427 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true); 437 dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
428 Expect.throws(() => new DateTime.utc(dt.year, dt.month, dt.day, 438 Expect.throws(() =>
429 dt.hour, dt.minute, 0, 0, 1)); 439 new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, 1));
430 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS); 440 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
431 Expect.throws(() => new DateTime(dt.year, dt.month, dt.day, 441 Expect.throws(() =>
432 dt.hour, dt.minute, 0, 0, -1)); 442 new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, -1));
433 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true); 443 dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
434 Expect.throws(() => new DateTime.utc(dt.year, dt.month, dt.day, 444 Expect.throws(() => new DateTime.utc(
435 dt.hour, dt.minute, 0, 0, -1)); 445 dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, -1));
436 } 446 }
437 447
438 void testUTCGetters() { 448 void testUTCGetters() {
439 var dt = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true); 449 var dt = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
440 Expect.equals(2011, dt.year); 450 Expect.equals(2011, dt.year);
441 Expect.equals(5, dt.month); 451 Expect.equals(5, dt.month);
442 Expect.equals(11, dt.day); 452 Expect.equals(11, dt.day);
443 Expect.equals(18, dt.hour); 453 Expect.equals(18, dt.hour);
444 Expect.equals(58, dt.minute); 454 Expect.equals(58, dt.minute);
445 Expect.equals(35, dt.second); 455 Expect.equals(35, dt.second);
(...skipping 19 matching lines...) Expand all
465 Expect.equals(31, dt.day); 475 Expect.equals(31, dt.day);
466 Expect.equals(21, dt.hour); 476 Expect.equals(21, dt.hour);
467 Expect.equals(13, dt.minute); 477 Expect.equals(13, dt.minute);
468 Expect.equals(20, dt.second); 478 Expect.equals(20, dt.second);
469 Expect.equals(0, dt.millisecond); 479 Expect.equals(0, dt.millisecond);
470 Expect.equals(1, dt.microsecond); 480 Expect.equals(1, dt.microsecond);
471 } 481 }
472 482
473 void testLocalGetters() { 483 void testLocalGetters() {
474 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000); 484 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000);
475 var dt2 = new DateTime.utc(dt1.year, dt1.month, dt1.day, 485 var dt2 = new DateTime.utc(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
476 dt1.hour, dt1.minute, dt1.second, dt1.millisecond, 486 dt1.second, dt1.millisecond, dt1.microsecond);
477 dt1.microsecond);
478 Duration zoneOffset = dt1.difference(dt2); 487 Duration zoneOffset = dt1.difference(dt2);
479 Expect.equals(true, zoneOffset.inDays == 0); 488 Expect.equals(true, zoneOffset.inDays == 0);
480 Expect.equals(true, zoneOffset.inHours.abs() <= 12); 489 Expect.equals(true, zoneOffset.inHours.abs() <= 12);
481 Expect.equals(dt1.year, dt2.year); 490 Expect.equals(dt1.year, dt2.year);
482 Expect.equals(dt1.month, dt2.month); 491 Expect.equals(dt1.month, dt2.month);
483 Expect.equals(true, (dt1.day - dt2.day).abs() <= 1); 492 Expect.equals(true, (dt1.day - dt2.day).abs() <= 1);
484 Expect.equals(true, dt1.hour < 24); 493 Expect.equals(true, dt1.hour < 24);
485 // There are timezones with 0.5 or 0.25 hour offsets. 494 // There are timezones with 0.5 or 0.25 hour offsets.
486 Expect.equals(true, 495 Expect.equals(
487 (dt1.minute == dt2.minute) || 496 true,
488 ((dt1.minute - dt2.minute).abs() == 30) || 497 (dt1.minute == dt2.minute) ||
489 ((dt1.minute - dt2.minute).abs() == 15)); 498 ((dt1.minute - dt2.minute).abs() == 30) ||
499 ((dt1.minute - dt2.minute).abs() == 15));
490 Expect.equals(dt1.second, dt2.second); 500 Expect.equals(dt1.second, dt2.second);
491 Expect.equals(dt1.millisecond, dt2.millisecond); 501 Expect.equals(dt1.millisecond, dt2.millisecond);
492 Expect.equals(dt1.microsecond, dt2.microsecond); 502 Expect.equals(dt1.microsecond, dt2.microsecond);
493 } 503 }
494 504
495 void testConstructors() { 505 void testConstructors() {
496 var dt0 = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0); 506 var dt0 = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0);
497 var dt0b = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0).toLocal(); 507 var dt0b = new DateTime.utc(2011, 5, 11, 18, 58, 35, 0, 0).toLocal();
498 Expect.equals(1305140315000, dt0.millisecondsSinceEpoch); 508 Expect.equals(1305140315000, dt0.millisecondsSinceEpoch);
499 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000); 509 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000);
500 Expect.equals(dt1.millisecondsSinceEpoch, dt0.millisecondsSinceEpoch); 510 Expect.equals(dt1.millisecondsSinceEpoch, dt0.millisecondsSinceEpoch);
501 Expect.equals(dt1.microsecondsSinceEpoch, dt0.microsecondsSinceEpoch); 511 Expect.equals(dt1.microsecondsSinceEpoch, dt0.microsecondsSinceEpoch);
502 Expect.equals(false, dt1 == dt0); 512 Expect.equals(false, dt1 == dt0);
503 Expect.equals(true, dt1 == dt0b); 513 Expect.equals(true, dt1 == dt0b);
504 var dt3 = new DateTime(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute, 514 var dt3 = new DateTime(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
505 dt1.second, dt1.millisecond, dt1.microsecond); 515 dt1.second, dt1.millisecond, dt1.microsecond);
506 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch); 516 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
507 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch); 517 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
508 Expect.equals(false, dt3 == dt0); 518 Expect.equals(false, dt3 == dt0);
509 Expect.equals(true, dt1 == dt3); 519 Expect.equals(true, dt1 == dt3);
510 dt3 = new DateTime( 520 dt3 = new DateTime(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
511 dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
512 dt1.second, dt1.millisecond, dt1.microsecond); 521 dt1.second, dt1.millisecond, dt1.microsecond);
513 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch); 522 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
514 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch); 523 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
515 Expect.equals(true, dt1 == dt3); 524 Expect.equals(true, dt1 == dt3);
516 var dt2 = dt1.toLocal(); 525 var dt2 = dt1.toLocal();
517 dt3 = new DateTime(2011, 5, dt1.day, dt1.hour, dt1.minute, 35, 0, 0); 526 dt3 = new DateTime(2011, 5, dt1.day, dt1.hour, dt1.minute, 35, 0, 0);
518 Expect.equals(dt2.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch); 527 Expect.equals(dt2.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
519 Expect.equals(dt2.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch); 528 Expect.equals(dt2.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
520 Expect.equals(true, dt2 == dt3); 529 Expect.equals(true, dt2 == dt3);
521 dt1 = new DateTime.fromMillisecondsSinceEpoch(-9999999, isUtc: true); 530 dt1 = new DateTime.fromMillisecondsSinceEpoch(-9999999, isUtc: true);
522 dt3 = new DateTime.utc(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute, 531 dt3 = new DateTime.utc(dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute,
523 dt1.second, dt1.millisecond); 532 dt1.second, dt1.millisecond);
524 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch); 533 Expect.equals(dt1.millisecondsSinceEpoch, dt3.millisecondsSinceEpoch);
525 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch); 534 Expect.equals(dt1.microsecondsSinceEpoch, dt3.microsecondsSinceEpoch);
526 dt3 = new DateTime.utc(99, 1, 2, 10, 11, 12, 0); 535 dt3 = new DateTime.utc(99, 1, 2, 10, 11, 12, 0);
527 Expect.equals(99, dt3.year); 536 Expect.equals(99, dt3.year);
528 Expect.equals(1, dt3.month); 537 Expect.equals(1, dt3.month);
529 Expect.equals(2, dt3.day); 538 Expect.equals(2, dt3.day);
530 Expect.equals(10, dt3.hour); 539 Expect.equals(10, dt3.hour);
531 Expect.equals(11, dt3.minute); 540 Expect.equals(11, dt3.minute);
532 Expect.equals(12, dt3.second); 541 Expect.equals(12, dt3.second);
533 Expect.equals(0, dt3.millisecond); 542 Expect.equals(0, dt3.millisecond);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 Expect.equals(dt1.day, dt4.day); 604 Expect.equals(dt1.day, dt4.day);
596 Expect.equals(dt1.hour, dt4.hour); 605 Expect.equals(dt1.hour, dt4.hour);
597 Expect.equals(dt1.minute, dt4.minute); 606 Expect.equals(dt1.minute, dt4.minute);
598 Expect.equals(dt1.second, dt4.second); 607 Expect.equals(dt1.second, dt4.second);
599 Expect.equals(dt1.millisecond, dt4.millisecond); 608 Expect.equals(dt1.millisecond, dt4.millisecond);
600 Expect.equals(dt1.microsecond, dt4.microsecond); 609 Expect.equals(dt1.microsecond, dt4.microsecond);
601 } 610 }
602 611
603 void testSubAdd() { 612 void testSubAdd() {
604 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true); 613 var dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
605 var dt2 = dt1.add(new Duration(milliseconds: 614 var dt2 = dt1.add(
606 3 * Duration.MILLISECONDS_PER_SECOND + 5)); 615 new Duration(milliseconds: 3 * Duration.MILLISECONDS_PER_SECOND + 5));
607 Expect.equals(dt1.year, dt2.year); 616 Expect.equals(dt1.year, dt2.year);
608 Expect.equals(dt1.month, dt2.month); 617 Expect.equals(dt1.month, dt2.month);
609 Expect.equals(dt1.day, dt2.day); 618 Expect.equals(dt1.day, dt2.day);
610 Expect.equals(dt1.hour, dt2.hour); 619 Expect.equals(dt1.hour, dt2.hour);
611 Expect.equals(dt1.minute, dt2.minute); 620 Expect.equals(dt1.minute, dt2.minute);
612 Expect.equals(dt1.second + 3, dt2.second); 621 Expect.equals(dt1.second + 3, dt2.second);
613 Expect.equals(dt1.millisecond + 5, dt2.millisecond); 622 Expect.equals(dt1.millisecond + 5, dt2.millisecond);
614 Expect.equals(dt1.microsecond, dt2.microsecond); 623 Expect.equals(dt1.microsecond, dt2.microsecond);
615 var dt3 = dt2.subtract(new Duration(milliseconds: 624 var dt3 = dt2.subtract(
616 3 * Duration.MILLISECONDS_PER_SECOND + 5)); 625 new Duration(milliseconds: 3 * Duration.MILLISECONDS_PER_SECOND + 5));
617 Expect.equals(true, dt1 == dt3); 626 Expect.equals(true, dt1 == dt3);
618 Expect.equals(false, dt1 == dt2); 627 Expect.equals(false, dt1 == dt2);
619 628
620 if (!supportsMicroseconds) return; 629 if (!supportsMicroseconds) return;
621 630
622 dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true); 631 dt1 = new DateTime.fromMillisecondsSinceEpoch(1305140315000, isUtc: true);
623 dt2 = dt1.add(new Duration(microseconds: 632 dt2 = dt1.add(
624 3 * Duration.MICROSECONDS_PER_SECOND + 5)); 633 new Duration(microseconds: 3 * Duration.MICROSECONDS_PER_SECOND + 5));
625 Expect.equals(dt1.year, dt2.year); 634 Expect.equals(dt1.year, dt2.year);
626 Expect.equals(dt1.month, dt2.month); 635 Expect.equals(dt1.month, dt2.month);
627 Expect.equals(dt1.day, dt2.day); 636 Expect.equals(dt1.day, dt2.day);
628 Expect.equals(dt1.hour, dt2.hour); 637 Expect.equals(dt1.hour, dt2.hour);
629 Expect.equals(dt1.minute, dt2.minute); 638 Expect.equals(dt1.minute, dt2.minute);
630 Expect.equals(dt1.second + 3, dt2.second); 639 Expect.equals(dt1.second + 3, dt2.second);
631 Expect.equals(dt1.millisecond, dt2.millisecond); 640 Expect.equals(dt1.millisecond, dt2.millisecond);
632 Expect.equals(dt1.microsecond + 5, dt2.microsecond); 641 Expect.equals(dt1.microsecond + 5, dt2.microsecond);
633 dt3 = dt2.subtract(new Duration(microseconds: 642 dt3 = dt2.subtract(
634 3 * Duration.MICROSECONDS_PER_SECOND + 5)); 643 new Duration(microseconds: 3 * Duration.MICROSECONDS_PER_SECOND + 5));
635 Expect.equals(true, dt1 == dt3); 644 Expect.equals(true, dt1 == dt3);
636 Expect.equals(false, dt1 == dt2); 645 Expect.equals(false, dt1 == dt2);
637 } 646 }
638 647
639 void testUnderflowAndOverflow() { 648 void testUnderflowAndOverflow() {
640 int microsecond = supportsMicroseconds ? 499 : 0; 649 int microsecond = supportsMicroseconds ? 499 : 0;
641 final dtBase = new DateTime(2012, 6, 20, 12, 30, 30, 500, microsecond); 650 final dtBase = new DateTime(2012, 6, 20, 12, 30, 30, 500, microsecond);
642 651
643 // Millisecond 652 // Millisecond
644 print(" >>> Millisecond+"); 653 print(" >>> Millisecond+");
645 var dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 654 var dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
646 dtBase.minute, dtBase.second, 1000, dtBase.microsecond); 655 dtBase.minute, dtBase.second, 1000, dtBase.microsecond);
647 Expect.equals(dtBase.year, dt.year); 656 Expect.equals(dtBase.year, dt.year);
648 Expect.equals(dtBase.month, dt.month); 657 Expect.equals(dtBase.month, dt.month);
649 Expect.equals(dtBase.day, dt.day); 658 Expect.equals(dtBase.day, dt.day);
650 Expect.equals(dtBase.hour, dt.hour); 659 Expect.equals(dtBase.hour, dt.hour);
651 Expect.equals(dtBase.minute, dt.minute); 660 Expect.equals(dtBase.minute, dt.minute);
652 Expect.equals(dtBase.second + 1, dt.second); 661 Expect.equals(dtBase.second + 1, dt.second);
653 Expect.equals(0, dt.millisecond); 662 Expect.equals(0, dt.millisecond);
654 Expect.equals(dtBase.microsecond, dt.microsecond); 663 Expect.equals(dtBase.microsecond, dt.microsecond);
655 664
656 print(" >>> Millisecond-"); 665 print(" >>> Millisecond-");
657 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 666 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
658 dtBase.minute, dtBase.second, -1000, dtBase.microsecond); 667 dtBase.minute, dtBase.second, -1000, dtBase.microsecond);
659 Expect.equals(dtBase.year, dt.year); 668 Expect.equals(dtBase.year, dt.year);
660 Expect.equals(dtBase.month, dt.month); 669 Expect.equals(dtBase.month, dt.month);
661 Expect.equals(dtBase.day, dt.day); 670 Expect.equals(dtBase.day, dt.day);
662 Expect.equals(dtBase.hour, dt.hour); 671 Expect.equals(dtBase.hour, dt.hour);
663 Expect.equals(dtBase.minute, dt.minute); 672 Expect.equals(dtBase.minute, dt.minute);
664 Expect.equals(dtBase.second - 1, dt.second); 673 Expect.equals(dtBase.second - 1, dt.second);
665 Expect.equals(0, dt.millisecond); 674 Expect.equals(0, dt.millisecond);
666 Expect.equals(dtBase.microsecond, dt.microsecond); 675 Expect.equals(dtBase.microsecond, dt.microsecond);
667 676
668 // Second 677 // Second
669 print(" >>> Second+"); 678 print(" >>> Second+");
670 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 679 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
671 dtBase.minute, 60, dtBase.millisecond, dtBase.microsecond); 680 dtBase.minute, 60, dtBase.millisecond, dtBase.microsecond);
672 Expect.equals(dtBase.year, dt.year); 681 Expect.equals(dtBase.year, dt.year);
673 Expect.equals(dtBase.month, dt.month); 682 Expect.equals(dtBase.month, dt.month);
674 Expect.equals(dtBase.day, dt.day); 683 Expect.equals(dtBase.day, dt.day);
675 Expect.equals(dtBase.hour, dt.hour); 684 Expect.equals(dtBase.hour, dt.hour);
676 Expect.equals(dtBase.minute + 1, dt.minute); 685 Expect.equals(dtBase.minute + 1, dt.minute);
677 Expect.equals(0, dt.second); 686 Expect.equals(0, dt.second);
678 Expect.equals(dtBase.millisecond, dt.millisecond); 687 Expect.equals(dtBase.millisecond, dt.millisecond);
679 Expect.equals(dtBase.microsecond, dt.microsecond); 688 Expect.equals(dtBase.microsecond, dt.microsecond);
680 689
681 print(" >>> Second-"); 690 print(" >>> Second-");
682 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 691 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
683 dtBase.minute, -60, dtBase.millisecond, dtBase.microsecond); 692 dtBase.minute, -60, dtBase.millisecond, dtBase.microsecond);
684 Expect.equals(dtBase.year, dt.year); 693 Expect.equals(dtBase.year, dt.year);
685 Expect.equals(dtBase.month, dt.month); 694 Expect.equals(dtBase.month, dt.month);
686 Expect.equals(dtBase.day, dt.day); 695 Expect.equals(dtBase.day, dt.day);
687 Expect.equals(dtBase.hour, dt.hour); 696 Expect.equals(dtBase.hour, dt.hour);
688 Expect.equals(dtBase.minute - 1, dt.minute); 697 Expect.equals(dtBase.minute - 1, dt.minute);
689 Expect.equals(0, dt.second); 698 Expect.equals(0, dt.second);
690 Expect.equals(dtBase.millisecond, dt.millisecond); 699 Expect.equals(dtBase.millisecond, dt.millisecond);
691 Expect.equals(dtBase.microsecond, dt.microsecond); 700 Expect.equals(dtBase.microsecond, dt.microsecond);
692 701
693 // Minute 702 // Minute
694 print(" >>> Minute+"); 703 print(" >>> Minute+");
695 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 60, 704 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 60,
696 dtBase.second, dtBase.millisecond, dtBase.microsecond); 705 dtBase.second, dtBase.millisecond, dtBase.microsecond);
697 Expect.equals(dtBase.year, dt.year); 706 Expect.equals(dtBase.year, dt.year);
698 Expect.equals(dtBase.month, dt.month); 707 Expect.equals(dtBase.month, dt.month);
699 Expect.equals(dtBase.day, dt.day); 708 Expect.equals(dtBase.day, dt.day);
700 Expect.equals(dtBase.hour + 1, dt.hour); 709 Expect.equals(dtBase.hour + 1, dt.hour);
701 Expect.equals(0, dt.minute); 710 Expect.equals(0, dt.minute);
702 Expect.equals(dtBase.second, dt.second); 711 Expect.equals(dtBase.second, dt.second);
703 Expect.equals(dtBase.millisecond, dt.millisecond); 712 Expect.equals(dtBase.millisecond, dt.millisecond);
704 Expect.equals(dtBase.microsecond, dt.microsecond); 713 Expect.equals(dtBase.microsecond, dt.microsecond);
705 714
706 print(" >>> Minute-"); 715 print(" >>> Minute-");
707 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, -60, 716 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, -60,
708 dtBase.second, dtBase.millisecond, dtBase.microsecond); 717 dtBase.second, dtBase.millisecond, dtBase.microsecond);
709 Expect.equals(dtBase.year, dt.year); 718 Expect.equals(dtBase.year, dt.year);
710 Expect.equals(dtBase.month, dt.month); 719 Expect.equals(dtBase.month, dt.month);
711 Expect.equals(dtBase.day, dt.day); 720 Expect.equals(dtBase.day, dt.day);
712 Expect.equals(dtBase.hour - 1, dt.hour); 721 Expect.equals(dtBase.hour - 1, dt.hour);
713 Expect.equals(0, dt.minute); 722 Expect.equals(0, dt.minute);
714 Expect.equals(dtBase.second, dt.second); 723 Expect.equals(dtBase.second, dt.second);
715 Expect.equals(dtBase.millisecond, dt.millisecond); 724 Expect.equals(dtBase.millisecond, dt.millisecond);
716 Expect.equals(dtBase.microsecond, dt.microsecond); 725 Expect.equals(dtBase.microsecond, dt.microsecond);
717 726
718 // Hour 727 // Hour
719 print(" >>> Hour+"); 728 print(" >>> Hour+");
720 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, 24, dtBase.minute, 729 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, 24, dtBase.minute,
721 dtBase.second, dtBase.millisecond, dtBase.microsecond); 730 dtBase.second, dtBase.millisecond, dtBase.microsecond);
722 Expect.equals(dtBase.year, dt.year); 731 Expect.equals(dtBase.year, dt.year);
723 Expect.equals(dtBase.month, dt.month); 732 Expect.equals(dtBase.month, dt.month);
724 Expect.equals(dtBase.day + 1, dt.day); 733 Expect.equals(dtBase.day + 1, dt.day);
725 Expect.equals(0, dt.hour); 734 Expect.equals(0, dt.hour);
726 Expect.equals(dtBase.minute, dt.minute); 735 Expect.equals(dtBase.minute, dt.minute);
727 Expect.equals(dtBase.second, dt.second); 736 Expect.equals(dtBase.second, dt.second);
728 Expect.equals(dtBase.millisecond, dt.millisecond); 737 Expect.equals(dtBase.millisecond, dt.millisecond);
729 Expect.equals(dtBase.microsecond, dt.microsecond); 738 Expect.equals(dtBase.microsecond, dt.microsecond);
730 739
731 print(" >>> Hour-"); 740 print(" >>> Hour-");
732 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, -24, dtBase.minute, 741 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, -24, dtBase.minute,
733 dtBase.second, dtBase.millisecond, dtBase.microsecond); 742 dtBase.second, dtBase.millisecond, dtBase.microsecond);
734 Expect.equals(dtBase.year, dt.year); 743 Expect.equals(dtBase.year, dt.year);
735 Expect.equals(dtBase.month, dt.month); 744 Expect.equals(dtBase.month, dt.month);
736 Expect.equals(dtBase.day - 1, dt.day); 745 Expect.equals(dtBase.day - 1, dt.day);
737 Expect.equals(0, dt.hour); 746 Expect.equals(0, dt.hour);
738 Expect.equals(dtBase.minute, dt.minute); 747 Expect.equals(dtBase.minute, dt.minute);
739 Expect.equals(dtBase.second, dt.second); 748 Expect.equals(dtBase.second, dt.second);
740 Expect.equals(dtBase.millisecond, dt.millisecond); 749 Expect.equals(dtBase.millisecond, dt.millisecond);
741 Expect.equals(dtBase.microsecond, dt.microsecond); 750 Expect.equals(dtBase.microsecond, dt.microsecond);
742 751
743 // Day 752 // Day
744 print(" >>> Day+"); 753 print(" >>> Day+");
745 dt = new DateTime(dtBase.year, dtBase.month, 31, dtBase.hour, dtBase.minute, 754 dt = new DateTime(dtBase.year, dtBase.month, 31, dtBase.hour, dtBase.minute,
746 dtBase.second, dtBase.millisecond, dtBase.microsecond); 755 dtBase.second, dtBase.millisecond, dtBase.microsecond);
747 Expect.equals(dtBase.year, dt.year); 756 Expect.equals(dtBase.year, dt.year);
748 Expect.equals(dtBase.month + 1, dt.month); 757 Expect.equals(dtBase.month + 1, dt.month);
749 Expect.equals(1, dt.day); 758 Expect.equals(1, dt.day);
750 Expect.equals(dtBase.hour, dt.hour); 759 Expect.equals(dtBase.hour, dt.hour);
751 Expect.equals(dtBase.minute, dt.minute); 760 Expect.equals(dtBase.minute, dt.minute);
752 Expect.equals(dtBase.second, dt.second); 761 Expect.equals(dtBase.second, dt.second);
753 Expect.equals(dtBase.millisecond, dt.millisecond); 762 Expect.equals(dtBase.millisecond, dt.millisecond);
754 Expect.equals(dtBase.microsecond, dt.microsecond); 763 Expect.equals(dtBase.microsecond, dt.microsecond);
755 764
756 print(" >>> Day-"); 765 print(" >>> Day-");
757 dt = new DateTime(dtBase.year, dtBase.month, -30, dtBase.hour, dtBase.minute, 766 dt = new DateTime(dtBase.year, dtBase.month, -30, dtBase.hour, dtBase.minute,
758 dtBase.second, dtBase.millisecond, dtBase.microsecond); 767 dtBase.second, dtBase.millisecond, dtBase.microsecond);
759 Expect.equals(dtBase.year, dt.year); 768 Expect.equals(dtBase.year, dt.year);
760 Expect.equals(dtBase.month - 1, dt.month); 769 Expect.equals(dtBase.month - 1, dt.month);
761 Expect.equals(1, dt.day); 770 Expect.equals(1, dt.day);
762 Expect.equals(dtBase.hour, dt.hour); 771 Expect.equals(dtBase.hour, dt.hour);
763 Expect.equals(dtBase.minute, dt.minute); 772 Expect.equals(dtBase.minute, dt.minute);
764 Expect.equals(dtBase.second, dt.second); 773 Expect.equals(dtBase.second, dt.second);
765 Expect.equals(dtBase.millisecond, dt.millisecond); 774 Expect.equals(dtBase.millisecond, dt.millisecond);
766 Expect.equals(dtBase.microsecond, dt.microsecond); 775 Expect.equals(dtBase.microsecond, dt.microsecond);
767 776
768 // Month 777 // Month
769 print(" >>> Month+"); 778 print(" >>> Month+");
770 dt = new DateTime(dtBase.year, 13, dtBase.day, dtBase.hour, dtBase.minute, 779 dt = new DateTime(dtBase.year, 13, dtBase.day, dtBase.hour, dtBase.minute,
771 dtBase.second, dtBase.millisecond, dtBase.microsecond); 780 dtBase.second, dtBase.millisecond, dtBase.microsecond);
772 Expect.equals(dtBase.year + 1, dt.year); 781 Expect.equals(dtBase.year + 1, dt.year);
773 Expect.equals(1, dt.month); 782 Expect.equals(1, dt.month);
774 Expect.equals(dtBase.day, dt.day); 783 Expect.equals(dtBase.day, dt.day);
775 Expect.equals(dtBase.hour, dt.hour); 784 Expect.equals(dtBase.hour, dt.hour);
776 Expect.equals(dtBase.minute, dt.minute); 785 Expect.equals(dtBase.minute, dt.minute);
777 Expect.equals(dtBase.second, dt.second); 786 Expect.equals(dtBase.second, dt.second);
778 Expect.equals(dtBase.millisecond, dt.millisecond); 787 Expect.equals(dtBase.millisecond, dt.millisecond);
779 Expect.equals(dtBase.microsecond, dt.microsecond); 788 Expect.equals(dtBase.microsecond, dt.microsecond);
780 789
781 print(" >>> Month-"); 790 print(" >>> Month-");
782 dt = new DateTime(dtBase.year, -11, dtBase.day, dtBase.hour, dtBase.minute, 791 dt = new DateTime(dtBase.year, -11, dtBase.day, dtBase.hour, dtBase.minute,
783 dtBase.second, dtBase.millisecond, dtBase.microsecond); 792 dtBase.second, dtBase.millisecond, dtBase.microsecond);
784 Expect.equals(dtBase.year - 1, dt.year); 793 Expect.equals(dtBase.year - 1, dt.year);
785 Expect.equals(1, dt.month); 794 Expect.equals(1, dt.month);
786 Expect.equals(dtBase.day, dt.day); 795 Expect.equals(dtBase.day, dt.day);
787 Expect.equals(dtBase.hour, dt.hour); 796 Expect.equals(dtBase.hour, dt.hour);
788 Expect.equals(dtBase.minute, dt.minute); 797 Expect.equals(dtBase.minute, dt.minute);
789 Expect.equals(dtBase.second, dt.second); 798 Expect.equals(dtBase.second, dt.second);
790 Expect.equals(dtBase.millisecond, dt.millisecond); 799 Expect.equals(dtBase.millisecond, dt.millisecond);
791 Expect.equals(dtBase.microsecond, dt.microsecond); 800 Expect.equals(dtBase.microsecond, dt.microsecond);
792 801
793 // Flowing all the way up the chain. 802 // Flowing all the way up the chain.
794 print(" >>> Flow+"); 803 print(" >>> Flow+");
795 var dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 000); 804 var dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 000);
796 var dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, 805 var dtTick = new DateTime(
797 dtBase1.hour, dtBase1.minute, dtBase1.second, 806 dtBase1.year,
798 dtBase1.millisecond + 1, dtBase1.microsecond); 807 dtBase1.month,
808 dtBase1.day,
809 dtBase1.hour,
810 dtBase1.minute,
811 dtBase1.second,
812 dtBase1.millisecond + 1,
813 dtBase1.microsecond);
799 Expect.equals(dtBase1.year + 1, dtTick.year); 814 Expect.equals(dtBase1.year + 1, dtTick.year);
800 Expect.equals(1, dtTick.month); 815 Expect.equals(1, dtTick.month);
801 Expect.equals(1, dtTick.day); 816 Expect.equals(1, dtTick.day);
802 Expect.equals(0, dtTick.hour); 817 Expect.equals(0, dtTick.hour);
803 Expect.equals(0, dtTick.minute); 818 Expect.equals(0, dtTick.minute);
804 Expect.equals(0, dtTick.second); 819 Expect.equals(0, dtTick.second);
805 Expect.equals(0, dtTick.millisecond); 820 Expect.equals(0, dtTick.millisecond);
806 Expect.equals(0, dtTick.microsecond); 821 Expect.equals(0, dtTick.microsecond);
807 822
808 print(" >>> Flow-"); 823 print(" >>> Flow-");
809 dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0); 824 dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0);
810 dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, dtBase1.hour, 825 dtTick = new DateTime(
811 dtBase1.minute, dtBase1.second, dtBase1.millisecond - 1, 826 dtBase1.year,
812 dtBase1.microsecond); 827 dtBase1.month,
828 dtBase1.day,
829 dtBase1.hour,
830 dtBase1.minute,
831 dtBase1.second,
832 dtBase1.millisecond - 1,
833 dtBase1.microsecond);
813 Expect.equals(dtBase1.year - 1, dtTick.year); 834 Expect.equals(dtBase1.year - 1, dtTick.year);
814 Expect.equals(12, dtTick.month); 835 Expect.equals(12, dtTick.month);
815 Expect.equals(31, dtTick.day); 836 Expect.equals(31, dtTick.day);
816 Expect.equals(23, dtTick.hour); 837 Expect.equals(23, dtTick.hour);
817 Expect.equals(59, dtTick.minute); 838 Expect.equals(59, dtTick.minute);
818 Expect.equals(59, dtTick.second); 839 Expect.equals(59, dtTick.second);
819 Expect.equals(999, dtTick.millisecond); 840 Expect.equals(999, dtTick.millisecond);
820 Expect.equals(0, dtTick.microsecond); 841 Expect.equals(0, dtTick.microsecond);
821 842
822 print(" >>> extra underflow"); 843 print(" >>> extra underflow");
823 dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, -17520, 844 dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, -17520,
824 dtBase1.minute, dtBase1.second, dtBase1.millisecond, 845 dtBase1.minute, dtBase1.second, dtBase1.millisecond, dtBase1.microsecond);
825 dtBase1.microsecond);
826 Expect.equals(dtBase1.year - 2, dtTick.year); 846 Expect.equals(dtBase1.year - 2, dtTick.year);
827 Expect.equals(dtBase1.month, dtTick.month); 847 Expect.equals(dtBase1.month, dtTick.month);
828 Expect.equals(dtBase1.day, dtTick.day); 848 Expect.equals(dtBase1.day, dtTick.day);
829 Expect.equals(dtBase1.hour, dtTick.hour); 849 Expect.equals(dtBase1.hour, dtTick.hour);
830 Expect.equals(dtBase1.minute, dtTick.minute); 850 Expect.equals(dtBase1.minute, dtTick.minute);
831 Expect.equals(dtBase1.second, dtTick.second); 851 Expect.equals(dtBase1.second, dtTick.second);
832 Expect.equals(dtBase1.millisecond, dtTick.millisecond); 852 Expect.equals(dtBase1.millisecond, dtTick.millisecond);
833 Expect.equals(dtBase1.microsecond, dtTick.microsecond); 853 Expect.equals(dtBase1.microsecond, dtTick.microsecond);
834 854
835 if (!supportsMicroseconds) return; 855 if (!supportsMicroseconds) return;
836 856
837 // Microsecond 857 // Microsecond
838 print(" >>> Microsecond+"); 858 print(" >>> Microsecond+");
839 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 859 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
840 dtBase.minute, dtBase.second, dtBase.millisecond, 1000); 860 dtBase.minute, dtBase.second, dtBase.millisecond, 1000);
841 Expect.equals(dtBase.year, dt.year); 861 Expect.equals(dtBase.year, dt.year);
842 Expect.equals(dtBase.month, dt.month); 862 Expect.equals(dtBase.month, dt.month);
843 Expect.equals(dtBase.day, dt.day); 863 Expect.equals(dtBase.day, dt.day);
844 Expect.equals(dtBase.hour, dt.hour); 864 Expect.equals(dtBase.hour, dt.hour);
845 Expect.equals(dtBase.minute, dt.minute); 865 Expect.equals(dtBase.minute, dt.minute);
846 Expect.equals(dtBase.second, dt.second); 866 Expect.equals(dtBase.second, dt.second);
847 Expect.equals(dtBase.millisecond + 1, dt.millisecond); 867 Expect.equals(dtBase.millisecond + 1, dt.millisecond);
848 Expect.equals(0, dt.microsecond); 868 Expect.equals(0, dt.microsecond);
849 869
850 print(" >>> Microsecond-"); 870 print(" >>> Microsecond-");
851 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 871 dt = new DateTime(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
852 dtBase.minute, dtBase.second, dtBase.millisecond, -1000); 872 dtBase.minute, dtBase.second, dtBase.millisecond, -1000);
853 Expect.equals(dtBase.year, dt.year); 873 Expect.equals(dtBase.year, dt.year);
854 Expect.equals(dtBase.month, dt.month); 874 Expect.equals(dtBase.month, dt.month);
855 Expect.equals(dtBase.day, dt.day); 875 Expect.equals(dtBase.day, dt.day);
856 Expect.equals(dtBase.hour, dt.hour); 876 Expect.equals(dtBase.hour, dt.hour);
857 Expect.equals(dtBase.minute, dt.minute); 877 Expect.equals(dtBase.minute, dt.minute);
858 Expect.equals(dtBase.second, dt.second); 878 Expect.equals(dtBase.second, dt.second);
859 Expect.equals(dtBase.millisecond - 1, dt.millisecond); 879 Expect.equals(dtBase.millisecond - 1, dt.millisecond);
860 Expect.equals(0, dt.microsecond); 880 Expect.equals(0, dt.microsecond);
861 881
862 // Flowing all the way up the chain. 882 // Flowing all the way up the chain.
863 print(" >>> Flow+ 2"); 883 print(" >>> Flow+ 2");
864 dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 999); 884 dtBase1 = new DateTime(2012, 12, 31, 23, 59, 59, 999, 999);
865 dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, 885 dtTick = new DateTime(
866 dtBase1.hour, dtBase1.minute, dtBase1.second, 886 dtBase1.year,
867 dtBase1.millisecond, dtBase1.microsecond + 1); 887 dtBase1.month,
888 dtBase1.day,
889 dtBase1.hour,
890 dtBase1.minute,
891 dtBase1.second,
892 dtBase1.millisecond,
893 dtBase1.microsecond + 1);
868 Expect.equals(dtBase1.year + 1, dtTick.year); 894 Expect.equals(dtBase1.year + 1, dtTick.year);
869 Expect.equals(1, dtTick.month); 895 Expect.equals(1, dtTick.month);
870 Expect.equals(1, dtTick.day); 896 Expect.equals(1, dtTick.day);
871 Expect.equals(0, dtTick.hour); 897 Expect.equals(0, dtTick.hour);
872 Expect.equals(0, dtTick.minute); 898 Expect.equals(0, dtTick.minute);
873 Expect.equals(0, dtTick.second); 899 Expect.equals(0, dtTick.second);
874 Expect.equals(0, dtTick.millisecond); 900 Expect.equals(0, dtTick.millisecond);
875 Expect.equals(0, dtTick.microsecond); 901 Expect.equals(0, dtTick.microsecond);
876 902
877 print(" >>> Flow- 2"); 903 print(" >>> Flow- 2");
878 dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0, 0); 904 dtBase1 = new DateTime(2012, 1, 1, 0, 0, 0, 0, 0);
879 dtTick = new DateTime(dtBase1.year, dtBase1.month, dtBase1.day, dtBase1.hour, 905 dtTick = new DateTime(
880 dtBase1.minute, dtBase1.second, dtBase1.millisecond, 906 dtBase1.year,
881 dtBase1.microsecond - 1); 907 dtBase1.month,
908 dtBase1.day,
909 dtBase1.hour,
910 dtBase1.minute,
911 dtBase1.second,
912 dtBase1.millisecond,
913 dtBase1.microsecond - 1);
882 Expect.equals(dtBase1.year - 1, dtTick.year); 914 Expect.equals(dtBase1.year - 1, dtTick.year);
883 Expect.equals(12, dtTick.month); 915 Expect.equals(12, dtTick.month);
884 Expect.equals(31, dtTick.day); 916 Expect.equals(31, dtTick.day);
885 Expect.equals(23, dtTick.hour); 917 Expect.equals(23, dtTick.hour);
886 Expect.equals(59, dtTick.minute); 918 Expect.equals(59, dtTick.minute);
887 Expect.equals(59, dtTick.second); 919 Expect.equals(59, dtTick.second);
888 Expect.equals(999, dtTick.millisecond); 920 Expect.equals(999, dtTick.millisecond);
889 Expect.equals(999, dtTick.microsecond); 921 Expect.equals(999, dtTick.microsecond);
890 } 922 }
891 923
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 Expect.equals(9, dt1.year); 1195 Expect.equals(9, dt1.year);
1164 Expect.equals(9, dt1.month); 1196 Expect.equals(9, dt1.month);
1165 Expect.equals(10, dt1.day); 1197 Expect.equals(10, dt1.day);
1166 Expect.equals(6, dt1.hour); 1198 Expect.equals(6, dt1.hour);
1167 Expect.equals(43, dt1.minute); 1199 Expect.equals(43, dt1.minute);
1168 Expect.equals(9, dt1.second); 1200 Expect.equals(9, dt1.second);
1169 Expect.equals(9, dt1.millisecond); 1201 Expect.equals(9, dt1.millisecond);
1170 Expect.equals(true, dt1.isUtc); 1202 Expect.equals(true, dt1.isUtc);
1171 1203
1172 Expect.throws(() => DateTime.parse("bad"), (e) => e is FormatException); 1204 Expect.throws(() => DateTime.parse("bad"), (e) => e is FormatException);
1173 var bad_year = 1970 + (_MAX_MILLISECONDS ~/ (1000*60*60*24*365.2425)) + 1; 1205 var bad_year =
1206 1970 + (_MAX_MILLISECONDS ~/ (1000 * 60 * 60 * 24 * 365.2425)) + 1;
1174 Expect.throws(() => DateTime.parse(bad_year.toString() + "-01-01"), 1207 Expect.throws(() => DateTime.parse(bad_year.toString() + "-01-01"),
1175 (e) => e is FormatException); 1208 (e) => e is FormatException);
1176 // The last valid time; should not throw. 1209 // The last valid time; should not throw.
1177 dt1 = DateTime.parse("275760-09-13T00:00:00.000Z"); 1210 dt1 = DateTime.parse("275760-09-13T00:00:00.000Z");
1178 Expect.throws(() => DateTime.parse("275760-09-14T00:00:00.000Z"), 1211 Expect.throws(() => DateTime.parse("275760-09-14T00:00:00.000Z"),
1179 (e) => e is FormatException); 1212 (e) => e is FormatException);
1180 Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.001Z"), 1213 Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.001Z"),
1181 (e) => e is FormatException); 1214 (e) => e is FormatException);
1182 if (supportsMicroseconds) { 1215 if (supportsMicroseconds) {
1183 Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.000001Z"), 1216 Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.000001Z"),
1184 (e) => e is FormatException); 1217 (e) => e is FormatException);
1185 } else { 1218 } else {
1186 dt1 = DateTime.parse("275760-09-13T00:00:00.000001Z"); 1219 dt1 = DateTime.parse("275760-09-13T00:00:00.000001Z");
1187 } 1220 }
1188 1221
1189 // first valid time; should not throw. 1222 // first valid time; should not throw.
1190 dt1 = DateTime.parse("-271821-04-20T00:00:00.000Z"); 1223 dt1 = DateTime.parse("-271821-04-20T00:00:00.000Z");
1191 Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999Z"), 1224 Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999Z"),
1192 (e) => e is FormatException); 1225 (e) => e is FormatException);
1193 1226
1194 if (supportsMicroseconds) { 1227 if (supportsMicroseconds) {
1195 Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999999Z"), 1228 Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999999Z"),
1196 (e) => e is FormatException); 1229 (e) => e is FormatException);
1197 } 1230 }
1198 } 1231 }
1199 1232
1200 void testWeekday() { 1233 void testWeekday() {
1201 // 2011-10-06 is Summertime. 1234 // 2011-10-06 is Summertime.
1202 var d = new DateTime(2011, 10, 6, 0, 45, 37, 0); 1235 var d = new DateTime(2011, 10, 6, 0, 45, 37, 0);
1203 Expect.equals(DateTime.THURSDAY, d.weekday); 1236 Expect.equals(DateTime.THURSDAY, d.weekday);
1204 d = new DateTime.utc(2011, 10, 6, 0, 45, 37, 0); 1237 d = new DateTime.utc(2011, 10, 6, 0, 45, 37, 0);
1205 Expect.equals(DateTime.THURSDAY, d.weekday); 1238 Expect.equals(DateTime.THURSDAY, d.weekday);
1206 d = new DateTime(2011, 10, 5, 23, 45, 37, 0); 1239 d = new DateTime(2011, 10, 5, 23, 45, 37, 0);
(...skipping 16 matching lines...) Expand all
1223 d = new DateTime(2011, 10, 2, 23, 45, 37, 0); 1256 d = new DateTime(2011, 10, 2, 23, 45, 37, 0);
1224 Expect.equals(DateTime.SUNDAY, d.weekday); 1257 Expect.equals(DateTime.SUNDAY, d.weekday);
1225 d = new DateTime(2011, 10, 1, 23, 45, 37, 0); 1258 d = new DateTime(2011, 10, 1, 23, 45, 37, 0);
1226 Expect.equals(DateTime.SATURDAY, d.weekday); 1259 Expect.equals(DateTime.SATURDAY, d.weekday);
1227 d = new DateTime(2011, 9, 30, 23, 45, 37, 0); 1260 d = new DateTime(2011, 9, 30, 23, 45, 37, 0);
1228 Expect.equals(DateTime.FRIDAY, d.weekday); 1261 Expect.equals(DateTime.FRIDAY, d.weekday);
1229 } 1262 }
1230 1263
1231 void testToStrings() { 1264 void testToStrings() {
1232 void test(date, time) { 1265 void test(date, time) {
1233 { // UTC time. 1266 {
1267 // UTC time.
1234 String source1 = "$date ${time}Z"; 1268 String source1 = "$date ${time}Z";
1235 String source2 = "${date}T${time}Z"; 1269 String source2 = "${date}T${time}Z";
1236 var utcTime1 = DateTime.parse(source1); 1270 var utcTime1 = DateTime.parse(source1);
1237 var utcTime2 = DateTime.parse(source1); 1271 var utcTime2 = DateTime.parse(source1);
1238 Expect.isTrue(utcTime1.isUtc); 1272 Expect.isTrue(utcTime1.isUtc);
1239 Expect.equals(utcTime1, utcTime2); 1273 Expect.equals(utcTime1, utcTime2);
1240 Expect.equals(source1, utcTime1.toString()); 1274 Expect.equals(source1, utcTime1.toString());
1241 Expect.equals(source2, utcTime1.toIso8601String()); 1275 Expect.equals(source2, utcTime1.toIso8601String());
1242 } 1276 }
1243 { // Local time 1277 {
1278 // Local time
1244 String source1 = "$date $time"; 1279 String source1 = "$date $time";
1245 String source2 = "${date}T$time"; 1280 String source2 = "${date}T$time";
1246 var utcTime1 = DateTime.parse(source1); 1281 var utcTime1 = DateTime.parse(source1);
1247 var utcTime2 = DateTime.parse(source1); 1282 var utcTime2 = DateTime.parse(source1);
1248 Expect.isFalse(utcTime1.isUtc); 1283 Expect.isFalse(utcTime1.isUtc);
1249 Expect.equals(utcTime1, utcTime2); 1284 Expect.equals(utcTime1, utcTime2);
1250 Expect.equals(source1, utcTime1.toString()); 1285 Expect.equals(source1, utcTime1.toString());
1251 Expect.equals(source2, utcTime1.toIso8601String()); 1286 Expect.equals(source2, utcTime1.toIso8601String());
1252 } 1287 }
1253 } 1288 }
1289
1254 test("2000-01-01", "12:00:00.000"); 1290 test("2000-01-01", "12:00:00.000");
1255 test("-2000-01-01", "12:00:00.000"); 1291 test("-2000-01-01", "12:00:00.000");
1256 test("1970-01-01", "00:00:00.000"); 1292 test("1970-01-01", "00:00:00.000");
1257 test("1969-12-31", "23:59:59.999"); 1293 test("1969-12-31", "23:59:59.999");
1258 test("1969-09-09", "00:09:09.009"); 1294 test("1969-09-09", "00:09:09.009");
1259 1295
1260 if (supportsMicroseconds) { 1296 if (supportsMicroseconds) {
1261 test("2000-01-01", "12:00:00.000001"); 1297 test("2000-01-01", "12:00:00.000001");
1262 test("-2000-01-01", "12:00:00.000001"); 1298 test("-2000-01-01", "12:00:00.000001");
1263 test("1970-01-01", "00:00:00.000001"); 1299 test("1970-01-01", "00:00:00.000001");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 testSubAdd(); 1371 testSubAdd();
1336 testUnderflowAndOverflow(); 1372 testUnderflowAndOverflow();
1337 testDateStrings(); 1373 testDateStrings();
1338 testEquivalentYears(); 1374 testEquivalentYears();
1339 testExtremes(); 1375 testExtremes();
1340 testFarAwayDates(); 1376 testFarAwayDates();
1341 testWeekday(); 1377 testWeekday();
1342 testToStrings(); 1378 testToStrings();
1343 testIsoString(); 1379 testIsoString();
1344 } 1380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698