source: Dev/branches/rest-dojo-ui/client/dojo/tests/date/stamp.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.5 KB
Line 
1dojo.provide("dojo.tests.date.stamp");
2
3dojo.require("dojo.date.stamp");
4
5tests.register("tests.date.stamp",
6        [
7function test_date_iso(t){
8        var rfc  = "2005-06-29T08:05:00-07:00";
9        var date = dojo.date.stamp.fromISOString(rfc);
10        t.is(2005,date.getFullYear());
11        t.is(5,date.getMonth());
12        t.is(29,date.getUTCDate());
13        t.is(15,date.getUTCHours());
14        t.is(5,date.getUTCMinutes());
15        t.is(0,date.getSeconds());
16
17        rfc  = "2004-02-29";
18        date = dojo.date.stamp.fromISOString(rfc);
19        t.is(2004,date.getFullYear());
20        t.is(1,date.getMonth());
21        t.is(29,date.getDate());
22
23        rfc  = "2004-01";
24        date = dojo.date.stamp.fromISOString(rfc);
25        t.is(2004,date.getFullYear());
26        t.is(0,date.getMonth());
27        t.is(1,date.getDate());
28
29        // No TZ info means local time
30        rfc  = "2004-02-29T01:23:45";
31        date = dojo.date.stamp.fromISOString(rfc);
32        t.is(2004,date.getFullYear());
33        t.is(1,date.getMonth());
34        t.is(29,date.getDate());
35        t.is(1,date.getHours());
36
37        date = new Date(2005,5,29,8,5,0);
38        rfc = dojo.date.stamp.toISOString(date);
39        //truncate for comparison
40        t.is("2005-06",rfc.substring(0,7));
41
42        date = new Date(101,0,2);
43        date.setFullYear(101);
44        rfc = dojo.date.stamp.toISOString(date);
45        //truncate for comparison
46        t.is("0101-01",rfc.substring(0,7));
47
48        rfc  = "0101-01-01";
49        date = dojo.date.stamp.fromISOString(rfc);
50        t.is(101,date.getFullYear());
51        t.is(0,date.getMonth());
52        t.is(1,date.getDate());
53
54        rfc = "0001-01T00:00:00";
55        date = dojo.date.stamp.fromISOString(rfc);
56        t.is(1,date.getFullYear());
57
58        date = dojo.date.stamp.fromISOString("T18:46:39");
59        t.is(18, date.getHours());
60        t.is(46, date.getMinutes());
61        t.is(39, date.getSeconds());
62},
63
64function test_date_iso_tz(t){
65
66        //23:59:59.9942 or 235959.9942
67//      var date = dojo.date.stamp.fromISOString("T18:46:39.9942");
68//      t.is(18, date.getHours());
69//      t.is(46, date.getMinutes());
70//      t.is(39, date.getSeconds());
71//      t.is(994, date.getMilliseconds());
72       
73        //1995-02-04 24:00 = 1995-02-05 00:00
74
75        //timezone tests
76        var offset = new Date().getTimezoneOffset()/60;
77        date = dojo.date.stamp.fromISOString("T18:46:39+07:00");
78        t.is(11, date.getUTCHours());
79
80        date = dojo.date.stamp.fromISOString("T18:46:39+00:00");
81        t.is(18, date.getUTCHours());
82
83        date = dojo.date.stamp.fromISOString("T18:46:39Z");
84        t.is(18, date.getUTCHours());
85
86        date = dojo.date.stamp.fromISOString("T16:46:39-07:00");
87        t.is(23, date.getUTCHours());
88       
89        date = dojo.date.stamp.fromISOString("T00:00:00Z", new Date(2010,3,1));
90        t.is(0, date.getUTCHours());
91        t.is(2010, date.getFullYear());
92       
93        //+hh:mm, +hhmm, or +hh
94       
95        //-hh:mm, -hhmm, or -hh
96        }
97        ]
98);
Note: See TracBrowser for help on using the repository browser.