1 if(!dojo._hasResource["tests.date"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["tests.date"] = true;
3 dojo.provide("tests.date");
5 dojo.require("dojo.date");
7 tests.register("tests.date.util",
10 /* Informational Functions
11 **************************/
13 function test_date_getDaysInMonth(t){
14 // months other than February
15 t.is(31, dojo.date.getDaysInMonth(new Date(2006,0,1)));
16 t.is(31, dojo.date.getDaysInMonth(new Date(2006,2,1)));
17 t.is(30, dojo.date.getDaysInMonth(new Date(2006,3,1)));
18 t.is(31, dojo.date.getDaysInMonth(new Date(2006,4,1)));
19 t.is(30, dojo.date.getDaysInMonth(new Date(2006,5,1)));
20 t.is(31, dojo.date.getDaysInMonth(new Date(2006,6,1)));
21 t.is(31, dojo.date.getDaysInMonth(new Date(2006,7,1)));
22 t.is(30, dojo.date.getDaysInMonth(new Date(2006,8,1)));
23 t.is(31, dojo.date.getDaysInMonth(new Date(2006,9,1)));
24 t.is(30, dojo.date.getDaysInMonth(new Date(2006,10,1)));
25 t.is(31, dojo.date.getDaysInMonth(new Date(2006,11,1)));
28 t.is(28, dojo.date.getDaysInMonth(new Date(2006,1,1)));
29 t.is(29, dojo.date.getDaysInMonth(new Date(2004,1,1)));
30 t.is(29, dojo.date.getDaysInMonth(new Date(2000,1,1)));
31 t.is(28, dojo.date.getDaysInMonth(new Date(1900,1,1)));
32 t.is(28, dojo.date.getDaysInMonth(new Date(1800,1,1)));
33 t.is(28, dojo.date.getDaysInMonth(new Date(1700,1,1)));
34 t.is(29, dojo.date.getDaysInMonth(new Date(1600,1,1)));
37 function test_date_isLeapYear(t){
38 t.f(dojo.date.isLeapYear(new Date(2006,0,1)));
39 t.t(dojo.date.isLeapYear(new Date(2004,0,1)));
40 t.t(dojo.date.isLeapYear(new Date(2000,0,1)));
41 t.f(dojo.date.isLeapYear(new Date(1900,0,1)));
42 t.f(dojo.date.isLeapYear(new Date(1800,0,1)));
43 t.f(dojo.date.isLeapYear(new Date(1700,0,1)));
44 t.t(dojo.date.isLeapYear(new Date(1600,0,1)));
47 // The getTimezone function pulls from either the date's toString or
48 // toLocaleString method -- it's really just a string-processing
49 // function (assuming the Date obj passed in supporting both toString
50 // and toLocaleString) and as such can be tested for multiple browsers
51 // by manually settting up fake Date objects with the actual strings
52 // produced by various browser/OS combinations.
53 // FIXME: the function and tests are not localized.
54 function test_date_getTimezoneName(t){
56 // Create a fake Date object with toString and toLocaleString
57 // results manually set to simulate tests for multiple browsers
58 function FakeDate(str, strLocale){
60 this.strLocale = strLocale || '';
61 this.toString = function() {
64 this.toLocaleString = function(){
65 return this.strLocale;
68 var dt = new FakeDate();
70 // FF 1.5 Ubuntu Linux (Breezy)
71 dt.str = 'Sun Sep 17 2006 22:25:51 GMT-0500 (CDT)';
72 dt.strLocale = 'Sun 17 Sep 2006 10:25:51 PM CDT';
73 t.is('CDT', dojo.date.getTimezoneName(dt));
75 // Safari 2.0 Mac OS X 10.4
76 dt.str = 'Sun Sep 17 2006 22:55:01 GMT-0500';
77 dt.strLocale = 'September 17, 2006 10:55:01 PM CDT';
78 t.is('CDT', dojo.date.getTimezoneName(dt));
80 // FF 1.5 Mac OS X 10.4
81 dt.str = 'Sun Sep 17 2006 22:57:18 GMT-0500 (CDT)';
82 dt.strLocale = 'Sun Sep 17 22:57:18 2006';
83 t.is('CDT', dojo.date.getTimezoneName(dt));
85 // Opera 9 Mac OS X 10.4 -- no TZ data expect empty string return
86 dt.str = 'Sun, 17 Sep 2006 22:58:06 GMT-0500';
87 dt.strLocale = 'Sunday September 17, 22:58:06 GMT-0500 2006';
88 t.is('', dojo.date.getTimezoneName(dt));
91 dt.str = 'Mon Sep 18 11:21:07 CDT 2006';
92 dt.strLocale = 'Monday, September 18, 2006 11:21:07 AM';
93 t.is('CDT', dojo.date.getTimezoneName(dt));
95 // Opera 9 Ubuntu Linux (Breezy) -- no TZ data expect empty string return
96 dt.str = 'Mon, 18 Sep 2006 13:30:32 GMT-0500';
97 dt.strLocale = 'Monday September 18, 13:30:32 GMT-0500 2006';
98 t.is('', dojo.date.getTimezoneName(dt));
100 // IE 5.5 Windows 2000
101 dt.str = 'Mon Sep 18 13:49:22 CDT 2006';
102 dt.strLocale = 'Monday, September 18, 2006 1:49:22 PM';
103 t.is('CDT', dojo.date.getTimezoneName(dt));
108 tests.register("tests.date.math",
110 function test_date_compare(t){
114 d2.setFullYear(2005);
116 t.is(0, dojo.date.compare(d1, d1));
117 t.is(1, dojo.date.compare(d1, d2, "date"));
118 t.is(-1, dojo.date.compare(d2, d1, "date"));
119 t.is(-1, dojo.date.compare(d1, d2, "time"));
120 t.is(1, dojo.date.compare(d1, d2, "datetime"));
122 function test_date_add(t){
123 var interv = ''; // Interval (e.g., year, month)
124 var dtA = null; // Date to increment
125 var dtB = null; // Expected result date
128 dtA = new Date(2005, 11, 27);
129 dtB = new Date(2006, 11, 27);
130 t.is(dtB, dojo.date.add(dtA, interv, 1));
132 dtA = new Date(2005, 11, 27);
133 dtB = new Date(2004, 11, 27);
134 t.is(dtB, dojo.date.add(dtA, interv, -1));
136 dtA = new Date(2000, 1, 29);
137 dtB = new Date(2001, 1, 28);
138 t.is(dtB, dojo.date.add(dtA, interv, 1));
140 dtA = new Date(2000, 1, 29);
141 dtB = new Date(2005, 1, 28);
142 t.is(dtB, dojo.date.add(dtA, interv, 5));
144 dtA = new Date(1900, 11, 31);
145 dtB = new Date(1930, 11, 31);
146 t.is(dtB, dojo.date.add(dtA, interv, 30));
148 dtA = new Date(1995, 11, 31);
149 dtB = new Date(2030, 11, 31);
150 t.is(dtB, dojo.date.add(dtA, interv, 35));
153 dtA = new Date(2000, 0, 1);
154 dtB = new Date(2000, 3, 1);
155 t.is(dtB, dojo.date.add(dtA, interv, 1));
157 dtA = new Date(2000, 1, 29);
158 dtB = new Date(2000, 7, 29);
159 t.is(dtB, dojo.date.add(dtA, interv, 2));
161 dtA = new Date(2000, 1, 29);
162 dtB = new Date(2001, 1, 28);
163 t.is(dtB, dojo.date.add(dtA, interv, 4));
166 dtA = new Date(2000, 0, 1);
167 dtB = new Date(2000, 1, 1);
168 t.is(dtB, dojo.date.add(dtA, interv, 1));
170 dtA = new Date(2000, 0, 31);
171 dtB = new Date(2000, 1, 29);
172 t.is(dtB, dojo.date.add(dtA, interv, 1));
174 dtA = new Date(2000, 1, 29);
175 dtB = new Date(2001, 1, 28);
176 t.is(dtB, dojo.date.add(dtA, interv, 12));
179 dtA = new Date(2000, 0, 1);
180 dtB = new Date(2000, 0, 8);
181 t.is(dtB, dojo.date.add(dtA, interv, 1));
184 dtA = new Date(2000, 0, 1);
185 dtB = new Date(2000, 0, 2);
186 t.is(dtB, dojo.date.add(dtA, interv, 1));
188 dtA = new Date(2001, 0, 1);
189 dtB = new Date(2002, 0, 1);
190 t.is(dtB, dojo.date.add(dtA, interv, 365));
192 dtA = new Date(2000, 0, 1);
193 dtB = new Date(2001, 0, 1);
194 t.is(dtB, dojo.date.add(dtA, interv, 366));
196 dtA = new Date(2000, 1, 28);
197 dtB = new Date(2000, 1, 29);
198 t.is(dtB, dojo.date.add(dtA, interv, 1));
200 dtA = new Date(2001, 1, 28);
201 dtB = new Date(2001, 2, 1);
202 t.is(dtB, dojo.date.add(dtA, interv, 1));
204 dtA = new Date(2000, 2, 1);
205 dtB = new Date(2000, 1, 29);
206 t.is(dtB, dojo.date.add(dtA, interv, -1));
208 dtA = new Date(2001, 2, 1);
209 dtB = new Date(2001, 1, 28);
210 t.is(dtB, dojo.date.add(dtA, interv, -1));
212 dtA = new Date(2000, 0, 1);
213 dtB = new Date(1999, 11, 31);
214 t.is(dtB, dojo.date.add(dtA, interv, -1));
218 dtA = new Date(2000, 0, 1);
219 // Should be Mon, Jan 3
220 dtB = new Date(2000, 0, 3);
221 t.is(dtB, dojo.date.add(dtA, interv, 1));
224 dtA = new Date(2000, 0, 2);
225 // Should be Mon, Jan 3
226 dtB = new Date(2000, 0, 3);
227 t.is(dtB, dojo.date.add(dtA, interv, 1));
230 dtA = new Date(2000, 0, 2);
231 // Should be Fri, Jan 7
232 dtB = new Date(2000, 0, 7);
233 t.is(dtB, dojo.date.add(dtA, interv, 5));
236 dtA = new Date(2000, 0, 2);
237 // Should be Mon, Jan 10
238 dtB = new Date(2000, 0, 10);
239 t.is(dtB, dojo.date.add(dtA, interv, 6));
242 dtA = new Date(2000, 0, 3);
243 // Should be Mon, Jan 17
244 dtB = new Date(2000, 0, 17);
245 t.is(dtB, dojo.date.add(dtA, interv, 10));
248 dtA = new Date(2000, 0, 8);
249 // Should be Mon, Jan 3
250 dtB = new Date(2000, 0, 3);
251 t.is(dtB, dojo.date.add(dtA, interv, -5));
254 dtA = new Date(2000, 0, 9);
255 // Should be Wed, Jan 5
256 dtB = new Date(2000, 0, 5);
257 t.is(dtB, dojo.date.add(dtA, interv, -3));
260 dtA = new Date(2000, 0, 23);
261 // Should be Fri, Jan 7
262 dtB = new Date(2000, 0, 7);
263 t.is(dtB, dojo.date.add(dtA, interv, -11));
266 dtA = new Date(2000, 0, 1, 11);
267 dtB = new Date(2000, 0, 1, 12);
268 t.is(dtB, dojo.date.add(dtA, interv, 1));
270 dtA = new Date(2001, 9, 28, 0);
271 dtB = new Date(dtA.getTime() + (60 * 60 * 1000));
272 t.is(dtB, dojo.date.add(dtA, interv, 1));
274 dtA = new Date(2001, 9, 28, 23);
275 dtB = new Date(2001, 9, 29, 0);
276 t.is(dtB, dojo.date.add(dtA, interv, 1));
278 dtA = new Date(2001, 11, 31, 23);
279 dtB = new Date(2002, 0, 1, 0);
280 t.is(dtB, dojo.date.add(dtA, interv, 1));
283 dtA = new Date(2000, 11, 31, 23, 59);
284 dtB = new Date(2001, 0, 1, 0, 0);
285 t.is(dtB, dojo.date.add(dtA, interv, 1));
287 dtA = new Date(2000, 11, 27, 12, 2);
288 dtB = new Date(2000, 11, 27, 13, 2);
289 t.is(dtB, dojo.date.add(dtA, interv, 60));
292 dtA = new Date(2000, 11, 31, 23, 59, 59);
293 dtB = new Date(2001, 0, 1, 0, 0, 0);
294 t.is(dtB, dojo.date.add(dtA, interv, 1));
296 dtA = new Date(2000, 11, 27, 8, 10, 59);
297 dtB = new Date(2000, 11, 27, 8, 11, 59);
298 t.is(dtB, dojo.date.add(dtA, interv, 60));
300 // Test environment JS Date doesn't support millisec?
301 //interv = "millisecond";
303 //dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
304 //dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
305 //t.is(dtB, dojo.date.add(dtA, interv, 1));
307 //dtA = new Date(2000, 11, 27, 8, 10, 53, 2);
308 //dtB = new Date(2000, 11, 27, 8, 10, 54, 2);
309 //t.is(dtB, dojo.date.add(dtA, interv, 1000));
311 function test_date_diff(t){
312 var dtA = null; // First date to compare
313 var dtB = null; // Second date to compare
314 var interv = ''; // Interval to compare on (e.g., year, month)
317 dtA = new Date(2005, 11, 27);
318 dtB = new Date(2006, 11, 27);
319 t.is(1, dojo.date.difference(dtA, dtB, interv));
321 dtA = new Date(2000, 11, 31);
322 dtB = new Date(2001, 0, 1);
323 t.is(1, dojo.date.difference(dtA, dtB, interv));
326 dtA = new Date(2000, 1, 29);
327 dtB = new Date(2001, 2, 1);
328 t.is(4, dojo.date.difference(dtA, dtB, interv));
330 dtA = new Date(2000, 11, 1);
331 dtB = new Date(2001, 0, 1);
332 t.is(1, dojo.date.difference(dtA, dtB, interv));
335 dtA = new Date(2000, 1, 29);
336 dtB = new Date(2001, 2, 1);
337 t.is(13, dojo.date.difference(dtA, dtB, interv));
339 dtA = new Date(2000, 11, 1);
340 dtB = new Date(2001, 0, 1);
341 t.is(1, dojo.date.difference(dtA, dtB, interv));
344 dtA = new Date(2000, 1, 1);
345 dtB = new Date(2000, 1, 8);
346 t.is(1, dojo.date.difference(dtA, dtB, interv));
348 dtA = new Date(2000, 1, 28);
349 dtB = new Date(2000, 2, 6);
350 t.is(1, dojo.date.difference(dtA, dtB, interv));
352 dtA = new Date(2000, 2, 6);
353 dtB = new Date(2000, 1, 28);
354 t.is(-1, dojo.date.difference(dtA, dtB, interv));
357 dtA = new Date(2000, 1, 29);
358 dtB = new Date(2000, 2, 1);
359 t.is(1, dojo.date.difference(dtA, dtB, interv));
361 dtA = new Date(2000, 11, 31);
362 dtB = new Date(2001, 0, 1);
363 t.is(1, dojo.date.difference(dtA, dtB, interv));
365 // DST leap -- check for rounding err
366 // This is dependent on US calendar, but
367 // shouldn't break in other locales
368 dtA = new Date(2005, 3, 3);
369 dtB = new Date(2005, 3, 4);
370 t.is(1, dojo.date.difference(dtA, dtB, interv));
373 dtA = new Date(2006, 7, 3);
374 dtB = new Date(2006, 7, 11);
375 t.is(6, dojo.date.difference(dtA, dtB, interv));
378 dtA = new Date(2006, 7, 4);
379 dtB = new Date(2006, 7, 11);
380 t.is(5, dojo.date.difference(dtA, dtB, interv));
382 dtA = new Date(2006, 7, 5);
383 dtB = new Date(2006, 7, 11);
384 t.is(5, dojo.date.difference(dtA, dtB, interv));
386 dtA = new Date(2006, 7, 6);
387 dtB = new Date(2006, 7, 11);
388 t.is(5, dojo.date.difference(dtA, dtB, interv));
390 dtA = new Date(2006, 7, 7);
391 dtB = new Date(2006, 7, 11);
392 t.is(4, dojo.date.difference(dtA, dtB, interv));
394 dtA = new Date(2006, 7, 7);
395 dtB = new Date(2006, 7, 13);
396 t.is(4, dojo.date.difference(dtA, dtB, interv));
398 dtA = new Date(2006, 7, 7);
399 dtB = new Date(2006, 7, 14);
400 t.is(5, dojo.date.difference(dtA, dtB, interv));
402 dtA = new Date(2006, 7, 7);
403 dtB = new Date(2006, 7, 15);
404 t.is(6, dojo.date.difference(dtA, dtB, interv));
406 dtA = new Date(2006, 7, 7);
407 dtB = new Date(2006, 7, 28);
408 t.is(15, dojo.date.difference(dtA, dtB, interv));
410 dtA = new Date(2006, 2, 2);
411 dtB = new Date(2006, 2, 28);
412 t.is(18, dojo.date.difference(dtA, dtB, interv));
415 dtA = new Date(2006, 7, 11);
416 dtB = new Date(2006, 7, 4);
417 t.is(-5, dojo.date.difference(dtA, dtB, interv));
419 dtA = new Date(2006, 7, 11);
420 dtB = new Date(2006, 7, 5);
421 t.is(-4, dojo.date.difference(dtA, dtB, interv));
423 dtA = new Date(2006, 7, 11);
424 dtB = new Date(2006, 7, 6);
425 t.is(-4, dojo.date.difference(dtA, dtB, interv));
427 dtA = new Date(2006, 7, 11);
428 dtB = new Date(2006, 7, 7);
429 t.is(-4, dojo.date.difference(dtA, dtB, interv));
431 dtA = new Date(2006, 7, 13);
432 dtB = new Date(2006, 7, 7);
433 t.is(-5, dojo.date.difference(dtA, dtB, interv));
435 dtA = new Date(2006, 7, 14);
436 dtB = new Date(2006, 7, 7);
437 t.is(-5, dojo.date.difference(dtA, dtB, interv));
439 dtA = new Date(2006, 7, 15);
440 dtB = new Date(2006, 7, 7);
441 t.is(-6, dojo.date.difference(dtA, dtB, interv));
443 dtA = new Date(2006, 7, 28);
444 dtB = new Date(2006, 7, 7);
445 t.is(-15, dojo.date.difference(dtA, dtB, interv));
447 dtA = new Date(2006, 2, 28);
448 dtB = new Date(2006, 2, 2);
449 t.is(-18, dojo.date.difference(dtA, dtB, interv));
451 // Two days on the same weekend -- no weekday diff
452 dtA = new Date(2006, 7, 5);
453 dtB = new Date(2006, 7, 6);
454 t.is(0, dojo.date.difference(dtA, dtB, interv));
457 dtA = new Date(2000, 11, 31, 23);
458 dtB = new Date(2001, 0, 1, 0);
459 t.is(1, dojo.date.difference(dtA, dtB, interv));
461 dtA = new Date(2000, 11, 31, 12);
462 dtB = new Date(2001, 0, 1, 0);
463 t.is(12, dojo.date.difference(dtA, dtB, interv));
466 dtA = new Date(2000, 11, 31, 23, 59);
467 dtB = new Date(2001, 0, 1, 0, 0);
468 t.is(1, dojo.date.difference(dtA, dtB, interv));
470 dtA = new Date(2000, 1, 28, 23, 59);
471 dtB = new Date(2000, 1, 29, 0, 0);
472 t.is(1, dojo.date.difference(dtA, dtB, interv));
475 dtA = new Date(2000, 11, 31, 23, 59, 59);
476 dtB = new Date(2001, 0, 1, 0, 0, 0);
477 t.is(1, dojo.date.difference(dtA, dtB, interv));
479 interv = "millisecond";
480 dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
481 dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
482 t.is(1, dojo.date.difference(dtA, dtB, interv));
484 dtA = new Date(2000, 11, 31, 23, 59, 59, 0);
485 dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
486 t.is(1000, dojo.date.difference(dtA, dtB, interv));
488 function test_date_add_diff_year(t){
489 var interv = ''; // Interval (e.g., year, month)
490 var dtA = null; // Date to increment
491 var dtB = null; // Expected result date
494 dtA = new Date(2005, 11, 27);
495 dtB = dojo.date.add(dtA, interv, 1);
496 t.is(dojo.date.difference(dtA, dtB, interv), 1);
498 dtA = new Date(2005, 11, 27);
499 dtB = dojo.date.add(dtA, interv, -1);
500 t.is(dojo.date.difference(dtA, dtB, interv), -1);
502 dtA = new Date(2000, 1, 29);
503 dtB = dojo.date.add(dtA, interv, 1);
504 t.is(dojo.date.difference(dtA, dtB, interv), 1);
506 dtA = new Date(2000, 1, 29);
507 dtB = dojo.date.add(dtA, interv, 5);
508 t.is(dojo.date.difference(dtA, dtB, interv), 5);
510 dtA = new Date(1900, 11, 31);
511 dtB = dojo.date.add(dtA, interv, 30);
512 t.is(dojo.date.difference(dtA, dtB, interv), 30);
514 dtA = new Date(1995, 11, 31);
515 dtB = dojo.date.add(dtA, interv, 35);
516 t.is(dojo.date.difference(dtA, dtB, interv), 35);
518 function test_date_add_diff_quarter(t){
519 var interv = ''; // Interval (e.g., year, month)
520 var dtA = null; // Date to increment
521 var dtB = null; // Expected result date
523 dtA = new Date(2000, 0, 1);
524 dtB = dojo.date.add(dtA, interv, 1);
525 t.is(dojo.date.difference(dtA, dtB, interv), 1);
527 dtA = new Date(2000, 1, 29);
528 dtB = dojo.date.add(dtA, interv, 2);
529 t.is(dojo.date.difference(dtA, dtB, interv), 2);
531 dtA = new Date(2000, 1, 29);
532 dtB = dojo.date.add(dtA, interv, 4);
533 t.is(dojo.date.difference(dtA, dtB, interv), 4);
535 function test_date_add_diff_month(t){
536 var interv = ''; // Interval (e.g., year, month)
537 var dtA = null; // Date to increment
538 var dtB = null; // Expected result date
540 dtA = new Date(2000, 0, 1);
541 dtB = dojo.date.add(dtA, interv, 1);
542 t.is(dojo.date.difference(dtA, dtB, interv), 1);
544 dtA = new Date(2000, 0, 31);
545 dtB = dojo.date.add(dtA, interv, 1);
546 t.is(dojo.date.difference(dtA, dtB, interv), 1);
548 dtA = new Date(2000, 1, 29);
549 dtB = dojo.date.add(dtA, interv, 12);
550 t.is(dojo.date.difference(dtA, dtB, interv), 12);
552 function test_date_add_diff_week(t){
553 var interv = ''; // Interval (e.g., year, month)
554 var dtA = null; // Date to increment
555 var dtB = null; // Expected result date
557 dtA = new Date(2000, 0, 1);
558 dtB = dojo.date.add(dtA, interv, 1);
559 t.is(dojo.date.difference(dtA, dtB, interv), 1);
561 function test_date_add_diff_day(t){
562 var interv = ''; // Interval (e.g., year, month)
563 var dtA = null; // Date to increment
564 var dtB = null; // Expected result date
566 dtA = new Date(2000, 0, 1);
567 dtB = dojo.date.add(dtA, interv, 1);
568 t.is(dojo.date.difference(dtA, dtB, interv), 1);
570 dtA = new Date(2001, 0, 1);
571 dtB = dojo.date.add(dtA, interv, 365);
572 t.is(dojo.date.difference(dtA, dtB, interv), 365);
574 dtA = new Date(2000, 0, 1);
575 dtB = dojo.date.add(dtA, interv, 366);
576 t.is(dojo.date.difference(dtA, dtB, interv), 366);
578 dtA = new Date(2000, 1, 28);
579 dtB = dojo.date.add(dtA, interv, 1);
580 t.is(dojo.date.difference(dtA, dtB, interv), 1);
582 dtA = new Date(2001, 1, 28);
583 dtB = dojo.date.add(dtA, interv, 1);
584 t.is(dojo.date.difference(dtA, dtB, interv), 1);
586 dtA = new Date(2000, 2, 1);
587 dtB = dojo.date.add(dtA, interv, -1);
588 t.is(dojo.date.difference(dtA, dtB, interv), -1);
590 dtA = new Date(2001, 2, 1);
591 dtB = dojo.date.add(dtA, interv, -1);
592 t.is(dojo.date.difference(dtA, dtB, interv), -1);
594 dtA = new Date(2000, 0, 1);
595 dtB = dojo.date.add(dtA, interv, -1);
596 t.is(dojo.date.difference(dtA, dtB, interv), -1);
598 function test_date_add_diff_weekday(t){
599 var interv = ''; // Interval (e.g., year, month)
600 var dtA = null; // Date to increment
601 var dtB = null; // Expected result date
604 dtA = new Date(2000, 0, 1);
605 // Should be Mon, Jan 3
606 dtB = dojo.date.add(dtA, interv, 1);
607 t.is(dojo.date.difference(dtA, dtB, interv), 1);
610 dtA = new Date(2000, 0, 2);
611 // Should be Mon, Jan 3
612 dtB = dojo.date.add(dtA, interv, 1);
613 t.is(dojo.date.difference(dtA, dtB, interv), 1);
616 dtA = new Date(2000, 0, 2);
617 // Should be Fri, Jan 7
618 dtB = dojo.date.add(dtA, interv, 5);
619 t.is(dojo.date.difference(dtA, dtB, interv), 5);
622 dtA = new Date(2000, 0, 2);
623 // Should be Mon, Jan 10
624 dtB = dojo.date.add(dtA, interv, 6);
625 t.is(dojo.date.difference(dtA, dtB, interv), 6);
628 dtA = new Date(2000, 0, 3);
629 // Should be Mon, Jan 17
630 dtB = dojo.date.add(dtA, interv, 10);
631 t.is(dojo.date.difference(dtA, dtB, interv), 10);
634 dtA = new Date(2000, 0, 8);
635 // Should be Mon, Jan 3
636 dtB = dojo.date.add(dtA, interv, -5);
637 t.is(dojo.date.difference(dtA, dtB, interv), -5);
640 dtA = new Date(2000, 0, 9);
641 // Should be Wed, Jan 5
642 dtB = dojo.date.add(dtA, interv, -3);
643 t.is(dojo.date.difference(dtA, dtB, interv), -3);
646 dtA = new Date(2000, 0, 23);
647 // Should be Fri, Jan 7
648 dtB = dojo.date.add(dtA, interv, -11);
649 t.is(dojo.date.difference(dtA, dtB, interv), -11);
651 function test_date_add_diff_hour(t){
652 var interv = ''; // Interval (e.g., year, month)
653 var dtA = null; // Date to increment
654 var dtB = null; // Expected result date
656 dtA = new Date(2000, 0, 1, 11);
657 dtB = dojo.date.add(dtA, interv, 1);
658 t.is(dojo.date.difference(dtA, dtB, interv), 1);
660 dtA = new Date(2001, 9, 28, 0);
661 dtB = dojo.date.add(dtA, interv, 1);
662 t.is(dojo.date.difference(dtA, dtB, interv), 1);
664 dtA = new Date(2001, 9, 28, 23);
665 dtB = dojo.date.add(dtA, interv, 1);
666 t.is(dojo.date.difference(dtA, dtB, interv), 1);
668 dtA = new Date(2001, 11, 31, 23);
669 dtB = dojo.date.add(dtA, interv, 1);
670 t.is(dojo.date.difference(dtA, dtB, interv), 1);
672 function test_date_add_diff_minute(t){
673 var interv = ''; // Interval (e.g., year, month)
674 var dtA = null; // Date to increment
675 var dtB = null; // Expected result date
677 dtA = new Date(2000, 11, 31, 23, 59);
678 dtB = dojo.date.add(dtA, interv, 1);
679 t.is(dojo.date.difference(dtA, dtB, interv), 1);
681 dtA = new Date(2000, 11, 27, 12, 2);
682 dtB = dojo.date.add(dtA, interv, 60);
683 t.is(dojo.date.difference(dtA, dtB, interv), 60);
685 function test_date_add_diff_second(t){
686 var interv = ''; // Interval (e.g., year, month)
687 var dtA = null; // Date to increment
688 var dtB = null; // Expected result date
689 console.debug("second");
691 dtA = new Date(2000, 11, 31, 23, 59, 59);
692 dtB = dojo.date.add(dtA, interv, 1);
693 t.is(dojo.date.difference(dtA, dtB, interv), 1);
695 dtA = new Date(2000, 11, 27, 8, 10, 59);
696 dtB = dojo.date.add(dtA, interv, 60);
697 t.is(dojo.date.difference(dtA, dtB, interv), 60);
699 // Test environment JS Date doesn't support millisec?
700 //interv = "millisecond";
702 //dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
703 //dtB = dojo.date.add(dtA, interv, 1);
704 //t.is(dojo.date.difference(dtA, dtB, interv), 1);
706 //dtA = new Date(2000, 11, 27, 8, 10, 53, 2);
707 //dtB = dojo.date.add(dtA, interv, 1000);
708 //t.is(dojo.date.difference(dtA, dtB, interv), 1000);
713 dojo.require("tests.date.locale");
714 dojo.require("tests.date.stamp");