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

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

Issue 10534111: Revert "Refactor Date implementation in VM." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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));
267 } 209 }
268 210
269 static void testUTCGetters() { 211 static void testUTCGetters() {
270 var dt = new Date.fromEpoch(1305140315000, isUtc: true); 212 var dt = new Date.fromEpoch(1305140315000, isUtc: true);
271 Expect.equals(2011, dt.year); 213 Expect.equals(2011, dt.year);
272 Expect.equals(5, dt.month); 214 Expect.equals(5, dt.month);
273 Expect.equals(11, dt.day); 215 Expect.equals(11, dt.day);
274 Expect.equals(18, dt.hours); 216 Expect.equals(18, dt.hours);
275 Expect.equals(58, dt.minutes); 217 Expect.equals(58, dt.minutes);
276 Expect.equals(35, dt.seconds); 218 Expect.equals(35, dt.seconds);
(...skipping 26 matching lines...) Expand all
303 // There are timezones with 0.5 or 0.25 hour offsets. 245 // There are timezones with 0.5 or 0.25 hour offsets.
304 Expect.equals(true, 246 Expect.equals(true,
305 (dt1.minutes == dt2.minutes) || 247 (dt1.minutes == dt2.minutes) ||
306 ((dt1.minutes - dt2.minutes).abs() == 30) || 248 ((dt1.minutes - dt2.minutes).abs() == 30) ||
307 ((dt1.minutes - dt2.minutes).abs() == 15)); 249 ((dt1.minutes - dt2.minutes).abs() == 15));
308 Expect.equals(dt1.seconds, dt2.seconds); 250 Expect.equals(dt1.seconds, dt2.seconds);
309 Expect.equals(dt1.milliseconds, dt2.milliseconds); 251 Expect.equals(dt1.milliseconds, dt2.milliseconds);
310 } 252 }
311 253
312 static void testConstructors() { 254 static void testConstructors() {
313 var dt0 = new Date(2011, 5, 11, 18, 58, 35, 0, isUtc: true);
314 Expect.equals(1305140315000, dt0.value);
315 var dt1 = new Date.fromEpoch(1305140315000); 255 var dt1 = new Date.fromEpoch(1305140315000);
316 Expect.equals(dt1.value, dt0.value);
317 Expect.equals(true, dt1 == dt0);
318 var dt3 = new Date(dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 256 var dt3 = new Date(dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
319 dt1.seconds, dt1.milliseconds); 257 dt1.seconds, dt1.milliseconds);
320 Expect.equals(dt1.value, dt3.value); 258 Expect.equals(dt1.value, dt3.value);
321 Expect.equals(true, dt1 == dt3); 259 Expect.equals(true, dt1 == dt3);
322 dt3 = new Date( 260 dt3 = new Date(
323 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 261 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
324 dt1.seconds, dt1.milliseconds); 262 dt1.seconds, dt1.milliseconds);
325 Expect.equals(dt1.value, dt3.value); 263 Expect.equals(dt1.value, dt3.value);
326 Expect.equals(true, dt1 == dt3); 264 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);
327 var dt2 = dt1.toLocal(); 268 var dt2 = dt1.toLocal();
328 dt3 = new Date(2011, 5, dt1.day, dt1.hours, dt1.minutes, 35, 0); 269 dt3 = new Date(2011, 5, dt1.day, dt1.hours, dt1.minutes, 35, 0);
329 Expect.equals(dt2.value, dt3.value); 270 Expect.equals(dt2.value, dt3.value);
330 Expect.equals(true, dt2 == dt3); 271 Expect.equals(true, dt2 == dt3);
331 dt1 = new Date.fromEpoch(-9999999, isUtc: true); 272 dt1 = new Date.fromEpoch(-9999999, isUtc: true);
332 dt3 = new Date( 273 dt3 = new Date(
333 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes, 274 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
334 dt1.seconds, dt1.milliseconds, isUtc: true); 275 dt1.seconds, dt1.milliseconds, isUtc: true);
335 Expect.equals(dt1.value, dt3.value); 276 Expect.equals(dt1.value, dt3.value);
336 dt3 = new Date(99, 1, 2, 10, 11, 12, 0, isUtc: true); 277 dt3 = new Date(99, 1, 2, 10, 11, 12, 0, isUtc: true);
337 Expect.equals(99, dt3.year); 278 Expect.equals(99, dt3.year);
338 Expect.equals(1, dt3.month); 279 Expect.equals(1, dt3.month);
339 Expect.equals(2, dt3.day); 280 Expect.equals(2, dt3.day);
340 Expect.equals(10, dt3.hours); 281 Expect.equals(10, dt3.hours);
341 Expect.equals(11, dt3.minutes); 282 Expect.equals(11, dt3.minutes);
342 Expect.equals(12, dt3.seconds); 283 Expect.equals(12, dt3.seconds);
343 Expect.equals(0, dt3.milliseconds); 284 Expect.equals(0, dt3.milliseconds);
344 Expect.equals(true, dt3.isUtc()); 285 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());
381 } 286 }
382 287
383 static void testChangeTimeZone() { 288 static void testChangeTimeZone() {
384 var dt1 = new Date.fromEpoch(1305140315000); 289 var dt1 = new Date.fromEpoch(1305140315000);
385 var dt2 = dt1.toUtc(); 290 var dt2 = dt1.toUtc();
386 Expect.equals(dt1.value, dt2.value); 291 Expect.equals(dt1.value, dt2.value);
387 var dt3 = new Date.fromEpoch(1305140315000, isUtc: true); 292 var dt3 = new Date.fromEpoch(1305140315000, isUtc: true);
388 Expect.equals(dt1.value, dt3.value); 293 Expect.equals(dt1.value, dt3.value);
389 Expect.equals(dt2.year, dt3.year); 294 Expect.equals(dt2.year, dt3.year);
390 Expect.equals(dt2.month, dt3.month); 295 Expect.equals(dt2.month, dt3.month);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 Expect.equals(Date.SUN, d.weekday); 522 Expect.equals(Date.SUN, d.weekday);
618 d = new Date(2011, 10, 1, 23, 45, 37, 0); 523 d = new Date(2011, 10, 1, 23, 45, 37, 0);
619 Expect.equals(Date.SAT, d.weekday); 524 Expect.equals(Date.SAT, d.weekday);
620 d = new Date(2011, 9, 30, 23, 45, 37, 0); 525 d = new Date(2011, 9, 30, 23, 45, 37, 0);
621 Expect.equals(Date.FRI, d.weekday); 526 Expect.equals(Date.FRI, d.weekday);
622 } 527 }
623 528
624 static void testMain() { 529 static void testMain() {
625 testNow(); 530 testNow();
626 testValue(); 531 testValue();
627 testConstructors();
628 testUTCGetters(); 532 testUTCGetters();
629 testLocalGetters(); 533 testLocalGetters();
534 testConstructors();
630 testChangeTimeZone(); 535 testChangeTimeZone();
631 testSubAdd(); 536 testSubAdd();
632 testDateStrings(); 537 testDateStrings();
633 testEquivalentYears(); 538 testEquivalentYears();
634 testExtremes();
635 testFarAwayDates(); 539 testFarAwayDates();
636 testWeekday(); 540 testWeekday();
637 } 541 }
638 } 542 }
639 543
640 main() { 544 main() {
641 DateTest.testMain(); 545 DateTest.testMain();
642 } 546 }
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