aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojo/tests/date.js
blob: 57df0fd46417baf05647a94f283a0df6e61df391 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
if(!dojo._hasResource["tests.date"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["tests.date"] = true;
dojo.provide("tests.date");

dojo.require("dojo.date");

tests.register("tests.date.util", 
	[

/* Informational Functions
 **************************/

function test_date_getDaysInMonth(t){
	// months other than February
	t.is(31, dojo.date.getDaysInMonth(new Date(2006,0,1)));
	t.is(31, dojo.date.getDaysInMonth(new Date(2006,2,1)));
	t.is(30, dojo.date.getDaysInMonth(new Date(2006,3,1)));
	t.is(31, dojo.date.getDaysInMonth(new Date(2006,4,1)));
	t.is(30, dojo.date.getDaysInMonth(new Date(2006,5,1)));
	t.is(31, dojo.date.getDaysInMonth(new Date(2006,6,1)));
	t.is(31, dojo.date.getDaysInMonth(new Date(2006,7,1)));
	t.is(30, dojo.date.getDaysInMonth(new Date(2006,8,1)));
	t.is(31, dojo.date.getDaysInMonth(new Date(2006,9,1)));
	t.is(30, dojo.date.getDaysInMonth(new Date(2006,10,1)));
	t.is(31, dojo.date.getDaysInMonth(new Date(2006,11,1)));

	// Februarys
	t.is(28, dojo.date.getDaysInMonth(new Date(2006,1,1)));
	t.is(29, dojo.date.getDaysInMonth(new Date(2004,1,1)));
	t.is(29, dojo.date.getDaysInMonth(new Date(2000,1,1)));
	t.is(28, dojo.date.getDaysInMonth(new Date(1900,1,1)));
	t.is(28, dojo.date.getDaysInMonth(new Date(1800,1,1)));
	t.is(28, dojo.date.getDaysInMonth(new Date(1700,1,1)));
	t.is(29, dojo.date.getDaysInMonth(new Date(1600,1,1)));
},

function test_date_isLeapYear(t){
	t.f(dojo.date.isLeapYear(new Date(2006,0,1)));
	t.t(dojo.date.isLeapYear(new Date(2004,0,1)));
	t.t(dojo.date.isLeapYear(new Date(2000,0,1)));
	t.f(dojo.date.isLeapYear(new Date(1900,0,1)));
	t.f(dojo.date.isLeapYear(new Date(1800,0,1)));
	t.f(dojo.date.isLeapYear(new Date(1700,0,1)));
	t.t(dojo.date.isLeapYear(new Date(1600,0,1)));
},

// The getTimezone function pulls from either the date's toString or
// toLocaleString method -- it's really just a string-processing
// function (assuming the Date obj passed in supporting both toString 
// and toLocaleString) and as such can be tested for multiple browsers
// by manually settting up fake Date objects with the actual strings
// produced by various browser/OS combinations.
// FIXME: the function and tests are not localized.
function test_date_getTimezoneName(t){
	
	// Create a fake Date object with toString and toLocaleString
	// results manually set to simulate tests for multiple browsers
	function FakeDate(str, strLocale){
		this.str = str || '';
		this.strLocale = strLocale || '';
		this.toString = function() {
			return this.str;
		};
		this.toLocaleString = function(){
			return this.strLocale;
		};
	}
	var dt = new FakeDate();
	
	// FF 1.5 Ubuntu Linux (Breezy)
	dt.str = 'Sun Sep 17 2006 22:25:51 GMT-0500 (CDT)';
	dt.strLocale = 'Sun 17 Sep 2006 10:25:51 PM CDT';
	t.is('CDT', dojo.date.getTimezoneName(dt));

	// Safari 2.0 Mac OS X 10.4
	dt.str = 'Sun Sep 17 2006 22:55:01 GMT-0500';
	dt.strLocale = 'September 17, 2006 10:55:01 PM CDT';
	t.is('CDT', dojo.date.getTimezoneName(dt));

	// FF 1.5 Mac OS X 10.4
	dt.str = 'Sun Sep 17 2006 22:57:18 GMT-0500 (CDT)';
	dt.strLocale = 'Sun Sep 17 22:57:18 2006';
	t.is('CDT', dojo.date.getTimezoneName(dt));

	// Opera 9 Mac OS X 10.4 -- no TZ data expect empty string return
	dt.str = 'Sun, 17 Sep 2006 22:58:06 GMT-0500';
	dt.strLocale = 'Sunday September 17, 22:58:06 GMT-0500 2006';
	t.is('', dojo.date.getTimezoneName(dt));
	
	// IE 6 Windows XP
	dt.str = 'Mon Sep 18 11:21:07 CDT 2006';
	dt.strLocale = 'Monday, September 18, 2006 11:21:07 AM';
	t.is('CDT', dojo.date.getTimezoneName(dt));

	// Opera 9 Ubuntu Linux (Breezy) -- no TZ data expect empty string return 
	dt.str = 'Mon, 18 Sep 2006 13:30:32 GMT-0500';
	dt.strLocale = 'Monday September 18, 13:30:32 GMT-0500 2006';
	t.is('', dojo.date.getTimezoneName(dt));
	
	// IE 5.5 Windows 2000
	dt.str = 'Mon Sep 18 13:49:22 CDT 2006';
	dt.strLocale = 'Monday, September 18, 2006 1:49:22 PM';
	t.is('CDT', dojo.date.getTimezoneName(dt));
}
	]
);

tests.register("tests.date.math", 
	[
function test_date_compare(t){
	var d1=new Date();
	d1.setHours(0);
	var d2=new Date();
	d2.setFullYear(2005);
	d2.setHours(12);
	t.is(0, dojo.date.compare(d1, d1));
	t.is(1, dojo.date.compare(d1, d2, "date"));
	t.is(-1, dojo.date.compare(d2, d1, "date"));
	t.is(-1, dojo.date.compare(d1, d2, "time"));
	t.is(1, dojo.date.compare(d1, d2, "datetime"));
},
function test_date_add(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	
	interv = "year";
	dtA = new Date(2005, 11, 27);
	dtB = new Date(2006, 11, 27);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2005, 11, 27);
	dtB = new Date(2004, 11, 27);
	t.is(dtB, dojo.date.add(dtA, interv, -1));
	
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2001, 1, 28);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2005, 1, 28);
	t.is(dtB, dojo.date.add(dtA, interv, 5));
	
	dtA = new Date(1900, 11, 31);
	dtB = new Date(1930, 11, 31);
	t.is(dtB, dojo.date.add(dtA, interv, 30));
	
	dtA = new Date(1995, 11, 31);
	dtB = new Date(2030, 11, 31);
	t.is(dtB, dojo.date.add(dtA, interv, 35));

	interv = "quarter";
	dtA = new Date(2000, 0, 1);
	dtB = new Date(2000, 3, 1);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2000, 7, 29);
	t.is(dtB, dojo.date.add(dtA, interv, 2));
	
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2001, 1, 28);
	t.is(dtB, dojo.date.add(dtA, interv, 4));
	
	interv = "month";
	dtA = new Date(2000, 0, 1);
	dtB = new Date(2000, 1, 1);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2000, 0, 31);
	dtB = new Date(2000, 1, 29);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2001, 1, 28);
	t.is(dtB, dojo.date.add(dtA, interv, 12));
	
	interv = "week";
	dtA = new Date(2000, 0, 1);
	dtB = new Date(2000, 0, 8);
	t.is(dtB, dojo.date.add(dtA, interv, 1));

	interv = "day";
	dtA = new Date(2000, 0, 1);
	dtB = new Date(2000, 0, 2);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2001, 0, 1);
	dtB = new Date(2002, 0, 1);
	t.is(dtB, dojo.date.add(dtA, interv, 365));
	
	dtA = new Date(2000, 0, 1);
	dtB = new Date(2001, 0, 1);
	t.is(dtB, dojo.date.add(dtA, interv, 366));
	
	dtA = new Date(2000, 1, 28);
	dtB = new Date(2000, 1, 29);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2001, 1, 28);
	dtB = new Date(2001, 2, 1);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	dtA = new Date(2000, 2, 1);
	dtB = new Date(2000, 1, 29);
	t.is(dtB, dojo.date.add(dtA, interv, -1));
	
	dtA = new Date(2001, 2, 1);
	dtB = new Date(2001, 1, 28);
	t.is(dtB, dojo.date.add(dtA, interv, -1));
	
	dtA = new Date(2000, 0, 1);
	dtB = new Date(1999, 11, 31);
	t.is(dtB, dojo.date.add(dtA, interv, -1));
	
	interv = "weekday";
	// Sat, Jan 1
	dtA = new Date(2000, 0, 1);
	// Should be Mon, Jan 3
	dtB = new Date(2000, 0, 3);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	// Sun, Jan 2
	dtA = new Date(2000, 0, 2);
	// Should be Mon, Jan 3
	dtB = new Date(2000, 0, 3);
	t.is(dtB, dojo.date.add(dtA, interv, 1));
	
	// Sun, Jan 2
	dtA = new Date(2000, 0, 2);
	// Should be Fri, Jan 7
	dtB = new Date(2000, 0, 7);
	t.is(dtB, dojo.date.add(dtA, interv, 5));
	
	// Sun, Jan 2
	dtA = new Date(2000, 0, 2);
	// Should be Mon, Jan 10
	dtB = new Date(2000, 0, 10);
	t.is(dtB, dojo.date.add(dtA, interv, 6));
	
	// Mon, Jan 3
	dtA = new Date(2000, 0, 3);
	// Should be Mon, Jan 17
	dtB = new Date(2000, 0, 17);
	t.is(dtB, dojo.date.add(dtA, interv, 10));
	
	// Sat, Jan 8
	dtA = new Date(2000, 0, 8);
	// Should be Mon, Jan 3
	dtB = new Date(2000, 0, 3);
	t.is(dtB, dojo.date.add(dtA, interv, -5));
	
	// Sun, Jan 9
	dtA = new Date(2000, 0, 9);
	// Should be Wed, Jan 5
	dtB = new Date(2000, 0, 5);
	t.is(dtB, dojo.date.add(dtA, interv, -3));
	
	// Sun, Jan 23
	dtA = new Date(2000, 0, 23);
	// Should be Fri, Jan 7
	dtB = new Date(2000, 0, 7);
	t.is(dtB, dojo.date.add(dtA, interv, -11));
	
	interv = "hour";
	dtA = new Date(2000, 0, 1, 11);
	dtB = new Date(2000, 0, 1, 12);
	t.is(dtB, dojo.date.add(dtA, interv, 1));

	dtA = new Date(2001, 9, 28, 0);
	dtB = new Date(dtA.getTime() + (60 * 60 * 1000));
	t.is(dtB, dojo.date.add(dtA, interv, 1));

	dtA = new Date(2001, 9, 28, 23);
	dtB = new Date(2001, 9, 29, 0);
	t.is(dtB, dojo.date.add(dtA, interv, 1));

	dtA = new Date(2001, 11, 31, 23);
	dtB = new Date(2002, 0, 1, 0);
	t.is(dtB, dojo.date.add(dtA, interv, 1));

	interv = "minute";
	dtA = new Date(2000, 11, 31, 23, 59);
	dtB = new Date(2001, 0, 1, 0, 0);
	t.is(dtB, dojo.date.add(dtA, interv, 1));

	dtA = new Date(2000, 11, 27, 12, 2);
	dtB = new Date(2000, 11, 27, 13, 2);
	t.is(dtB, dojo.date.add(dtA, interv, 60));
	
	interv = "second";
	dtA = new Date(2000, 11, 31, 23, 59, 59);
	dtB = new Date(2001, 0, 1, 0, 0, 0);
	t.is(dtB, dojo.date.add(dtA, interv, 1));

	dtA = new Date(2000, 11, 27, 8, 10, 59);
	dtB = new Date(2000, 11, 27, 8, 11, 59);
	t.is(dtB, dojo.date.add(dtA, interv, 60));
	
	// Test environment JS Date doesn't support millisec?
	//interv = "millisecond";
	//
	//dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
	//dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
	//t.is(dtB, dojo.date.add(dtA, interv, 1));
	//
	//dtA = new Date(2000, 11, 27, 8, 10, 53, 2);
	//dtB = new Date(2000, 11, 27, 8, 10, 54, 2);
	//t.is(dtB, dojo.date.add(dtA, interv, 1000));
},
function test_date_diff(t){
	var dtA = null; // First date to compare
	var dtB = null; // Second date to compare
	var interv = ''; // Interval to compare on (e.g., year, month)
	
	interv = "year";
	dtA = new Date(2005, 11, 27);
	dtB = new Date(2006, 11, 27);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 11, 31);
	dtB = new Date(2001, 0, 1);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	interv = "quarter";
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2001, 2, 1);
	t.is(4, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 11, 1);
	dtB = new Date(2001, 0, 1);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	interv = "month";
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2001, 2, 1);
	t.is(13, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 11, 1);
	dtB = new Date(2001, 0, 1);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	interv = "week";
	dtA = new Date(2000, 1, 1);
	dtB = new Date(2000, 1, 8);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 1, 28);
	dtB = new Date(2000, 2, 6);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 2, 6);
	dtB = new Date(2000, 1, 28);
	t.is(-1, dojo.date.difference(dtA, dtB, interv));
	
	interv = "day";
	dtA = new Date(2000, 1, 29);
	dtB = new Date(2000, 2, 1);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 11, 31);
	dtB = new Date(2001, 0, 1);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	// DST leap -- check for rounding err
	// This is dependent on US calendar, but
	// shouldn't break in other locales
	dtA = new Date(2005, 3, 3);
	dtB = new Date(2005, 3, 4);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	interv = "weekday";
	dtA = new Date(2006, 7, 3);
	dtB = new Date(2006, 7, 11);
	t.is(6, dojo.date.difference(dtA, dtB, interv));
	
	// Positive diffs
	dtA = new Date(2006, 7, 4);
	dtB = new Date(2006, 7, 11);
	t.is(5, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 5);
	dtB = new Date(2006, 7, 11);
	t.is(5, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 6);
	dtB = new Date(2006, 7, 11);
	t.is(5, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 7);
	dtB = new Date(2006, 7, 11);
	t.is(4, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 7);
	dtB = new Date(2006, 7, 13);
	t.is(4, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 7);
	dtB = new Date(2006, 7, 14);
	t.is(5, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 7);
	dtB = new Date(2006, 7, 15);
	t.is(6, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 7);
	dtB = new Date(2006, 7, 28);
	t.is(15, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 2, 2);
	dtB = new Date(2006, 2, 28);
	t.is(18, dojo.date.difference(dtA, dtB, interv));
	
	// Negative diffs
	dtA = new Date(2006, 7, 11);
	dtB = new Date(2006, 7, 4);
	t.is(-5, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 11);
	dtB = new Date(2006, 7, 5);
	t.is(-4, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 11);
	dtB = new Date(2006, 7, 6);
	t.is(-4, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 11);
	dtB = new Date(2006, 7, 7);
	t.is(-4, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 13);
	dtB = new Date(2006, 7, 7);
	t.is(-5, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 14);
	dtB = new Date(2006, 7, 7);
	t.is(-5, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 15);
	dtB = new Date(2006, 7, 7);
	t.is(-6, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 7, 28);
	dtB = new Date(2006, 7, 7);
	t.is(-15, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2006, 2, 28);
	dtB = new Date(2006, 2, 2);
	t.is(-18, dojo.date.difference(dtA, dtB, interv));

	// Two days on the same weekend -- no weekday diff
	dtA = new Date(2006, 7, 5);
	dtB = new Date(2006, 7, 6);
	t.is(0, dojo.date.difference(dtA, dtB, interv));
	
	interv = "hour";
	dtA = new Date(2000, 11, 31, 23);
	dtB = new Date(2001, 0, 1, 0);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 11, 31, 12);
	dtB = new Date(2001, 0, 1, 0);
	t.is(12, dojo.date.difference(dtA, dtB, interv));
	
	interv = "minute";
	dtA = new Date(2000, 11, 31, 23, 59);
	dtB = new Date(2001, 0, 1, 0, 0);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 1, 28, 23, 59);
	dtB = new Date(2000, 1, 29, 0, 0);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	interv = "second";
	dtA = new Date(2000, 11, 31, 23, 59, 59);
	dtB = new Date(2001, 0, 1, 0, 0, 0);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	interv = "millisecond";
	dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
	dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
	t.is(1, dojo.date.difference(dtA, dtB, interv));
	
	dtA = new Date(2000, 11, 31, 23, 59, 59, 0);
	dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
	t.is(1000, dojo.date.difference(dtA, dtB, interv));
},
function test_date_add_diff_year(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	
	interv = "year";
	dtA = new Date(2005, 11, 27);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2005, 11, 27);
	dtB = dojo.date.add(dtA, interv, -1);
	t.is(dojo.date.difference(dtA, dtB, interv), -1);
	
	dtA = new Date(2000, 1, 29);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2000, 1, 29);
	dtB = dojo.date.add(dtA, interv, 5);
	t.is(dojo.date.difference(dtA, dtB, interv), 5);
	
	dtA = new Date(1900, 11, 31);
	dtB = dojo.date.add(dtA, interv, 30);
	t.is(dojo.date.difference(dtA, dtB, interv), 30);
	
	dtA = new Date(1995, 11, 31);
	dtB = dojo.date.add(dtA, interv, 35);
	t.is(dojo.date.difference(dtA, dtB, interv), 35);
},
function test_date_add_diff_quarter(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	interv = "quarter";
	dtA = new Date(2000, 0, 1);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2000, 1, 29);
	dtB = dojo.date.add(dtA, interv, 2);
	t.is(dojo.date.difference(dtA, dtB, interv), 2);
	
	dtA = new Date(2000, 1, 29);
	dtB = dojo.date.add(dtA, interv, 4);
	t.is(dojo.date.difference(dtA, dtB, interv), 4);
},
function test_date_add_diff_month(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	interv = "month";
	dtA = new Date(2000, 0, 1);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2000, 0, 31);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2000, 1, 29);
	dtB = dojo.date.add(dtA, interv, 12);
	t.is(dojo.date.difference(dtA, dtB, interv), 12);
},
function test_date_add_diff_week(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	interv = "week";
	dtA = new Date(2000, 0, 1);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
},
function test_date_add_diff_day(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	interv = "day";
	dtA = new Date(2000, 0, 1);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2001, 0, 1);
	dtB = dojo.date.add(dtA, interv, 365);
	t.is(dojo.date.difference(dtA, dtB, interv), 365);
	
	dtA = new Date(2000, 0, 1);
	dtB = dojo.date.add(dtA, interv, 366);
	t.is(dojo.date.difference(dtA, dtB, interv), 366);
	
	dtA = new Date(2000, 1, 28);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2001, 1, 28);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	dtA = new Date(2000, 2, 1);
	dtB = dojo.date.add(dtA, interv, -1);
	t.is(dojo.date.difference(dtA, dtB, interv), -1);
	
	dtA = new Date(2001, 2, 1);
	dtB = dojo.date.add(dtA, interv, -1);
	t.is(dojo.date.difference(dtA, dtB, interv), -1);
	
	dtA = new Date(2000, 0, 1);
	dtB = dojo.date.add(dtA, interv, -1);
	t.is(dojo.date.difference(dtA, dtB, interv), -1);
},
function test_date_add_diff_weekday(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	interv = "weekday";
	// Sat, Jan 1
	dtA = new Date(2000, 0, 1);
	// Should be Mon, Jan 3
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	// Sun, Jan 2
	dtA = new Date(2000, 0, 2);
	// Should be Mon, Jan 3
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
	
	// Sun, Jan 2
	dtA = new Date(2000, 0, 2);
	// Should be Fri, Jan 7
	dtB = dojo.date.add(dtA, interv, 5);
	t.is(dojo.date.difference(dtA, dtB, interv), 5);
	
	// Sun, Jan 2
	dtA = new Date(2000, 0, 2);
	// Should be Mon, Jan 10
	dtB = dojo.date.add(dtA, interv, 6);
	t.is(dojo.date.difference(dtA, dtB, interv), 6);
	
	// Mon, Jan 3
	dtA = new Date(2000, 0, 3);
	// Should be Mon, Jan 17
	dtB = dojo.date.add(dtA, interv, 10);
	t.is(dojo.date.difference(dtA, dtB, interv), 10);
	
	// Sat, Jan 8
	dtA = new Date(2000, 0, 8);
	// Should be Mon, Jan 3
	dtB = dojo.date.add(dtA, interv, -5);
	t.is(dojo.date.difference(dtA, dtB, interv), -5);
	
	// Sun, Jan 9
	dtA = new Date(2000, 0, 9);
	// Should be Wed, Jan 5
	dtB = dojo.date.add(dtA, interv, -3);
	t.is(dojo.date.difference(dtA, dtB, interv), -3);
	
	// Sun, Jan 23
	dtA = new Date(2000, 0, 23);
	// Should be Fri, Jan 7
	dtB = dojo.date.add(dtA, interv, -11);
	t.is(dojo.date.difference(dtA, dtB, interv), -11);
},
function test_date_add_diff_hour(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	interv = "hour";
	dtA = new Date(2000, 0, 1, 11);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);

	dtA = new Date(2001, 9, 28, 0);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);

	dtA = new Date(2001, 9, 28, 23);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);

	dtA = new Date(2001, 11, 31, 23);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);
},
function test_date_add_diff_minute(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	interv = "minute";
	dtA = new Date(2000, 11, 31, 23, 59);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);

	dtA = new Date(2000, 11, 27, 12, 2);
	dtB = dojo.date.add(dtA, interv, 60);
	t.is(dojo.date.difference(dtA, dtB, interv), 60);
},
function test_date_add_diff_second(t){
	var interv = ''; // Interval (e.g., year, month)
	var dtA = null; // Date to increment
	var dtB = null; // Expected result date
	console.debug("second");
	interv = "second";
	dtA = new Date(2000, 11, 31, 23, 59, 59);
	dtB = dojo.date.add(dtA, interv, 1);
	t.is(dojo.date.difference(dtA, dtB, interv), 1);

	dtA = new Date(2000, 11, 27, 8, 10, 59);
	dtB = dojo.date.add(dtA, interv, 60);
	t.is(dojo.date.difference(dtA, dtB, interv), 60);
	
	// Test environment JS Date doesn't support millisec?
	//interv = "millisecond";
	//
	//dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
	//dtB = dojo.date.add(dtA, interv, 1);
	//t.is(dojo.date.difference(dtA, dtB, interv), 1);
	//
	//dtA = new Date(2000, 11, 27, 8, 10, 53, 2);
	//dtB = dojo.date.add(dtA, interv, 1000);
	//t.is(dojo.date.difference(dtA, dtB, interv), 1000);
}
	]
);

dojo.require("tests.date.locale");
dojo.require("tests.date.stamp");

}