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

Side by Side Diff: tests/corelib/src/DateTimeTest.dart

Issue 10244009: test rename overhaul: step 7 - corelib tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Dart test program for Date.
6
7 class DateTest {
8 // Tests if the time moves eventually forward.
9 static void testNow() {
10 var t1 = new Date.now();
11 bool timeMovedForward = false;
12 for (int i = 0; i < 1000000; i++) {
13 var t2 = new Date.now();
14 if (t1.value < t2.value) {
15 timeMovedForward = true;
16 break;
17 }
18 }
19 Expect.equals(true, timeMovedForward);
20 }
21
22 static void testValue() {
23 var dt1 = new Date.now();
24 var value = dt1.value;
25 var dt2 = new Date.fromEpoch(value, new TimeZone.local());
26 Expect.equals(value, dt2.value);
27 }
28
29 static void testFarAwayDates() {
30 Date dt = new Date.fromEpoch(1000000000000001, const TimeZone.utc());
31 Expect.equals(33658, dt.year);
32 Expect.equals(9, dt.month);
33 Expect.equals(27, dt.day);
34 Expect.equals(1, dt.hours);
35 Expect.equals(46, dt.minutes);
36 Expect.equals(40, dt.seconds);
37 Expect.equals(1, dt.milliseconds);
38 dt = new Date.fromEpoch(-1000000000000001, const TimeZone.utc());
39 Expect.equals(-29719, dt.year);
40 Expect.equals(4, dt.month);
41 Expect.equals(5, dt.day);
42 Expect.equals(22, dt.hours);
43 Expect.equals(13, dt.minutes);
44 Expect.equals(19, dt.seconds);
45 Expect.equals(999, dt.milliseconds);
46 // Same with local zone.
47 dt = new Date.fromEpoch(1000000000000001, new TimeZone.local());
48 Expect.equals(33658, dt.year);
49 Expect.equals(9, dt.month);
50 Expect.equals(true, dt.day == 27 || dt.day == 26);
51 // Not much we can test for local hours.
52 Expect.equals(true, dt.hours >= 0 && dt.hours < 24);
53 // Timezones can have offsets down to 15 minutes.
54 Expect.equals(true, dt.minutes % 15 == 46 % 15);
55 Expect.equals(40, dt.seconds);
56 Expect.equals(1, dt.milliseconds);
57 dt = new Date.fromEpoch(-1000000000000001, new TimeZone.local());
58 Expect.equals(-29719, dt.year);
59 Expect.equals(4, dt.month);
60 Expect.equals(true, 5 == dt.day || 6 == dt.day);
61 // Not much we can test for local hours.
62 Expect.equals(true, dt.hours >= 0 && dt.hours < 24);
63 // Timezones can have offsets down to 15 minutes.
64 Expect.equals(true, dt.minutes % 15 == 13);
65 Expect.equals(19, dt.seconds);
66 Expect.equals(999, dt.milliseconds);
67 }
68
69 static void testEquivalentYears() {
70 // All hardcoded values come from V8. This means that the values are not
71 // necessarily correct (see limitations of Date object in
72 // EcmaScript 15.9.1 and in particular 15.9.1.8/9).
73 Date dt = new Date.fromEpoch(-31485600000, const TimeZone.utc());
74 Expect.equals(1969, dt.year);
75 Expect.equals(1, dt.month);
76 Expect.equals(1, dt.day);
77 Expect.equals(14, dt.hours);
78 Expect.equals(0, dt.minutes);
79 Expect.equals(0, dt.seconds);
80 Expect.equals(0, dt.milliseconds);
81 dt = new Date.fromEpoch(-63108000000, const TimeZone.utc());
82 Expect.equals(1968, dt.year);
83 Expect.equals(1, dt.month);
84 Expect.equals(1, dt.day);
85 Expect.equals(14, dt.hours);
86 Expect.equals(0, dt.minutes);
87 Expect.equals(0, dt.seconds);
88 Expect.equals(0, dt.milliseconds);
89 dt = new Date.fromEpoch(-94644000000, const TimeZone.utc());
90 Expect.equals(1967, dt.year);
91 Expect.equals(1, dt.month);
92 Expect.equals(1, dt.day);
93 Expect.equals(14, dt.hours);
94 Expect.equals(0, dt.minutes);
95 Expect.equals(0, dt.seconds);
96 Expect.equals(0, dt.milliseconds);
97 dt = new Date.fromEpoch(-126180000000, const TimeZone.utc());
98 Expect.equals(1966, dt.year);
99 Expect.equals(1, dt.month);
100 Expect.equals(1, dt.day);
101 Expect.equals(14, dt.hours);
102 Expect.equals(0, dt.minutes);
103 Expect.equals(0, dt.seconds);
104 Expect.equals(0, dt.milliseconds);
105 dt = new Date.fromEpoch(-157716000000, const TimeZone.utc());
106 Expect.equals(1965, dt.year);
107 Expect.equals(1, dt.month);
108 Expect.equals(1, dt.day);
109 Expect.equals(14, dt.hours);
110 Expect.equals(0, dt.minutes);
111 Expect.equals(0, dt.seconds);
112 Expect.equals(0, dt.milliseconds);
113 dt = new Date.fromEpoch(-2177402400000, const TimeZone.utc());
114 Expect.equals(1901, dt.year);
115 Expect.equals(1, dt.month);
116 Expect.equals(1, dt.day);
117 Expect.equals(14, dt.hours);
118 Expect.equals(0, dt.minutes);
119 Expect.equals(0, dt.seconds);
120 Expect.equals(0, dt.milliseconds);
121 dt = new Date.fromEpoch(-5333076000000, const TimeZone.utc());
122 Expect.equals(1801, dt.year);
123 Expect.equals(1, dt.month);
124 Expect.equals(1, dt.day);
125 Expect.equals(14, dt.hours);
126 Expect.equals(0, dt.minutes);
127 Expect.equals(0, dt.seconds);
128 Expect.equals(0, dt.milliseconds);
129 dt = new Date.fromEpoch(-8520285600000, const TimeZone.utc());
130 Expect.equals(1700, dt.year);
131 Expect.equals(1, dt.month);
132 Expect.equals(1, dt.day);
133 Expect.equals(14, dt.hours);
134 Expect.equals(0, dt.minutes);
135 Expect.equals(0, dt.seconds);
136 Expect.equals(0, dt.milliseconds);
137 dt = new Date.fromEpoch(-14831719200000, const TimeZone.utc());
138 Expect.equals(1500, dt.year);
139 Expect.equals(1, dt.month);
140 Expect.equals(1, dt.day);
141 Expect.equals(14, dt.hours);
142 Expect.equals(0, dt.minutes);
143 Expect.equals(0, dt.seconds);
144 Expect.equals(0, dt.milliseconds);
145 dt = new Date.fromEpoch(-59011408800000, const TimeZone.utc());
146 Expect.equals(100, dt.year);
147 Expect.equals(1, dt.month);
148 Expect.equals(1, dt.day);
149 Expect.equals(14, dt.hours);
150 Expect.equals(0, dt.minutes);
151 Expect.equals(0, dt.seconds);
152 Expect.equals(0, dt.milliseconds);
153 dt = new Date.fromEpoch(-62011408800000, const TimeZone.utc());
154 Expect.equals(4, dt.year);
155 Expect.equals(12, dt.month);
156 Expect.equals(8, dt.day);
157 Expect.equals(8, dt.hours);
158 Expect.equals(40, dt.minutes);
159 Expect.equals(0, dt.seconds);
160 Expect.equals(0, dt.milliseconds);
161 dt = new Date.fromEpoch(-64011408800000, const TimeZone.utc());
162 Expect.equals(-59, dt.year);
163 Expect.equals(7, dt.month);
164 Expect.equals(24, dt.day);
165 Expect.equals(5, dt.hours);
166 Expect.equals(6, dt.minutes);
167 Expect.equals(40, dt.seconds);
168 Expect.equals(0, dt.milliseconds);
169 final int SECONDS_YEAR_2035 = 2051222400;
170 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 + 1, const TimeZone.utc());
171 Expect.equals(2035, dt.year);
172 Expect.equals(1, dt.month);
173 Expect.equals(1, dt.day);
174 Expect.equals(0, dt.hours);
175 Expect.equals(0, dt.minutes);
176 Expect.equals(0, dt.seconds);
177 Expect.equals(1, dt.milliseconds);
178 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1, const TimeZone.utc());
179 Expect.equals(2034, dt.year);
180 Expect.equals(12, dt.month);
181 Expect.equals(31, dt.day);
182 Expect.equals(23, dt.hours);
183 Expect.equals(59, dt.minutes);
184 Expect.equals(59, dt.seconds);
185 Expect.equals(999, dt.milliseconds);
186 dt = new Date.withTimeZone(2035, 1, 1, 0, 0, 0, 1, const TimeZone.utc());
187 Expect.equals(SECONDS_YEAR_2035 * 1000 + 1, dt.value);
188 dt = new Date.withTimeZone(2034, 12, 31, 23, 59, 59, 999,
189 const TimeZone.utc());
190 Expect.equals(SECONDS_YEAR_2035 * 1000 - 1, dt.value);
191 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 + 1, new TimeZone.local());
192 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
193 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
194 Expect.equals(0, dt.seconds);
195 Expect.equals(1, dt.milliseconds);
196 Date dt2 = new Date.withTimeZone(
197 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds,
198 dt.milliseconds, new TimeZone.local());
199 Expect.equals(dt.value, dt2.value);
200 dt = new Date.fromEpoch(SECONDS_YEAR_2035 * 1000 - 1, new TimeZone.local());
201 Expect.equals(true, (2035 == dt.year && 1 == dt.month && 1 == dt.day) ||
202 (2034 == dt.year && 12 == dt.month && 31 == dt.day));
203 Expect.equals(59, dt.seconds);
204 Expect.equals(999, dt.milliseconds);
205 dt2 = new Date.withTimeZone(
206 dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds,
207 dt.milliseconds, new TimeZone.local());
208 Expect.equals(dt.value, dt2.value);
209 }
210
211 static void testUTCGetters() {
212 var dt = new Date.fromEpoch(1305140315000, const TimeZone.utc());
213 Expect.equals(2011, dt.year);
214 Expect.equals(5, dt.month);
215 Expect.equals(11, dt.day);
216 Expect.equals(18, dt.hours);
217 Expect.equals(58, dt.minutes);
218 Expect.equals(35, dt.seconds);
219 Expect.equals(0, dt.milliseconds);
220 Expect.equals(true, const TimeZone.utc() == dt.timeZone);
221 Expect.equals(1305140315000, dt.value);
222 dt = new Date.fromEpoch(-9999999, const TimeZone.utc());
223 Expect.equals(1969, dt.year);
224 Expect.equals(12, dt.month);
225 Expect.equals(31, dt.day);
226 Expect.equals(21, dt.hours);
227 Expect.equals(13, dt.minutes);
228 Expect.equals(20, dt.seconds);
229 Expect.equals(1, dt.milliseconds);
230 }
231
232 static void testLocalGetters() {
233 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local());
234 var dt2 = new Date.withTimeZone(dt1.year, dt1.month, dt1.day,
235 dt1.hours, dt1.minutes, dt1.seconds,
236 dt1.milliseconds,
237 const TimeZone.utc());
238 Duration zoneOffset = dt1.difference(dt2);
239 Expect.equals(true, zoneOffset.inDays == 0);
240 Expect.equals(true, zoneOffset.inHours.abs() <= 12);
241 Expect.equals(dt1.year, dt2.year);
242 Expect.equals(dt1.month, dt2.month);
243 Expect.equals(true, (dt1.day - dt2.day).abs() <= 1);
244 Expect.equals(true, dt1.hours < 24);
245 // There are timezones with 0.5 or 0.25 hour offsets.
246 Expect.equals(true,
247 (dt1.minutes == dt2.minutes) ||
248 ((dt1.minutes - dt2.minutes).abs() == 30) ||
249 ((dt1.minutes - dt2.minutes).abs() == 15));
250 Expect.equals(dt1.seconds, dt2.seconds);
251 Expect.equals(dt1.milliseconds, dt2.milliseconds);
252 }
253
254 static void testConstructors() {
255 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local());
256 var dt3 = new Date(dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
257 dt1.seconds, dt1.milliseconds);
258 Expect.equals(dt1.value, dt3.value);
259 Expect.equals(true, dt1 == dt3);
260 dt3 = new Date.withTimeZone(
261 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
262 dt1.seconds, dt1.milliseconds, new TimeZone.local());
263 Expect.equals(dt1.value, dt3.value);
264 Expect.equals(true, dt1 == dt3);
265 dt3 = new Date.withTimeZone(2011, 5, 11, 18, 58, 35, 0,
266 const TimeZone.utc());
267 Expect.equals(dt1.value, dt3.value);
268 Expect.equals(false, dt1 == dt3);
269 var dt2 = dt1.changeTimeZone(new TimeZone.local());
270 dt3 = new Date.withTimeZone(2011, 5, dt1.day,
271 dt1.hours, dt1.minutes, 35, 0,
272 new TimeZone.local());
273 Expect.equals(dt2.value, dt3.value);
274 Expect.equals(true, dt2 == dt3);
275 dt1 = new Date.fromEpoch(-9999999, const TimeZone.utc());
276 dt3 = new Date.withTimeZone(
277 dt1.year, dt1.month, dt1.day, dt1.hours, dt1.minutes,
278 dt1.seconds, dt1.milliseconds, const TimeZone.utc());
279 Expect.equals(dt1.value, dt3.value);
280 dt3 = new Date.withTimeZone(99, 1, 2, 10, 11, 12, 0,
281 const TimeZone.utc());
282 Expect.equals(99, dt3.year);
283 Expect.equals(1, dt3.month);
284 Expect.equals(2, dt3.day);
285 Expect.equals(10, dt3.hours);
286 Expect.equals(11, dt3.minutes);
287 Expect.equals(12, dt3.seconds);
288 Expect.equals(0, dt3.milliseconds);
289 Expect.equals(true, dt3.isUtc());
290 }
291
292 static void testChangeTimeZone() {
293 var dt1 = new Date.fromEpoch(1305140315000, new TimeZone.local());
294 var dt2 = dt1.changeTimeZone(const TimeZone.utc());
295 Expect.equals(dt1.value, dt2.value);
296 var dt3 = new Date.fromEpoch(1305140315000, const TimeZone.utc());
297 Expect.equals(dt1.value, dt3.value);
298 Expect.equals(dt2.year, dt3.year);
299 Expect.equals(dt2.month, dt3.month);
300 Expect.equals(dt2.day, dt3.day);
301 Expect.equals(dt2.hours, dt3.hours);
302 Expect.equals(dt2.minutes, dt3.minutes);
303 Expect.equals(dt2.seconds, dt3.seconds);
304 Expect.equals(dt2.milliseconds, dt3.milliseconds);
305 var dt4 = dt3.changeTimeZone(new TimeZone.local());
306 Expect.equals(dt1.year, dt4.year);
307 Expect.equals(dt1.month, dt4.month);
308 Expect.equals(dt1.day, dt4.day);
309 Expect.equals(dt1.hours, dt4.hours);
310 Expect.equals(dt1.minutes, dt4.minutes);
311 Expect.equals(dt1.seconds, dt4.seconds);
312 Expect.equals(dt1.milliseconds, dt4.milliseconds);
313 }
314
315 static void testSubAdd() {
316 var dt1 = new Date.fromEpoch(1305140315000, const TimeZone.utc());
317 var dt2 = dt1.add(new Duration(milliseconds:
318 3 * Duration.MILLISECONDS_PER_SECOND + 5));
319 Expect.equals(dt1.year, dt2.year);
320 Expect.equals(dt1.month, dt2.month);
321 Expect.equals(dt1.day, dt2.day);
322 Expect.equals(dt1.hours, dt2.hours);
323 Expect.equals(dt1.minutes, dt2.minutes);
324 Expect.equals(dt1.seconds + 3, dt2.seconds);
325 Expect.equals(dt1.milliseconds + 5, dt2.milliseconds);
326 var dt3 = dt2.subtract(new Duration(milliseconds:
327 3 * Duration.MILLISECONDS_PER_SECOND + 5));
328 Expect.equals(true, dt1 == dt3);
329 Expect.equals(false, dt1 == dt2);
330 }
331
332 static void testDateStrings() {
333 // TODO(floitsch): Clean up the Date API that deals with strings.
334 var dt1 = new Date.fromString("2011-05-11 18:58:35Z");
335 Expect.equals(1305140315000, dt1.value);
336 Expect.isTrue(dt1.isUtc());
337 dt1 = new Date.fromString("20110511 18:58:35z");
338 Expect.equals(1305140315000, dt1.value);
339 Expect.isTrue(dt1.isUtc());
340 dt1 = new Date.fromString("+20110511 18:58:35z");
341 Expect.equals(1305140315000, dt1.value);
342 Expect.isTrue(dt1.isUtc());
343 var str = dt1.toString();
344 var dt2 = new Date.fromString(str);
345 Expect.equals(true, dt1 == dt2);
346 var dt3 = dt1.changeTimeZone(const TimeZone.utc());
347 str = dt3.toString();
348 Expect.equals("2011-05-11 18:58:35.000Z", str);
349 var dt4 = new Date.fromString("-1234-01-01 00:00:00Z");
350 Expect.equals(-1234, dt4.year);
351 Expect.equals(1, dt4.month);
352 Expect.equals(1, dt4.day);
353 Expect.equals(0, dt4.hours);
354 Expect.equals(0, dt4.minutes);
355 Expect.equals(0, dt4.seconds);
356 Expect.equals(0, dt4.milliseconds);
357 Expect.isTrue(dt4.isUtc());
358 var dt5 = new Date.fromString("0099-01-02");
359 Expect.equals(99, dt5.year);
360 Expect.equals(1, dt5.month);
361 Expect.equals(2, dt5.day);
362 Expect.equals(0, dt5.hours);
363 Expect.equals(0, dt5.minutes);
364 Expect.equals(0, dt5.seconds);
365 Expect.equals(0, dt5.milliseconds);
366 Expect.isFalse(dt5.isUtc());
367 var dt6 = new Date.fromString("2012-01-01 00:00:10.012");
368 Expect.equals(12, dt6.milliseconds);
369 dt6 = new Date.fromString("2012-01-01 00:00:10.003");
370 Expect.equals(3, dt6.milliseconds);
371 dt6 = new Date.fromString("2012-01-01 00:00:10.5");
372 Expect.equals(500, dt6.milliseconds);
373 dt6 = new Date.fromString("2012-01-01 00:00:10.003Z");
374 Expect.equals(3, dt6.milliseconds);
375 dt6 = new Date.fromString("2012-01-01 00:00:10.5z");
376 Expect.equals(500, dt6.milliseconds);
377 var dt7 = new Date.fromString("2011-05-11T18:58:35Z");
378 Expect.equals(1305140315000, dt7.value);
379 var dt8 = new Date.fromString("-1234-01-01T00:00:00Z");
380 Expect.equals(-1234, dt8.year);
381 Expect.equals(1, dt8.month);
382 Expect.equals(1, dt8.day);
383 Expect.equals(0, dt8.hours);
384 Expect.equals(0, dt8.minutes);
385 Expect.equals(0, dt8.seconds);
386 Expect.equals(0, dt8.milliseconds);
387 Expect.isTrue(dt8.isUtc());
388 var dt9 = new Date.fromString("-1234-01-01T00:00:00");
389 Expect.equals(-1234, dt9.year);
390 Expect.equals(1, dt9.month);
391 Expect.equals(1, dt9.day);
392 Expect.equals(0, dt9.hours);
393 Expect.equals(0, dt9.minutes);
394 Expect.equals(0, dt9.seconds);
395 Expect.equals(0, dt9.milliseconds);
396 Expect.isFalse(dt9.isUtc());
397 var dt10 = new Date.fromString("-12340101");
398 Expect.equals(-1234, dt10.year);
399 Expect.equals(1, dt10.month);
400 Expect.equals(1, dt10.day);
401 Expect.equals(0, dt10.hours);
402 Expect.equals(0, dt10.minutes);
403 Expect.equals(0, dt10.seconds);
404 Expect.equals(0, dt10.milliseconds);
405 Expect.isFalse(dt10.isUtc());
406 dt1 = new Date.fromString("2012-02-27 13:27:00");
407 Expect.equals(2012, dt1.year);
408 Expect.equals(2, dt1.month);
409 Expect.equals(27, dt1.day);
410 Expect.equals(13, dt1.hours);
411 Expect.equals(27, dt1.minutes);
412 Expect.equals(0, dt1.seconds);
413 Expect.equals(0, dt1.milliseconds);
414 Expect.equals(false, dt1.isUtc());
415 dt1 = new Date.fromString("2012-02-27 13:27:00.423z");
416 Expect.equals(2012, dt1.year);
417 Expect.equals(2, dt1.month);
418 Expect.equals(27, dt1.day);
419 Expect.equals(13, dt1.hours);
420 Expect.equals(27, dt1.minutes);
421 Expect.equals(0, dt1.seconds);
422 Expect.equals(423, dt1.milliseconds);
423 Expect.equals(true, dt1.isUtc());
424 dt1 = new Date.fromString("20120227 13:27:00");
425 Expect.equals(2012, dt1.year);
426 Expect.equals(2, dt1.month);
427 Expect.equals(27, dt1.day);
428 Expect.equals(13, dt1.hours);
429 Expect.equals(27, dt1.minutes);
430 Expect.equals(0, dt1.seconds);
431 Expect.equals(0, dt1.milliseconds);
432 Expect.equals(false, dt1.isUtc());
433 dt1 = new Date.fromString("20120227T132700");
434 Expect.equals(2012, dt1.year);
435 Expect.equals(2, dt1.month);
436 Expect.equals(27, dt1.day);
437 Expect.equals(13, dt1.hours);
438 Expect.equals(27, dt1.minutes);
439 Expect.equals(0, dt1.seconds);
440 Expect.equals(0, dt1.milliseconds);
441 Expect.equals(false, dt1.isUtc());
442 dt1 = new Date.fromString("20120227");
443 Expect.equals(2012, dt1.year);
444 Expect.equals(2, dt1.month);
445 Expect.equals(27, dt1.day);
446 Expect.equals(0, dt1.hours);
447 Expect.equals(0, dt1.minutes);
448 Expect.equals(0, dt1.seconds);
449 Expect.equals(0, dt1.milliseconds);
450 Expect.equals(false, dt1.isUtc());
451 dt1 = new Date.fromString("2012-02-27T14Z");
452 Expect.equals(2012, dt1.year);
453 Expect.equals(2, dt1.month);
454 Expect.equals(27, dt1.day);
455 Expect.equals(14, dt1.hours);
456 Expect.equals(0, dt1.minutes);
457 Expect.equals(0, dt1.seconds);
458 Expect.equals(0, dt1.milliseconds);
459 Expect.equals(true, dt1.isUtc());
460 dt1 = new Date.fromString("-123450101 00:00:00 Z");
461 Expect.equals(-12345, dt1.year);
462 Expect.equals(1, dt1.month);
463 Expect.equals(1, dt1.day);
464 Expect.equals(0, dt1.hours);
465 Expect.equals(0, dt1.minutes);
466 Expect.equals(0, dt1.seconds);
467 Expect.equals(0, dt1.milliseconds);
468 Expect.equals(true, dt1.isUtc());
469 // We only support milliseconds. If the user supplies more data (the "51"
470 // here), we round.
471 // If (eventually) we support more than just milliseconds this test could
472 // fail. Please update the test in this case.
473 dt1 = new Date.fromString("1999-01-02 23:59:59.99951");
474 Expect.equals(1999, dt1.year);
475 Expect.equals(1, dt1.month);
476 Expect.equals(3, dt1.day);
477 Expect.equals(0, dt1.hours);
478 Expect.equals(0, dt1.minutes);
479 Expect.equals(0, dt1.seconds);
480 Expect.equals(0, dt1.milliseconds);
481 Expect.equals(false, dt1.isUtc());
482 dt1 = new Date.fromString("1999-01-02 23:58:59.99951Z");
483 Expect.equals(1999, dt1.year);
484 Expect.equals(1, dt1.month);
485 Expect.equals(2, dt1.day);
486 Expect.equals(23, dt1.hours);
487 Expect.equals(59, dt1.minutes);
488 Expect.equals(0, dt1.seconds);
489 Expect.equals(0, dt1.milliseconds);
490 Expect.equals(true, dt1.isUtc());
491 dt1 = new Date.fromString("0009-09-09 09:09:09.009Z");
492 Expect.equals(9, dt1.year);
493 Expect.equals(9, dt1.month);
494 Expect.equals(9, dt1.day);
495 Expect.equals(9, dt1.hours);
496 Expect.equals(9, dt1.minutes);
497 Expect.equals(9, dt1.seconds);
498 Expect.equals(9, dt1.milliseconds);
499 Expect.equals(true, dt1.isUtc());
500 }
501
502 static void testWeekday() {
503 // 2011-10-06 is Summertime.
504 var d = new Date(2011, 10, 6, 0, 45, 37, 0);
505 Expect.equals(Date.THU, d.weekday);
506 d = new Date.withTimeZone(2011, 10, 6, 0, 45, 37, 0, const TimeZone.utc());
507 Expect.equals(Date.THU, d.weekday);
508 d = new Date(2011, 10, 5, 23, 45, 37, 0);
509 Expect.equals(Date.WED, d.weekday);
510 d = new Date.withTimeZone(2011, 10, 5, 23, 45, 37, 0, const TimeZone.utc());
511 Expect.equals(Date.WED, d.weekday);
512 // 1970-01-01 is Wintertime.
513 d = new Date(1970, 1, 1, 0, 0, 0, 1);
514 Expect.equals(Date.THU, d.weekday);
515 d = new Date.withTimeZone(1970, 1, 1, 0, 0, 0, 1, const TimeZone.utc());
516 Expect.equals(Date.THU, d.weekday);
517 d = new Date.withTimeZone(1969, 12, 31, 23, 59, 59, 999,
518 const TimeZone.utc());
519 Expect.equals(Date.WED, d.weekday);
520 d = new Date(1969, 12, 31, 23, 59, 59, 999);
521 Expect.equals(Date.WED, d.weekday);
522 d = new Date(2011, 10, 4, 23, 45, 37, 0);
523 Expect.equals(Date.TUE, d.weekday);
524 d = new Date(2011, 10, 3, 23, 45, 37, 0);
525 Expect.equals(Date.MON, d.weekday);
526 d = new Date(2011, 10, 2, 23, 45, 37, 0);
527 Expect.equals(Date.SUN, d.weekday);
528 d = new Date(2011, 10, 1, 23, 45, 37, 0);
529 Expect.equals(Date.SAT, d.weekday);
530 d = new Date(2011, 9, 30, 23, 45, 37, 0);
531 Expect.equals(Date.FRI, d.weekday);
532 }
533
534 static void testMain() {
535 testNow();
536 testValue();
537 testUTCGetters();
538 testLocalGetters();
539 testConstructors();
540 testChangeTimeZone();
541 testSubAdd();
542 testDateStrings();
543 testEquivalentYears();
544 testFarAwayDates();
545 testWeekday();
546 }
547 }
548
549 main() {
550 DateTest.testMain();
551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698