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

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

Issue 10536116: Reapply "Refactor Date implementation in VM." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « tests/co19/co19-runtime.status ('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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Dart test program for Date. 5 // Dart test program for Date.
6 6
7 class DateTest { 7 class DateTest {
8 // Tests if the time moves eventually forward. 8 // Tests if the time moves eventually forward.
9 static void testNow() { 9 static void testNow() {
10 var t1 = new Date.now(); 10 var t1 = new Date.now();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 Expect.equals(dt.value, dt2.value); 199 Expect.equals(dt.value, dt2.value);
200 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1); 200 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1);
201 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) || 201 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
202 (2034 == dt.year && 12 == dt.month && 31 == dt.day)); 202 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
203 Expect.equals(59, dt.seconds); 203 Expect.equals(59, dt.seconds);
204 Expect.equals(999, dt.milliseconds); 204 Expect.equals(999, dt.milliseconds);
205 dt2 = new Date( 205 dt2 = new Date(
206 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds, 206 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds,
207 dt.milliseconds); 207 dt.milliseconds);
208 Expect.equals(dt.value, dt2.value); 208 Expect.equals(dt.value, dt2.value);
209 dt = new Date.fromEpoch(2100000000 * 1000, isUtc: true);
210 Expect.equals(2036, dt.year);
211 Expect.equals(7, dt.month);
212 Expect.equals(18, dt.day);
213 Expect.equals(13, dt.hours);
214 Expect.equals(20, dt.minutes);
215 Expect.equals(0, dt.seconds);
216 Expect.equals(0, dt.milliseconds);
217 // Internally this will use the maximum value for the native calls.
218 dt = new Date(2036, 7, 18, 13, 20);
219 Expect.equals(2036, dt.year);
220 Expect.equals(7, dt.month);
221 Expect.equals(18, dt.day);
222 Expect.equals(13, dt.hours);
223 Expect.equals(20, dt.minutes);
224 Expect.equals(0, dt.seconds);
225 Expect.equals(0, dt.milliseconds);
226 Expect.equals("2036-07-18 13:20:00.000", dt.toString());
227 }
228
229 static void testExtremes() {
230 var dt = new Date.fromEpoch(8640000000000000, isUtc: true);
231 Expect.equals(275760, dt.year);
232 Expect.equals(9, dt.month);
233 Expect.equals(13, dt.day);
234 Expect.equals(0, dt.hours);
235 Expect.equals(0, dt.minutes);
236 Expect.equals(0, dt.seconds);
237 Expect.equals(0, dt.milliseconds);
238 dt = new Date.fromEpoch(-8640000000000000, isUtc: true);
239 Expect.equals(-271821, dt.year);
240 Expect.equals(4, dt.month);
241 Expect.equals(20, dt.day);
242 Expect.equals(0, dt.hours);
243 Expect.equals(0, dt.minutes);
244 Expect.equals(0, dt.seconds);
245 Expect.equals(0, dt.milliseconds);
246 // Make sure that we can build the extreme dates in local too.
247 dt = new Date.fromEpoch(8640000000000000);
248 dt = new Date(dt.year, dt.month, dt.day, dt.hours, dt.minutes);
249 Expect.equals(8640000000000000, dt.value);
250 dt = new Date.fromEpoch(-8640000000000000);
251 dt = new Date(dt.year, dt.month, dt.day, dt.hours, dt.minutes);
252 Expect.equals(-8640000000000000, dt.value);
253 Expect.throws(() => new Date.fromEpoch(8640000000000001, isUtc: true));
254 Expect.throws(() => new Date.fromEpoch(-8640000000000001, isUtc: true));
255 Expect.throws(() => new Date.fromEpoch(8640000000000001));
256 Expect.throws(() => new Date.fromEpoch(-8640000000000001));
257 dt = new Date.fromEpoch(8640000000000000);
258 Expect.throws(() => new Date(dt.year, dt.month, dt.day,
259 dt.hours, dt.minutes, 0, 1));
260 dt = new Date.fromEpoch(-8640000000000000);
261 // TODO(floitsch): Update comment after refactoring.
262 // This test currently fails because the arguments must not be negative.
263 // However we are going to allow negative (and overflowing) arguments and
264 // this line will then throw for the correct reason.
265 Expect.throws(() => new Date(dt.year, dt.month, dt.day,
266 dt.hours, dt.minutes, 0, -1));
209 } 267 }
210 268
211 static void testUTCGetters() { 269 static void testUTCGetters() {
212 var dt = new Date.fromEpoch(1305140315000, isUtc: true); 270 var dt = new Date.fromEpoch(1305140315000, isUtc: true);
213 Expect.equals(2011, dt.year); 271 Expect.equals(2011, dt.year);
214 Expect.equals(5, dt.month); 272 Expect.equals(5, dt.month);
215 Expect.equals(11, dt.day); 273 Expect.equals(11, dt.day);
216 Expect.equals(18, dt.hours); 274 Expect.equals(18, dt.hours);
217 Expect.equals(58, dt.minutes); 275 Expect.equals(58, dt.minutes);
218 Expect.equals(35, dt.seconds); 276 Expect.equals(35, dt.seconds);
(...skipping 26 matching lines...) Expand all
245 // There are timezones with 0.5 or 0.25 hour offsets. 303 // There are timezones with 0.5 or 0.25 hour offsets.
246 Expect.equals(true, 304 Expect.equals(true,
247 (dt1.minutes == dt2.minutes) || 305 (dt1.minutes == dt2.minutes) ||
248 ((dt1.minutes - dt2.minutes).abs() == 30) || 306 ((dt1.minutes - dt2.minutes).abs() == 30) ||
249 ((dt1.minutes - dt2.minutes).abs() == 15)); 307 ((dt1.minutes - dt2.minutes).abs() == 15));
250 Expect.equals(dt1.seconds, dt2.seconds); 308 Expect.equals(dt1.seconds, dt2.seconds);
251 Expect.equals(dt1.milliseconds, dt2.milliseconds); 309 Expect.equals(dt1.milliseconds, dt2.milliseconds);
252 } 310 }
253 311
254 static void testConstructors() { 312 static void testConstructors() {
313 var dt0 = new Date(2011, 5, 11, 18, 58, 35, 0, isUtc: true);
314 Expect.equals(1305140315000, dt0.value);
255 var dt1 = new Date.fromEpoch(1305140315000); 315 var dt1 = new Date.fromEpoch(1305140315000);
316 Expect.equals(dt1.value, dt0.value);
317 Expect.equals(true, dt1 == dt0);
256 var dt3 = new Date(dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 318 var dt3 = new Date(dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
257 dt1.seconds, dt1.milliseconds); 319 dt1.seconds, dt1.milliseconds);
258 Expect.equals(dt1.value, dt3.value); 320 Expect.equals(dt1.value, dt3.value);
259 Expect.equals(true, dt1 == dt3); 321 Expect.equals(true, dt1 == dt3);
260 dt3 = new Date( 322 dt3 = new Date(
261 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 323 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
262 dt1.seconds, dt1.milliseconds); 324 dt1.seconds, dt1.milliseconds);
263 Expect.equals(dt1.value, dt3.value); 325 Expect.equals(dt1.value, dt3.value);
264 Expect.equals(true, dt1 == dt3); 326 Expect.equals(true, dt1 == dt3);
265 dt3 = new Date(2011, 5, 11, 18, 58, 35, 0, isUtc: true);
266 Expect.equals(dt1.value, dt3.value);
267 Expect.equals(true, dt1 == dt3);
268 var dt2 = dt1.toLocal(); 327 var dt2 = dt1.toLocal();
269 dt3 = new Date(2011, 5, dt1.day, dt1.hours, dt1.minutes, 35, 0); 328 dt3 = new Date(2011, 5, dt1.day, dt1.hours, dt1.minutes, 35, 0);
270 Expect.equals(dt2.value, dt3.value); 329 Expect.equals(dt2.value, dt3.value);
271 Expect.equals(true, dt2 == dt3); 330 Expect.equals(true, dt2 == dt3);
272 dt1 = new Date.fromEpoch(-9999999, isUtc: true); 331 dt1 = new Date.fromEpoch(-9999999, isUtc: true);
273 dt3 = new Date( 332 dt3 = new Date(
274 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 333 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
275 dt1.seconds, dt1.milliseconds, isUtc: true); 334 dt1.seconds, dt1.milliseconds, isUtc: true);
276 Expect.equals(dt1.value, dt3.value); 335 Expect.equals(dt1.value, dt3.value);
277 dt3 = new Date(99, 1, 2, 10, 11, 12, 0, isUtc: true); 336 dt3 = new Date(99, 1, 2, 10, 11, 12, 0, isUtc: true);
278 Expect.equals(99, dt3.year); 337 Expect.equals(99, dt3.year);
279 Expect.equals(1, dt3.month); 338 Expect.equals(1, dt3.month);
280 Expect.equals(2, dt3.day); 339 Expect.equals(2, dt3.day);
281 Expect.equals(10, dt3.hours); 340 Expect.equals(10, dt3.hours);
282 Expect.equals(11, dt3.minutes); 341 Expect.equals(11, dt3.minutes);
283 Expect.equals(12, dt3.seconds); 342 Expect.equals(12, dt3.seconds);
284 Expect.equals(0, dt3.milliseconds); 343 Expect.equals(0, dt3.milliseconds);
285 Expect.equals(true, dt3.isUtc()); 344 Expect.equals(true, dt3.isUtc());
345 var dt4 = new Date(99, 1, 2);
346 Expect.equals(99, dt4.year);
347 Expect.equals(1, dt4.month);
348 Expect.equals(2, dt4.day);
349 Expect.equals(0, dt4.hours);
350 Expect.equals(0, dt4.minutes);
351 Expect.equals(0, dt4.seconds);
352 Expect.equals(0, dt4.milliseconds);
353 Expect.isFalse(dt4.isUtc());
354 var dt5 = new Date(99, 1, 2, isUtc: true);
355 Expect.equals(99, dt5.year);
356 Expect.equals(1, dt5.month);
357 Expect.equals(2, dt5.day);
358 Expect.equals(0, dt5.hours);
359 Expect.equals(0, dt5.minutes);
360 Expect.equals(0, dt5.seconds);
361 Expect.equals(0, dt5.milliseconds);
362 Expect.isTrue(dt5.isUtc());
363 var dt6 = new Date(2012, 2, 27, 13, 27, 0);
364 Expect.equals(2012, dt6.year);
365 Expect.equals(2, dt6.month);
366 Expect.equals(27, dt6.day);
367 Expect.equals(13, dt6.hours);
368 Expect.equals(27, dt6.minutes);
369 Expect.equals(0, dt6.seconds);
370 Expect.equals(0, dt6.milliseconds);
371 Expect.isFalse(dt6.isUtc());
372 var dt7 = new Date(2012, 2, 27, 13, 27, 0, isUtc: true);
373 Expect.equals(2012, dt7.year);
374 Expect.equals(2, dt7.month);
375 Expect.equals(27, dt7.day);
376 Expect.equals(13, dt7.hours);
377 Expect.equals(27, dt7.minutes);
378 Expect.equals(0, dt7.seconds);
379 Expect.equals(0, dt7.milliseconds);
380 Expect.isTrue(dt7.isUtc());
286 } 381 }
287 382
288 static void testChangeTimeZone() { 383 static void testChangeTimeZone() {
289 var dt1 = new Date.fromEpoch(1305140315000); 384 var dt1 = new Date.fromEpoch(1305140315000);
290 var dt2 = dt1.toUtc(); 385 var dt2 = dt1.toUtc();
291 Expect.equals(dt1.value, dt2.value); 386 Expect.equals(dt1.value, dt2.value);
292 var dt3 = new Date.fromEpoch(1305140315000, isUtc: true); 387 var dt3 = new Date.fromEpoch(1305140315000, isUtc: true);
293 Expect.equals(dt1.value, dt3.value); 388 Expect.equals(dt1.value, dt3.value);
294 Expect.equals(dt2.year, dt3.year); 389 Expect.equals(dt2.year, dt3.year);
295 Expect.equals(dt2.month, dt3.month); 390 Expect.equals(dt2.month, dt3.month);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 Expect.equals(Date.SUN, d.weekday); 617 Expect.equals(Date.SUN, d.weekday);
523 d = new Date(2011, 10, 1, 23, 45, 37, 0); 618 d = new Date(2011, 10, 1, 23, 45, 37, 0);
524 Expect.equals(Date.SAT, d.weekday); 619 Expect.equals(Date.SAT, d.weekday);
525 d = new Date(2011, 9, 30, 23, 45, 37, 0); 620 d = new Date(2011, 9, 30, 23, 45, 37, 0);
526 Expect.equals(Date.FRI, d.weekday); 621 Expect.equals(Date.FRI, d.weekday);
527 } 622 }
528 623
529 static void testMain() { 624 static void testMain() {
530 testNow(); 625 testNow();
531 testValue(); 626 testValue();
627 testConstructors();
532 testUTCGetters(); 628 testUTCGetters();
533 testLocalGetters(); 629 testLocalGetters();
534 testConstructors();
535 testChangeTimeZone(); 630 testChangeTimeZone();
536 testSubAdd(); 631 testSubAdd();
537 testDateStrings(); 632 testDateStrings();
538 testEquivalentYears(); 633 testEquivalentYears();
634 testExtremes();
539 testFarAwayDates(); 635 testFarAwayDates();
540 testWeekday(); 636 testWeekday();
541 } 637 }
542 } 638 }
543 639
544 main() { 640 main() {
545 DateTest.testMain(); 641 DateTest.testMain();
546 } 642 }
OLDNEW
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698