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

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

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

Powered by Google App Engine
This is Rietveld 408576698