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