1 | dojo.provide("dojox.date.tests.posix"); |
---|
2 | dojo.require("dojox.date.posix"); |
---|
3 | |
---|
4 | tests.register("dojox.date.tests.posix", |
---|
5 | [ |
---|
6 | { |
---|
7 | // see tests for dojo.date.locale for setup info |
---|
8 | |
---|
9 | name: "dojox.date.tests.posix", |
---|
10 | setUp: function(){ |
---|
11 | var partLocaleList = ["en"]; |
---|
12 | |
---|
13 | dojo.forEach(partLocaleList, function(locale){ |
---|
14 | dojo.requireLocalization("dojo.cldr", "gregorian", locale); |
---|
15 | }); |
---|
16 | }, |
---|
17 | runTest: function(t){ |
---|
18 | }, |
---|
19 | tearDown: function(){ |
---|
20 | //Clean up bundles that should not exist if |
---|
21 | //the test is re-run. |
---|
22 | // delete dojo.cldr.nls.gregorian; |
---|
23 | } |
---|
24 | }, |
---|
25 | { |
---|
26 | name: "strftime", |
---|
27 | runTest: function(t){ |
---|
28 | var date = new Date(2006, 7, 11, 0, 55, 12, 3456); |
---|
29 | t.is("06/08/11", dojox.date.posix.strftime(date, "%y/%m/%d")); |
---|
30 | |
---|
31 | var dt = null; // Date to test |
---|
32 | var fmt = ''; // Format to test |
---|
33 | var res = ''; // Expected result |
---|
34 | |
---|
35 | dt = new Date(2006, 0, 1, 18, 23); |
---|
36 | fmt = '%a'; |
---|
37 | res = 'Sun'; |
---|
38 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
39 | |
---|
40 | fmt = '%A'; |
---|
41 | res = 'Sunday'; |
---|
42 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
43 | |
---|
44 | fmt = '%b'; |
---|
45 | res = 'Jan'; |
---|
46 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
47 | |
---|
48 | fmt = '%B'; |
---|
49 | res = 'January'; |
---|
50 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
51 | |
---|
52 | fmt = '%c'; |
---|
53 | res = 'Sunday, January 1, 2006 6:23:00 PM'; |
---|
54 | t.is(res, dojox.date.posix.strftime(dt, fmt).substring(0, res.length)); |
---|
55 | |
---|
56 | fmt = '%C'; |
---|
57 | res = '20'; |
---|
58 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
59 | |
---|
60 | fmt = '%d'; |
---|
61 | res = '01'; |
---|
62 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
63 | |
---|
64 | fmt = '%D'; |
---|
65 | res = '01/01/06'; |
---|
66 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
67 | |
---|
68 | fmt = '%e'; |
---|
69 | res = ' 1'; |
---|
70 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
71 | |
---|
72 | fmt = '%h'; |
---|
73 | res = 'Jan'; |
---|
74 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
75 | |
---|
76 | fmt = '%H'; |
---|
77 | res = '18'; |
---|
78 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
79 | |
---|
80 | fmt = '%I'; |
---|
81 | res = '06'; |
---|
82 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
83 | |
---|
84 | fmt = '%j'; |
---|
85 | res = '001'; |
---|
86 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
87 | |
---|
88 | fmt = '%k'; |
---|
89 | res = '18'; |
---|
90 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
91 | |
---|
92 | fmt = '%l'; |
---|
93 | res = ' 6'; |
---|
94 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
95 | |
---|
96 | fmt = '%m'; |
---|
97 | res = '01'; |
---|
98 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
99 | |
---|
100 | fmt = '%M'; |
---|
101 | res = '23'; |
---|
102 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
103 | |
---|
104 | fmt = '%p'; |
---|
105 | res = 'PM'; |
---|
106 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
107 | |
---|
108 | fmt = '%r'; |
---|
109 | res = '06:23:00 PM'; |
---|
110 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
111 | |
---|
112 | fmt = '%R'; |
---|
113 | res = '18:23'; |
---|
114 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
115 | |
---|
116 | fmt = '%S'; |
---|
117 | res = '00'; |
---|
118 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
119 | |
---|
120 | fmt = '%T'; |
---|
121 | res = '18:23:00'; |
---|
122 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
123 | |
---|
124 | fmt = '%u'; |
---|
125 | res = '7'; |
---|
126 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
127 | |
---|
128 | fmt = '%w'; |
---|
129 | res = '0'; |
---|
130 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
131 | |
---|
132 | fmt = '%x'; |
---|
133 | res = 'Sunday, January 1, 2006'; |
---|
134 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en')); |
---|
135 | |
---|
136 | fmt = '%X'; |
---|
137 | res = '6:23:00 PM'; |
---|
138 | t.is(res, dojox.date.posix.strftime(dt, fmt, 'en').substring(0,res.length)); |
---|
139 | |
---|
140 | fmt = '%y'; |
---|
141 | res = '06'; |
---|
142 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
143 | |
---|
144 | fmt = '%Y'; |
---|
145 | res = '2006'; |
---|
146 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
147 | |
---|
148 | fmt = '%%'; |
---|
149 | res = '%'; |
---|
150 | t.is(res, dojox.date.posix.strftime(dt, fmt)); |
---|
151 | } |
---|
152 | }, |
---|
153 | { |
---|
154 | name: "getStartOfWeek", |
---|
155 | runTest: function(t){ |
---|
156 | var weekStart; |
---|
157 | |
---|
158 | // Monday |
---|
159 | var date = new Date(2007, 0, 1); |
---|
160 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 1), 1); |
---|
161 | t.is(date, weekStart); |
---|
162 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 2), 1); |
---|
163 | t.is(date, weekStart); |
---|
164 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 3), 1); |
---|
165 | t.is(date, weekStart); |
---|
166 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 4), 1); |
---|
167 | t.is(date, weekStart); |
---|
168 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 5), 1); |
---|
169 | t.is(date, weekStart); |
---|
170 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 6), 1); |
---|
171 | t.is(date, weekStart); |
---|
172 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 7), 1); |
---|
173 | t.is(date, weekStart); |
---|
174 | |
---|
175 | // Sunday |
---|
176 | date = new Date(2007, 0, 7); |
---|
177 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 7), 0); |
---|
178 | t.is(date, weekStart); |
---|
179 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 8), 0); |
---|
180 | t.is(date, weekStart); |
---|
181 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 9), 0); |
---|
182 | t.is(date, weekStart); |
---|
183 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 10), 0); |
---|
184 | t.is(date, weekStart); |
---|
185 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 11), 0); |
---|
186 | t.is(date, weekStart); |
---|
187 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 12), 0); |
---|
188 | t.is(date, weekStart); |
---|
189 | weekStart = dojox.date.posix.getStartOfWeek(new Date(2007, 0, 13), 0); |
---|
190 | t.is(date, weekStart); |
---|
191 | } |
---|
192 | }, |
---|
193 | { |
---|
194 | name: "setIsoWeekOfYear", |
---|
195 | runTest: function(t){ |
---|
196 | var date = new Date(2006,10,10); |
---|
197 | var result = dojox.date.posix.setIsoWeekOfYear(date, 1); |
---|
198 | t.is(new Date(2006,0,6), result); |
---|
199 | result = dojox.date.posix.setIsoWeekOfYear(date, 10); |
---|
200 | result = dojox.date.posix.setIsoWeekOfYear(date, 2); |
---|
201 | t.is(new Date(2006,0,13), result); |
---|
202 | result = dojox.date.posix.setIsoWeekOfYear(date, 10); |
---|
203 | t.is(new Date(2006,2,10), result); |
---|
204 | result = dojox.date.posix.setIsoWeekOfYear(date, 52); |
---|
205 | t.is(new Date(2006,11,29), result); |
---|
206 | var result = dojox.date.posix.setIsoWeekOfYear(date, -1); |
---|
207 | t.is(new Date(2006,11,29), result); |
---|
208 | var result = dojox.date.posix.setIsoWeekOfYear(date, -2); |
---|
209 | t.is(new Date(2006,11,22), result); |
---|
210 | var result = dojox.date.posix.setIsoWeekOfYear(date, -10); |
---|
211 | t.is(new Date(2006,9,27), result); |
---|
212 | |
---|
213 | date = new Date(2004,10,10); |
---|
214 | result = dojox.date.posix.setIsoWeekOfYear(date, 1); |
---|
215 | t.is(new Date(2003,11,31), result); |
---|
216 | result = dojox.date.posix.setIsoWeekOfYear(date, 2); |
---|
217 | t.is(new Date(2004,0,7), result); |
---|
218 | result = dojox.date.posix.setIsoWeekOfYear(date, -1); |
---|
219 | t.is(new Date(2004,11,29), result); |
---|
220 | } |
---|
221 | }, |
---|
222 | { |
---|
223 | name: "getIsoWeekOfYear", |
---|
224 | runTest: function(t){ |
---|
225 | var week = dojox.date.posix.getIsoWeekOfYear(new Date(2006,0,1)); |
---|
226 | t.is(52, week); |
---|
227 | week = dojox.date.posix.getIsoWeekOfYear(new Date(2006,0,4)); |
---|
228 | t.is(1, week); |
---|
229 | week = dojox.date.posix.getIsoWeekOfYear(new Date(2006,11,31)); |
---|
230 | t.is(52, week); |
---|
231 | week = dojox.date.posix.getIsoWeekOfYear(new Date(2007,0,1)); |
---|
232 | t.is(1, week); |
---|
233 | week = dojox.date.posix.getIsoWeekOfYear(new Date(2007,11,31)); |
---|
234 | t.is(53, week); |
---|
235 | week = dojox.date.posix.getIsoWeekOfYear(new Date(2008,0,1)); |
---|
236 | t.is(1, week); |
---|
237 | week = dojox.date.posix.getIsoWeekOfYear(new Date(2007,11,31)); |
---|
238 | t.is(53, week); |
---|
239 | } |
---|
240 | }, |
---|
241 | { |
---|
242 | name: "getIsoWeeksInYear", |
---|
243 | runTest: function(t){ |
---|
244 | // 44 long years in a 400 year cycle. |
---|
245 | var longYears = [4, 9, 15, 20, 26, 32, 37, 43, 48, 54, 60, 65, 71, 76, 82, |
---|
246 | 88, 93, 99, 105, 111, 116, 122, 128, 133, 139, 144, 150, 156, 161, 167, |
---|
247 | 172, 178, 184, 189, 195, 201, 207, 212, 218, 224, 229, 235, 240, 246, |
---|
248 | 252, 257, 263, 268, 274, 280, 285, 291, 296, 303, 308, 314, 320, 325, |
---|
249 | 331, 336, 342, 348, 353, 359, 364, 370, 376, 381, 387, 392, 398]; |
---|
250 | |
---|
251 | var i, j, weeks, result; |
---|
252 | for(i=0; i < 400; i++) { |
---|
253 | weeks = 52; |
---|
254 | if(i == longYears[0]) { weeks = 53; longYears.shift(); } |
---|
255 | result = dojox.date.posix.getIsoWeeksInYear(new Date(2000 + i, 0, 1)); |
---|
256 | t.is(/*weeks +" weeks in "+ (2000+i), */weeks, result); |
---|
257 | } |
---|
258 | } |
---|
259 | } |
---|
260 | ] |
---|
261 | ); |
---|