]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/tests/date.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / tests / date.js
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");
4
5 dojo.require("dojo.date");
6
7 tests.register("tests.date.util", 
8         [
9
10 /* Informational Functions
11  **************************/
12
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)));
26
27         // Februarys
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)));
35 },
36
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)));
45 },
46
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){
55         
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){
59                 this.str = str || '';
60                 this.strLocale = strLocale || '';
61                 this.toString = function() {
62                         return this.str;
63                 };
64                 this.toLocaleString = function(){
65                         return this.strLocale;
66                 };
67         }
68         var dt = new FakeDate();
69         
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));
74
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));
79
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));
84
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));
89         
90         // IE 6 Windows XP
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));
94
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));
99         
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));
104 }
105         ]
106 );
107
108 tests.register("tests.date.math", 
109         [
110 function test_date_compare(t){
111         var d1=new Date();
112         d1.setHours(0);
113         var d2=new Date();
114         d2.setFullYear(2005);
115         d2.setHours(12);
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"));
121 },
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
126         
127         interv = "year";
128         dtA = new Date(2005, 11, 27);
129         dtB = new Date(2006, 11, 27);
130         t.is(dtB, dojo.date.add(dtA, interv, 1));
131         
132         dtA = new Date(2005, 11, 27);
133         dtB = new Date(2004, 11, 27);
134         t.is(dtB, dojo.date.add(dtA, interv, -1));
135         
136         dtA = new Date(2000, 1, 29);
137         dtB = new Date(2001, 1, 28);
138         t.is(dtB, dojo.date.add(dtA, interv, 1));
139         
140         dtA = new Date(2000, 1, 29);
141         dtB = new Date(2005, 1, 28);
142         t.is(dtB, dojo.date.add(dtA, interv, 5));
143         
144         dtA = new Date(1900, 11, 31);
145         dtB = new Date(1930, 11, 31);
146         t.is(dtB, dojo.date.add(dtA, interv, 30));
147         
148         dtA = new Date(1995, 11, 31);
149         dtB = new Date(2030, 11, 31);
150         t.is(dtB, dojo.date.add(dtA, interv, 35));
151
152         interv = "quarter";
153         dtA = new Date(2000, 0, 1);
154         dtB = new Date(2000, 3, 1);
155         t.is(dtB, dojo.date.add(dtA, interv, 1));
156         
157         dtA = new Date(2000, 1, 29);
158         dtB = new Date(2000, 7, 29);
159         t.is(dtB, dojo.date.add(dtA, interv, 2));
160         
161         dtA = new Date(2000, 1, 29);
162         dtB = new Date(2001, 1, 28);
163         t.is(dtB, dojo.date.add(dtA, interv, 4));
164         
165         interv = "month";
166         dtA = new Date(2000, 0, 1);
167         dtB = new Date(2000, 1, 1);
168         t.is(dtB, dojo.date.add(dtA, interv, 1));
169         
170         dtA = new Date(2000, 0, 31);
171         dtB = new Date(2000, 1, 29);
172         t.is(dtB, dojo.date.add(dtA, interv, 1));
173         
174         dtA = new Date(2000, 1, 29);
175         dtB = new Date(2001, 1, 28);
176         t.is(dtB, dojo.date.add(dtA, interv, 12));
177         
178         interv = "week";
179         dtA = new Date(2000, 0, 1);
180         dtB = new Date(2000, 0, 8);
181         t.is(dtB, dojo.date.add(dtA, interv, 1));
182
183         interv = "day";
184         dtA = new Date(2000, 0, 1);
185         dtB = new Date(2000, 0, 2);
186         t.is(dtB, dojo.date.add(dtA, interv, 1));
187         
188         dtA = new Date(2001, 0, 1);
189         dtB = new Date(2002, 0, 1);
190         t.is(dtB, dojo.date.add(dtA, interv, 365));
191         
192         dtA = new Date(2000, 0, 1);
193         dtB = new Date(2001, 0, 1);
194         t.is(dtB, dojo.date.add(dtA, interv, 366));
195         
196         dtA = new Date(2000, 1, 28);
197         dtB = new Date(2000, 1, 29);
198         t.is(dtB, dojo.date.add(dtA, interv, 1));
199         
200         dtA = new Date(2001, 1, 28);
201         dtB = new Date(2001, 2, 1);
202         t.is(dtB, dojo.date.add(dtA, interv, 1));
203         
204         dtA = new Date(2000, 2, 1);
205         dtB = new Date(2000, 1, 29);
206         t.is(dtB, dojo.date.add(dtA, interv, -1));
207         
208         dtA = new Date(2001, 2, 1);
209         dtB = new Date(2001, 1, 28);
210         t.is(dtB, dojo.date.add(dtA, interv, -1));
211         
212         dtA = new Date(2000, 0, 1);
213         dtB = new Date(1999, 11, 31);
214         t.is(dtB, dojo.date.add(dtA, interv, -1));
215         
216         interv = "weekday";
217         // Sat, Jan 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));
222         
223         // Sun, Jan 2
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));
228         
229         // Sun, Jan 2
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));
234         
235         // Sun, Jan 2
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));
240         
241         // Mon, Jan 3
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));
246         
247         // Sat, Jan 8
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));
252         
253         // Sun, Jan 9
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));
258         
259         // Sun, Jan 23
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));
264         
265         interv = "hour";
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));
269
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));
273
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));
277
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));
281
282         interv = "minute";
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));
286
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));
290         
291         interv = "second";
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));
295
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));
299         
300         // Test environment JS Date doesn't support millisec?
301         //interv = "millisecond";
302         //
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));
306         //
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));
310 },
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)
315         
316         interv = "year";
317         dtA = new Date(2005, 11, 27);
318         dtB = new Date(2006, 11, 27);
319         t.is(1, dojo.date.difference(dtA, dtB, interv));
320         
321         dtA = new Date(2000, 11, 31);
322         dtB = new Date(2001, 0, 1);
323         t.is(1, dojo.date.difference(dtA, dtB, interv));
324         
325         interv = "quarter";
326         dtA = new Date(2000, 1, 29);
327         dtB = new Date(2001, 2, 1);
328         t.is(4, dojo.date.difference(dtA, dtB, interv));
329         
330         dtA = new Date(2000, 11, 1);
331         dtB = new Date(2001, 0, 1);
332         t.is(1, dojo.date.difference(dtA, dtB, interv));
333         
334         interv = "month";
335         dtA = new Date(2000, 1, 29);
336         dtB = new Date(2001, 2, 1);
337         t.is(13, dojo.date.difference(dtA, dtB, interv));
338         
339         dtA = new Date(2000, 11, 1);
340         dtB = new Date(2001, 0, 1);
341         t.is(1, dojo.date.difference(dtA, dtB, interv));
342         
343         interv = "week";
344         dtA = new Date(2000, 1, 1);
345         dtB = new Date(2000, 1, 8);
346         t.is(1, dojo.date.difference(dtA, dtB, interv));
347         
348         dtA = new Date(2000, 1, 28);
349         dtB = new Date(2000, 2, 6);
350         t.is(1, dojo.date.difference(dtA, dtB, interv));
351         
352         dtA = new Date(2000, 2, 6);
353         dtB = new Date(2000, 1, 28);
354         t.is(-1, dojo.date.difference(dtA, dtB, interv));
355         
356         interv = "day";
357         dtA = new Date(2000, 1, 29);
358         dtB = new Date(2000, 2, 1);
359         t.is(1, dojo.date.difference(dtA, dtB, interv));
360         
361         dtA = new Date(2000, 11, 31);
362         dtB = new Date(2001, 0, 1);
363         t.is(1, dojo.date.difference(dtA, dtB, interv));
364         
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));
371         
372         interv = "weekday";
373         dtA = new Date(2006, 7, 3);
374         dtB = new Date(2006, 7, 11);
375         t.is(6, dojo.date.difference(dtA, dtB, interv));
376         
377         // Positive diffs
378         dtA = new Date(2006, 7, 4);
379         dtB = new Date(2006, 7, 11);
380         t.is(5, dojo.date.difference(dtA, dtB, interv));
381         
382         dtA = new Date(2006, 7, 5);
383         dtB = new Date(2006, 7, 11);
384         t.is(5, dojo.date.difference(dtA, dtB, interv));
385         
386         dtA = new Date(2006, 7, 6);
387         dtB = new Date(2006, 7, 11);
388         t.is(5, dojo.date.difference(dtA, dtB, interv));
389         
390         dtA = new Date(2006, 7, 7);
391         dtB = new Date(2006, 7, 11);
392         t.is(4, dojo.date.difference(dtA, dtB, interv));
393         
394         dtA = new Date(2006, 7, 7);
395         dtB = new Date(2006, 7, 13);
396         t.is(4, dojo.date.difference(dtA, dtB, interv));
397         
398         dtA = new Date(2006, 7, 7);
399         dtB = new Date(2006, 7, 14);
400         t.is(5, dojo.date.difference(dtA, dtB, interv));
401         
402         dtA = new Date(2006, 7, 7);
403         dtB = new Date(2006, 7, 15);
404         t.is(6, dojo.date.difference(dtA, dtB, interv));
405         
406         dtA = new Date(2006, 7, 7);
407         dtB = new Date(2006, 7, 28);
408         t.is(15, dojo.date.difference(dtA, dtB, interv));
409         
410         dtA = new Date(2006, 2, 2);
411         dtB = new Date(2006, 2, 28);
412         t.is(18, dojo.date.difference(dtA, dtB, interv));
413         
414         // Negative diffs
415         dtA = new Date(2006, 7, 11);
416         dtB = new Date(2006, 7, 4);
417         t.is(-5, dojo.date.difference(dtA, dtB, interv));
418         
419         dtA = new Date(2006, 7, 11);
420         dtB = new Date(2006, 7, 5);
421         t.is(-4, dojo.date.difference(dtA, dtB, interv));
422         
423         dtA = new Date(2006, 7, 11);
424         dtB = new Date(2006, 7, 6);
425         t.is(-4, dojo.date.difference(dtA, dtB, interv));
426         
427         dtA = new Date(2006, 7, 11);
428         dtB = new Date(2006, 7, 7);
429         t.is(-4, dojo.date.difference(dtA, dtB, interv));
430         
431         dtA = new Date(2006, 7, 13);
432         dtB = new Date(2006, 7, 7);
433         t.is(-5, dojo.date.difference(dtA, dtB, interv));
434         
435         dtA = new Date(2006, 7, 14);
436         dtB = new Date(2006, 7, 7);
437         t.is(-5, dojo.date.difference(dtA, dtB, interv));
438         
439         dtA = new Date(2006, 7, 15);
440         dtB = new Date(2006, 7, 7);
441         t.is(-6, dojo.date.difference(dtA, dtB, interv));
442         
443         dtA = new Date(2006, 7, 28);
444         dtB = new Date(2006, 7, 7);
445         t.is(-15, dojo.date.difference(dtA, dtB, interv));
446         
447         dtA = new Date(2006, 2, 28);
448         dtB = new Date(2006, 2, 2);
449         t.is(-18, dojo.date.difference(dtA, dtB, interv));
450
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));
455         
456         interv = "hour";
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));
460         
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));
464         
465         interv = "minute";
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));
469         
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));
473         
474         interv = "second";
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));
478         
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));
483         
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));
487 },
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
492         
493         interv = "year";
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);
497         
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);
501         
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);
505         
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);
509         
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);
513         
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);
517 },
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
522         interv = "quarter";
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);
526         
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);
530         
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);
534 },
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
539         interv = "month";
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);
543         
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);
547         
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);
551 },
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
556         interv = "week";
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);
560 },
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
565         interv = "day";
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);
569         
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);
573         
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);
577         
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);
581         
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);
585         
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);
589         
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);
593         
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);
597 },
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
602         interv = "weekday";
603         // Sat, Jan 1
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);
608         
609         // Sun, Jan 2
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);
614         
615         // Sun, Jan 2
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);
620         
621         // Sun, Jan 2
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);
626         
627         // Mon, Jan 3
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);
632         
633         // Sat, Jan 8
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);
638         
639         // Sun, Jan 9
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);
644         
645         // Sun, Jan 23
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);
650 },
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
655         interv = "hour";
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);
659
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);
663
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);
667
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);
671 },
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
676         interv = "minute";
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);
680
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);
684 },
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");
690         interv = "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);
694
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);
698         
699         // Test environment JS Date doesn't support millisec?
700         //interv = "millisecond";
701         //
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);
705         //
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);
709 }
710         ]
711 );
712
713 dojo.require("tests.date.locale");
714 dojo.require("tests.date.stamp");
715
716 }