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