Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / actionscript.all / Date.as
blob174599dabcb6e7b5d3facaae76e45b79ddc1d6ae
1 //
2 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // Test case for Date ActionScript class
22 // compile this test case with Ming makeswf, and then
23 // execute it like this gnash -1 -r 0 -v out.swf
26 rcsid="Date.as";
27 #include "check.as"
29 check_equals(typeof(Date), 'function');
30 check_equals(typeof(Date.prototype), 'object');
31 check_equals(typeof(Date.prototype.__proto__), 'object');
32 check_equals(Date.prototype.__proto__, Object.prototype);
33 #if OUTPUT_VERSION > 5
34 check_equals(typeof(Date.__proto__), 'object');
35 check_equals(Date.__proto__, Function.prototype);
37 check (Date.prototype.hasOwnProperty('getDate'));
38 check (Date.prototype.hasOwnProperty('getDay'));
39 check (Date.prototype.hasOwnProperty('getFullYear'));
40 check (Date.prototype.hasOwnProperty('getHours'));
41 check (Date.prototype.hasOwnProperty('getMilliseconds'));
42 check (Date.prototype.hasOwnProperty('getMinutes'));
43 check (Date.prototype.hasOwnProperty('getMonth'));
44 check (Date.prototype.hasOwnProperty('getSeconds'));
45 check (Date.prototype.hasOwnProperty('getTime'));
46 check (Date.prototype.hasOwnProperty('getTimezoneOffset'));
47 check (Date.prototype.hasOwnProperty('getUTCDate'));
48 check (Date.prototype.hasOwnProperty('getUTCDay'));
49 check (Date.prototype.hasOwnProperty('getUTCFullYear'));
50 check (Date.prototype.hasOwnProperty('getUTCHours'));
51 check (Date.prototype.hasOwnProperty('getUTCMilliseconds'));
52 check (Date.prototype.hasOwnProperty('getUTCMinutes'));
53 check (Date.prototype.hasOwnProperty('getUTCMonth'));
54 check (Date.prototype.hasOwnProperty('getUTCSeconds'));
55 check (Date.prototype.hasOwnProperty('getYear'));
56 check (Date.prototype.hasOwnProperty('setDate'));
57 check (Date.prototype.hasOwnProperty('setFullYear'));
58 check (Date.prototype.hasOwnProperty('setHours'));
59 check (Date.prototype.hasOwnProperty('setMilliseconds'));
60 check (Date.prototype.hasOwnProperty('setMinutes'));
61 check (Date.prototype.hasOwnProperty('setMonth'));
62 check (Date.prototype.hasOwnProperty('setSeconds'));
63 check (Date.prototype.hasOwnProperty('setTime'));
64 check (Date.prototype.hasOwnProperty('setUTCDate'));
65 check (Date.prototype.hasOwnProperty('setUTCFullYear'));
66 check (Date.prototype.hasOwnProperty('setUTCHours'));
67 check (Date.prototype.hasOwnProperty('setUTCMilliseconds'));
68 check (Date.prototype.hasOwnProperty('setUTCMinutes'));
69 check (Date.prototype.hasOwnProperty('setUTCMonth'));
70 check (Date.prototype.hasOwnProperty('setUTCSeconds'));
71 check (Date.prototype.hasOwnProperty('setYear'));
72 check (Date.prototype.hasOwnProperty('toString'));
73 check (!Date.prototype.hasOwnProperty('toLocaleString'));
75 // UTC is a static method present from v5
76 check_equals (d.UTC, undefined);
77 check (Date.UTC);
78 #else
79 check_equals(typeof(Date.__proto__), 'undefined');
80 #endif
82 // Static method should be available even if you haven't asked for a Date object.
84 // We have to specify "000.0" bucause ming fails to parse large integer constants,
85 // returning 2147483647 instead of the correct value.
86 check_equals (Date.UTC(2000,0,1).valueOf(), 946684800000.0);
88 // test the Date constructor exists.
89 // This specific value is used below to check conversion back to year/mon/day etc
90 var d = new Date(70,1,2,3,4,5,6);
91 check (d);
93 // test methods' existence
94 check (d.getDate);
95 check (d.getDay);
96 check (d.getFullYear);
97 check (d.getHours);
98 check (d.getMilliseconds);
99 check (d.getMinutes);
100 check (d.getMonth);
101 check (d.getSeconds);
102 check (d.getTime);
103 check (d.getTimezoneOffset);
104 check (d.getUTCDate);
105 check (d.getUTCDay);
106 check (d.getUTCFullYear);
107 check (d.getUTCYear);
108 check (d.getUTCHours);
109 check (d.getUTCMilliseconds);
110 check (d.getUTCMinutes);
111 check (d.getUTCMonth);
112 check (d.getUTCSeconds);
113 check (d.getYear);
114 check (d.setDate);
115 check (d.setFullYear);
116 check (d.setHours);
117 check (d.setMilliseconds);
118 check (d.setMinutes);
119 check (d.setMonth);
120 check (d.setSeconds);
121 check (d.setTime);
122 check (d.setUTCDate);
123 check (d.setUTCFullYear);
124 check (d.setUTCHours);
125 check (d.setUTCMilliseconds);
126 check (d.setUTCMinutes);
127 check (d.setUTCMonth);
128 check (d.setUTCSeconds);
129 check (d.setYear);
130 check (d.toString);
131 check (d.toLocaleString);
132 // UTC is a static method present from v5
133 check_equals (d.UTC, undefined);
134 check (Date.UTC);
136 #if OUTPUT_VERSION > 6
137 // From SWF 7 up methods are case-sensitive !
138 check_equals (d.getdate, undefined);
139 check_equals (d.getday, undefined);
140 check_equals (d.getfullYear, undefined);
141 check_equals (d.gethours, undefined);
142 check_equals (d.getmilliseconds, undefined);
143 check_equals (d.getminutes, undefined);
144 check_equals (d.getmonth, undefined);
145 check_equals (d.getseconds, undefined);
146 check_equals (d.gettime, undefined);
147 check_equals (d.gettimezoneOffset, undefined);
148 check_equals (d.getUTCdate, undefined);
149 check_equals (d.getUTCday, undefined);
150 check_equals (d.getUTCfullYear, undefined);
151 check_equals (d.getUTCyear, undefined);
152 check_equals (d.getUTChours, undefined);
153 check_equals (d.getUTCmilliseconds, undefined);
154 check_equals (d.getUTCminutes, undefined);
155 check_equals (d.getUTCmonth, undefined);
156 check_equals (d.getUTCseconds, undefined);
157 check_equals (d.getyear, undefined);
158 check_equals (d.setdate, undefined);
159 check_equals (d.setfullYear, undefined);
160 check_equals (d.sethours, undefined);
161 check_equals (d.setmilliseconds, undefined);
162 check_equals (d.setminutes, undefined);
163 check_equals (d.setmonth, undefined);
164 check_equals (d.setseconds, undefined);
165 check_equals (d.settime, undefined);
166 check_equals (d.setUTCdate, undefined);
167 check_equals (d.setUTCfullYear, undefined);
168 check_equals (d.setUTChours, undefined);
169 check_equals (d.setUTCmilliseconds, undefined);
170 check_equals (d.setUTCminutes, undefined);
171 check_equals (d.setUTCmonth, undefined);
172 check_equals (d.setUTCseconds, undefined);
173 check_equals (d.setyear, undefined);
174 check_equals (d.tostring, undefined);
175 check_equals (Date.utc, undefined);
176 #else
177 check (d.getdate);
178 check (d.getday);
179 check (d.getfullYear);
180 check (d.gethours);
181 check (d.getmilliseconds);
182 check (d.getminutes);
183 check (d.getmonth);
184 check (d.getseconds);
185 check (d.gettime);
186 check (d.gettimezoneOffset);
187 check (d.getUTCdate);
188 check (d.getUTCday);
189 check (d.getUTCfullYear);
190 check (d.getUTCyear);
191 check (d.getUTChours);
192 check (d.getUTCmilliseconds);
193 check (d.getUTCminutes);
194 check (d.getUTCmonth);
195 check (d.getUTCseconds);
196 check (d.getyear);
197 check (d.setdate);
198 check (d.setfullYear);
199 check (d.sethours);
200 check (d.setmilliseconds);
201 check (d.setminutes);
202 check (d.setmonth);
203 check (d.setseconds);
204 check (d.settime);
205 check (d.setUTCdate);
206 check (d.setUTCfullYear);
207 check (d.setUTChours);
208 check (d.setUTCmilliseconds);
209 check (d.setUTCminutes);
210 check (d.setUTCmonth);
211 check (d.setUTCseconds);
212 check (d.setyear);
213 check (d.tostring);
214 check (Date.utc);
215 #endif // OUTPUT_VERSION > 6
217 // Some values we will use to test things
218 var zero = 0.0;
219 var plusinfinity = 1.0/zero;
220 var minusinfinity = -1.0/zero;
221 var notanumber = zero/zero;
223 // Check Date constructor in its many forms,
224 // (also uses valueOf() and toString() methods)
226 // Constructor with no args sets current localtime
227 var d = new Date();
228 check (d != undefined);
229 // Check it's a valid number after 1 April 2007
230 check (d.valueOf() > 1175385600000.0)
231 // and before Jan 1 2037 00:00:00
232 check (d.valueOf() < 2114380800000.0)
234 // Constructor with first arg == undefined also sets current localtime
235 var d2 = new Date(undefined);
236 check (d2 != undefined);
237 check (d2.valueOf() >= d.valueOf());
238 delete d2;
240 // One numeric argument sets milliseconds since 1970 UTC
241 delete d; var d = new Date(0);
242 // Check UTC "get" methods too
243 check_equals(typeof(d.valueOf()), 'number');
244 check_equals(d.valueOf(), 0);
245 check_equals(typeof(d.getTime()), 'number');
246 check_equals(d.getTime(), 0);
247 check_equals(d.getUTCFullYear(), 1970);
248 check_equals(d.getUTCMonth(), 0);
249 check_equals(d.getUTCDate(), 1);
250 check_equals(d.getUTCDay(), 4); // It was a Thursday
251 check_equals(d.getUTCHours(), 0);
252 check_equals(d.getUTCMinutes(), 0);
253 check_equals(d.getUTCSeconds(), 0);
254 check_equals(d.getUTCMilliseconds(), 0);
256 // These all vary according to timezone... 0 milliseconds since
257 // midnight 1 Jan 1970 was 1969 in anything west of Greenwich.
258 // It *should* fail there (and does in the pp).
259 //check_equals(d.getFullYear(), 1970);
260 //check_equals(d.getMonth(), 0);
261 //check_equals(d.getDate(), 1);
262 //check_equals(d.getDay(), 4); // It was a Thursday
263 //check_equals(d.getHours(), 1);
264 //check_equals(d.getMinutes(), 0);
265 check_equals(d.getSeconds(), 0);
266 check_equals(d.getMilliseconds(), 0);
268 /// No difference:
269 check_equals (Date.toLocaleString(), Date.toString());
271 // Check other convertible types
272 // Booleans convert to 0 and 1
273 var foo = true; delete d; var d = new Date(foo);
274 check_equals(d.valueOf(), 1);
275 foo = false; delete d; var d = new Date(foo);
276 check_equals(d.valueOf(), 0);
277 // Numeric strings
278 foo = "12345"; delete d; var d = new Date(foo);
279 check_equals(d.valueOf(), 12345.0);
280 foo = "12345.0"; delete d; var d = new Date(foo);
281 check_equals(d.valueOf(), 12345.0);
282 foo = "12345.5"; delete d; var d = new Date(foo);
283 check_equals(d.valueOf(), 12345.5); // Sets fractions of msec ok?
284 foo = "-12345"; delete d; var d = new Date(foo);
285 check_equals(d.valueOf(), -12345.0);
286 // Bad numeric values
287 // NAN
288 delete d; var d = new Date(notanumber);
289 check_equals(d.valueOf().toString(), "NaN");
290 check_equals(d.toString(), "Invalid Date");
291 // Infinity
292 delete d; var d = new Date(plusinfinity);
293 check_equals(d.valueOf().toString(), "Infinity");
294 check_equals(d.toString(), "Invalid Date");
295 // -Infinity
296 delete d; var d = new Date(minusinfinity);
297 check_equals(d.valueOf().toString(), "-Infinity");
298 check_equals(d.toString(), "Invalid Date");
299 // Bogus values: non-numeric strings
300 foo = "bones"; delete d; var d = new Date(foo);
301 check_equals(d.valueOf().toString(), "NaN");
302 foo = "1234X"; delete d; var d = new Date(foo);
303 check_equals(d.valueOf().toString(), "NaN");
305 // Constructor with two numeric args means year and month in localtime.
306 // Now we check the localtime decoding methods too.
307 // Negative year means <1900; 0-99 means 1900-1999; 100- means 100-)
308 // Month is 0-11. month>11 increments year; month<0 decrements year.
309 delete d; var d = new Date(70,0); // 1 Jan 1970 00:00:00 localtime
310 check_equals(d.getYear(), 70);
311 check_equals(d.getFullYear(), 1970);
312 check_equals(d.getMonth(), 0);
313 check_equals(d.getDate(), 1);
314 check_equals(d.getDay(), 4); // It was a Thursday
315 check_equals(d.getHours(), 0);
316 check_equals(d.getMinutes(), 0);
317 check_equals(d.getSeconds(), 0);
318 check_equals(d.getMilliseconds(), 0);
319 // Check four-figure version - should be the same.
320 var d2 = new Date(1970,0); check_equals(d.valueOf(), d2.valueOf());
321 // Check four-figure version and non-zero month
322 delete d; var d = new Date(2000,3); // 1 April 2000 00:00:00 localtime
323 check_equals(d.getYear(), 100);
324 check_equals(d.getFullYear(), 2000);
325 check_equals(d.getMonth(), 3);
326 check_equals(d.getDate(), 1);
327 check_equals(d.getDay(), 6); // It was a Saturday
328 check_equals(d.getHours(), 0);
329 check_equals(d.getMinutes(), 0);
330 check_equals(d.getSeconds(), 0);
331 check_equals(d.getMilliseconds(), 0);
332 // Check month overflow/underflow
333 delete d; var d = new Date(2000,12);
334 check_equals(d.getFullYear(), 2001);
335 check_equals(d.getMonth(), 0);
336 delete d; var d = new Date(2000,-18);
337 check_equals(d.getFullYear(), 1998);
338 check_equals(d.getMonth(), 6);
339 // Bad numeric value handling: year is an invalid number with >1 arg
340 // The commercial player for these first three cases gives
341 // -6.77681005679712e+19 Tue Jan -719527 00:00:00 GMT+0000
342 // but that doesn't seem worth emulating...
343 note("The pp is known to fail the next three tests");
344 delete d; var d = new Date(notanumber,0);
345 check_equals(d.valueOf().toString(), "NaN");
346 delete d; var d = new Date(plusinfinity,0);
347 check_equals(d.valueOf().toString(), "Infinity");
348 delete d; var d = new Date(minusinfinity,0);
349 check_equals(d.valueOf().toString(), "-Infinity");
350 // Bad numeric value handling: month is an invalid number
351 delete d; var d = new Date(0,notanumber);
352 check_equals(d.valueOf().toString(), "NaN");
353 delete d; var d = new Date(0,plusinfinity);
354 xcheck_equals(d.valueOf().toString(), "NaN");
355 delete d; var d = new Date(0,minusinfinity);
356 xcheck_equals(d.valueOf().toString(), "NaN");
358 // Constructor with three numeric args means year month day-of-month
359 delete d; var d = new Date(2000,0,1); // 1 Jan 2000 00:00:00 localtime
360 check_equals(d.getFullYear(), 2000);
361 check_equals(d.getMonth(), 0);
362 check_equals(d.getDate(), 1);
363 // Check day-of-month overflow/underflow
364 delete d; var d = new Date(2000,0,32); // 32 Jan -> 1 Feb
365 check_equals(d.getFullYear(), 2000);
366 check_equals(d.getMonth(), 1);
367 check_equals(d.getDate(), 1);
368 delete d; var d = new Date(2000,1,0); // 0 Feb -> 31 Jan
369 check_equals(d.getFullYear(), 2000);
370 check_equals(d.getMonth(), 0);
371 check_equals(d.getDate(), 31);
372 delete d; var d = new Date(2000,0,-6); // -6 Jan 2000 -> 25 Dec 1999
373 check_equals(d.getFullYear(), 1999);
374 check_equals(d.getMonth(), 11);
375 check_equals(d.getDate(), 25);
376 // Bad numeric value handling when day-of-month is an invalid number
377 // A bad month always returns NaN but a bad d-o-m returns the infinities.
378 delete d; var d = new Date(2000,0,notanumber);
379 check_equals(d.valueOf().toString(), "NaN");
380 delete d; var d = new Date(2000,0,plusinfinity);
381 check_equals(d.valueOf().toString(), "Infinity");
382 delete d; var d = new Date(2000,0,minusinfinity);
383 check_equals(d.valueOf().toString(), "-Infinity");
384 // Check bad string value
385 foo = "bones"; delete d; var d = new Date(2000,0,foo);
386 check_equals(d.valueOf().toString(), "NaN");
388 // Constructor with four numeric args means year month day-of-month hour
389 delete d; var d = new Date(2000,0,1,12);
390 check_equals(d.getHours(), 12);
391 check_equals(d.getMinutes(), 0);
392 check_equals(d.getSeconds(), 0);
393 check_equals(d.getMilliseconds(), 0);
394 // Check that fractional parts of hours are ignored
395 delete d; var d = new Date(2000,0,1,12.5);
396 check_equals(d.getHours(), 12);
397 check_equals(d.getMinutes(), 0);
398 // Check hours overflow/underflow
399 delete d; var d = new Date(2000,0,1,25);
400 check_equals(d.getDate(), 2);
401 check_equals(d.getHours(), 1);
402 // Bad hours, like bad d-o-m, return infinites.
403 delete d; var d = new Date(2000,0,1,notanumber);
404 check_equals(d.valueOf().toString(), "NaN");
405 delete d; var d = new Date(2000,0,1,plusinfinity);
406 check_equals(d.valueOf().toString(), "Infinity");
407 delete d; var d = new Date(2000,0,1,minusinfinity);
408 check_equals(d.valueOf().toString(), "-Infinity");
409 // Check bad string value
410 foo = "bones"; delete d; var d = new Date(2000,0,1,foo);
411 check_equals(d.valueOf().toString(), "NaN");
413 // Constructor with five numeric args means year month day-of-month hour min
414 delete d; var d = new Date(2000,0,1,12,30);
415 check_equals(d.getHours(), 12);
416 check_equals(d.getMinutes(), 30);
417 check_equals(d.getSeconds(), 0);
418 check_equals(d.getMilliseconds(), 0);
419 // Check minute overflow/underflow
420 delete d; var d = new Date(2000,0,1,12,70);
421 check_equals(d.getHours(), 13);
422 check_equals(d.getMinutes(), 10);
423 check_equals(d.getSeconds(), 0);
424 delete d; var d = new Date(2000,0,1,12,-120);
425 check_equals(d.getHours(), 10);
426 check_equals(d.getMinutes(), 0);
427 check_equals(d.getSeconds(), 0);
428 // Infinite minutes return infinites.
429 delete d; var d = new Date(2000,0,1,0,notanumber);
430 check_equals(d.valueOf().toString(), "NaN");
431 delete d; var d = new Date(2000,0,1,0,plusinfinity);
432 check_equals(d.valueOf().toString(), "Infinity");
433 delete d; var d = new Date(2000,0,1,0,minusinfinity);
434 check_equals(d.valueOf().toString(), "-Infinity");
435 // Check bad string value
436 foo = "bones"; delete d; var d = new Date(2000,0,1,0,foo);
437 check_equals(d.valueOf().toString(), "NaN");
439 // Constructor with six numeric args means year month d-of-m hour min sec
440 // Check UTC seconds here too since it should be the same.
441 delete d; var d = new Date(2000,0,1,0,0,45);
442 check_equals(d.getHours(), 0);
443 check_equals(d.getMinutes(), 0);
444 check_equals(d.getSeconds(), 45);
445 check_equals(d.getUTCSeconds(), 45);
446 check_equals(d.getMilliseconds(), 0);
447 // Check second overflow/underflow
448 delete d; var d = new Date(2000,0,1,12,0,70);
449 check_equals(d.getHours(), 12);
450 check_equals(d.getMinutes(), 1);
451 check_equals(d.getSeconds(), 10);
452 delete d; var d = new Date(2000,0,1,12,0,-120);
453 check_equals(d.getHours(), 11);
454 check_equals(d.getMinutes(), 58);
455 check_equals(d.getSeconds(), 0);
456 // Infinite seconds return infinites.
457 delete d; var d = new Date(2000,0,1,0,0,notanumber);
458 check_equals(d.valueOf().toString(), "NaN");
459 delete d; var d = new Date(2000,0,1,0,0,plusinfinity);
460 check_equals(d.valueOf().toString(), "Infinity");
461 delete d; var d = new Date(2000,0,1,0,0,minusinfinity);
462 check_equals(d.valueOf().toString(), "-Infinity");
463 // Check bad string value
464 foo = "bones"; delete d; var d = new Date(2000,0,1,0,0,foo);
465 check_equals(d.valueOf().toString(), "NaN");
467 // Constructor with seven numeric args means year month dom hour min sec msec
468 // Check UTC milliseconds here too since it should be the same.
469 delete d; var d = new Date(2000,0,1,0,0,0,500);
470 check_equals(d.getHours(), 0);
471 check_equals(d.getMinutes(), 0);
472 check_equals(d.getSeconds(), 0);
473 check_equals(d.getMilliseconds(), 500);
474 check_equals(d.getUTCMilliseconds(), 500);
475 // Fractions of milliseconds are ignored here
476 delete d; var d = new Date(2000,0,1,0,0,0,500.5);
477 check_equals(d.getMilliseconds(), 500.0);
478 // Check millisecond overflow/underflow
479 delete d; var d = new Date(2000,0,1,12,0,0,1000);
480 check_equals(d.getMinutes(), 0);
481 check_equals(d.getSeconds(), 1);
482 check_equals(d.getMilliseconds(), 0);
483 delete d; var d = new Date(2000,0,1,12,0,0,-120000);
484 check_equals(d.getHours(), 11);
485 check_equals(d.getMinutes(), 58);
486 check_equals(d.getSeconds(), 0);
487 // Infinite milliseconds return infinites.
488 delete d; var d = new Date(2000,0,1,0,0,0,notanumber);
489 check_equals(d.valueOf().toString(), "NaN");
490 delete d; var d = new Date(2000,0,1,0,0,0,plusinfinity);
491 check_equals(d.valueOf().toString(), "Infinity");
492 delete d; var d = new Date(2000,0,1,0,0,0,minusinfinity);
493 check_equals(d.valueOf().toString(), "-Infinity");
494 // Check bad string value
495 foo = "bones"; delete d; var d = new Date(2000,0,1,0,0,0,foo);
496 check_equals(d.valueOf().toString(), "NaN");
497 // Finally, check that a millisecond is enough to overflow/underflow a year
498 delete d; var d = new Date(1999,11,31,23,59,59,1001);
499 check_equals(d.getFullYear(), 2000);
500 check_equals(d.getMonth(), 0);
501 check_equals(d.getDate(), 1);
502 check_equals(d.getMinutes(), 0);
503 check_equals(d.getSeconds(), 0);
504 check_equals(d.getMilliseconds(), 1);
505 delete d; var d = new Date(2000,0,1,0,0,0,-1);
506 //note (d.valueOf());
507 check_equals(d.getFullYear(), 1999);
508 check_equals(d.getMonth(), 11);
509 check_equals(d.getDate(), 31);
510 check_equals(d.getMinutes(), 59);
511 check_equals(d.getSeconds(), 59);
512 check_equals(d.getMilliseconds(), 999);
513 // If a mixture of infinities and/or NaNs are present the result is NaN.
514 delete d; var d = new Date(2000,0,1,plusinfinity,minusinfinity,0,0);
515 check_equals(d.valueOf().toString(), "NaN");
517 wierddate = new Date (-2000, 5, 6, 12, 30, 12, 7);
518 check_equals(wierddate.getFullYear(), -100);
519 check_equals(wierddate.getMonth(), 5);
520 check_equals(wierddate.getDate(), 6);
521 check_equals(wierddate.getHours(), 12);
522 check_equals(wierddate.getMinutes(), 30);
523 check_equals(wierddate.getSeconds(), 12);
524 check_equals(wierddate.getMilliseconds(), 7);
526 // Bogus tests: depend on the timezone.
527 //xcheck_equals(wierddate.valueOf().toString(), "-65309372987993");
529 wierddate.setMilliseconds(300);
530 check_equals(wierddate.getMilliseconds(), 300);
531 check_equals(wierddate.getSeconds(), 12);
533 //xcheck_equals(wierddate.valueOf().toString(), "-65309372987700");
535 wierddate.setMilliseconds(-300);
536 check_equals(wierddate.getMilliseconds(), 700);
537 check_equals(wierddate.getSeconds(), 11);
539 //xcheck_equals(wierddate.valueOf().toString(), "-65309372988300");
541 wierddate.setYear(100000);
542 check_equals(wierddate.getMilliseconds(), 700);
543 check_equals(wierddate.getFullYear(), 100000);
546 wierddate.setYear(-100000);
547 check_equals(wierddate.getMilliseconds(), 700);
548 check_equals(wierddate.getFullYear(), -100000);
550 // The accessor functions for such a large number give different
551 // results according to the platform and compiler options, so
552 // we won't test them.
553 h = new Date(3.0935415006117e+23);
554 check_equals(h.valueOf().toString(), "3.0935415006117e+23");
556 h = new Date(10000001);
557 check_equals(h.getMilliseconds(), 1);
558 check_equals(h.getSeconds(), 40);
559 check_equals(h.getUTCMilliseconds(), 1);
560 check_equals(h.getUTCSeconds(), 40);
561 check_equals(h.getUTCMinutes(), 46);
562 check_equals(h.getUTCDay(), 4);
564 // It's hard to test TimezoneOffset because the values will be different
565 // depending upon where geographically you run the tests.
566 // We do what we can without knowing where we are!
568 // Set midnight local time, adjust for tzoffset
569 // and this should give us midnight UTC.
571 // If we are in GMT+1 then TimezoneOffset is -60.
572 // If we set midnight localtime in the GMT+1 zone,
573 // that is 23:00 the day before in UTC (because in GMT+1 clock times happen
574 // an hour earlier than they do in "real" time).
575 // Thus to set UTC to midnight we need to subtract the TimezoneOffset.
576 delete d;
577 var d = new Date(2000, 0, 1, 0, 0, 0, 0);
578 d.setTime(d.getTime() - (60000 * d.getTimezoneOffset()));
579 check_equals (d.getUTCHours(), 0);
581 // Try the same thing in July to get one with DST and one without
582 d = new Date(2000, 6, 1, 0, 0, 0, 0);
583 d.setTime(d.getTime() - (60000 * d.getTimezoneOffset()));
584 check_equals (d.getUTCHours(), 0);
587 // Test behaviour when you set the time during DST then change
588 // to a non-DST date.
589 // setUTCHours should preserve the time of day in UTC;
590 // setHours should preserve the time of day in localtime.
592 // We assume that January/December and June/July will have different DST values
594 trace ("Testing hour when setting date into/out of DST");
595 d.setUTCFullYear(2000, 0, 1);
596 d.setUTCHours(0, 0, 0, 0);
597 d.setUTCMonth(6);
598 check_equals (d.getUTCHours(), 0);
600 d.setUTCFullYear(2000, 6, 1);
601 d.setUTCHours(0, 0, 0, 0);
602 d.setUTCMonth(11);
603 check_equals (d.getUTCHours(), 0);
605 d.setFullYear(2000, 0, 1);
606 d.setHours(0, 0, 0, 0);
607 d.setMonth(6);
608 check_equals (d.getHours(), 0);
610 d.setFullYear(2000, 6, 1);
611 d.setHours(0, 0, 0, 0);
612 d.setMonth(11);
613 check_equals (d.getHours(), 0);
615 // It's not easy to test the toString() code here because we cannot find out from
616 // within AS whether DST is in effect or not.
618 check_equals (Date.UTC(1970,0), 0);
619 check_equals (Date.UTC(70,0), 0);
621 // Check that Date.UTC gives the same as setUTC*, which we tested above.
622 // Test two dates: one in DST and one not.
623 d.setUTCFullYear(2000, 0, 1);
624 d.setUTCHours(0, 0, 0, 0);
625 check (Date.UTC(2000,0,1,0,0,0,0) == d.valueOf());
626 d.setUTCFullYear(2000, 6, 1);
627 d.setUTCHours(0, 0, 0, 0);
628 check (Date.UTC(2000,6,1,0,0,0,0) == d.valueOf());
630 d1 = Date(123);
631 d2 = new Date;
632 check_equals(d1.toString(), d2.toString());
634 d1 = Date(2008, 10, 10, 10, 10, 10, 10);
635 d2 = new Date;
636 check_equals(d1.toString(), d2.toString());
638 check_equals (Date.UTC(-1000, 20).valueOf(), -33713366400000);
639 check_equals (Date.UTC(-70, 0).toString(), "-4417977600000");
640 check_equals (Date.UTC(-70, 0).valueOf(), -4417977600000);
641 check_equals (Date.UTC(1969, 11).toString(), "-2678400000");
642 check_equals (Date.UTC(1969, 11).valueOf(), -2678400000);
643 check_equals (Date.UTC(1969, 12).toString(), "0");
644 check_equals (Date.UTC(1969, 12).valueOf(), 0);
646 check_equals (Date.UTC(0, 0, 0, 0, 0, 0, 0).toString(), "-2209075200000");
647 check_equals (Date.UTC(1969, 12, 31).toString(), "2592000000");
648 check_equals (Date.UTC(1969, 12, 31).toString(), "2592000000");
650 check_equals (Date.UTC(1970, 1).toString(), "2678400000");
651 check_equals (Date.UTC(1970, 1).valueOf(), 2678400000);
653 check_equals (Date.UTC(-1, -12).toString(), "-2272060800000");
654 check_equals ((Date.UTC(-1, 12).valueOf() < -2208988799999.5 &&
655 Date.UTC(-1, 12).valueOf() > -2208988800000.5), true);
657 pd = new Date();
658 ret = (pd < 67);
659 check_equals(typeof(ret), "boolean");
661 ret = (pd > 67);
662 check_equals(typeof(ret), "boolean");
663 check_equals(ret, true);
665 ret = (pd < "a string");
666 check_equals(typeof(ret), "undefined");
667 check_equals(ret, undefined);
669 ret = (pd > "a string");
670 check_equals(typeof(ret), "undefined");
671 check_equals(ret, undefined);
674 // Check if Date, concatenated to a string, is in human readable form
675 d = new Date(2000, 1, 15, 0, 0, 0);
676 var foo = "foo "+d;
677 var bar = 0+d;
678 check_equals(typeof(foo), 'string');
679 #if OUTPUT_VERSION > 5
680 // correct: "0Tue Feb 15 00:00:00 GMT+0100 2000"
681 // but this probably depends on time zone, so just check for some fixed part..
682 check_equals(typeof(bar), 'string');
683 check_equals(bar.substring(0, 1), '0');
684 check_equals(bar.indexOf("Feb"), 5);
685 // correct: "foo Tue Feb 15 00:00:00 GMT+0100 2000"
686 // but this probably depends on time zone, so just check for some fixed part..
687 check_equals(foo.indexOf("Feb"), 8);
688 #else
689 check_equals(typeof(bar), 'number');
690 // correct: "foo 950569200000", but only for the timezone
691 // of the original author
692 check_equals(foo.substring(0, 7), 'foo 950');
693 #endif
696 var o = new Date();
697 o.setUTCMilliseconds(); // sets o's date to NaN
699 ASSetPropFlags(o.__proto__, null, 0, 1);
700 for (prop in o) {
701 if (prop.substr(0, 3) == "set" && prop != "setTime") {
702 o[prop](1,2,3,4);
703 check_equals(o.valueOf().toString(), "NaN");
708 #if OUTPUT_VERSION == 5
709 totals(307);
710 #else
711 totals (349);
712 #endif