1 | dojo.provide("dojo.tests.date.locale"); |
---|
2 | |
---|
3 | dojo.require("dojo.date.locale"); |
---|
4 | |
---|
5 | tests.register("tests.date.locale", |
---|
6 | [ |
---|
7 | { |
---|
8 | // Test formatting and parsing of dates in various locales pre-built in dojo.cldr |
---|
9 | // NOTE: we can't set djConfig.extraLocale before bootstrapping unit tests, so directly |
---|
10 | // load resources here for specific locales: |
---|
11 | |
---|
12 | name: "date.locale", |
---|
13 | runTest: function(t){ |
---|
14 | var partLocaleList = ["en-us", "fr-fr", "es", "de-at", "ja-jp", "zh-cn"]; |
---|
15 | if(dojo.isAsync){ |
---|
16 | var def = new doh.Deferred(), |
---|
17 | deps = dojo.map(partLocaleList, function(locale){ |
---|
18 | return dojo.getL10nName("dojo/cldr", "gregorian", locale) |
---|
19 | }); |
---|
20 | require(deps, function(){ |
---|
21 | def.callback(true); |
---|
22 | }); |
---|
23 | return def; |
---|
24 | }else{ // tests for the v1.x loader/i18n machinery |
---|
25 | dojo.forEach(partLocaleList, function(locale){ |
---|
26 | dojo.requireLocalization("dojo.cldr", "gregorian", locale); |
---|
27 | }); |
---|
28 | } |
---|
29 | }, |
---|
30 | tearDown: function(){ |
---|
31 | //Clean up bundles that should not exist if |
---|
32 | //the test is re-run. |
---|
33 | //delete dojo.cldr.nls.gregorian; |
---|
34 | } |
---|
35 | }, |
---|
36 | { |
---|
37 | name: "isWeekend", |
---|
38 | runTest: function(t){ |
---|
39 | var thursday = new Date(2006, 8, 21); |
---|
40 | var friday = new Date(2006, 8, 22); |
---|
41 | var saturday = new Date(2006, 8, 23); |
---|
42 | var sunday = new Date(2006, 8, 24); |
---|
43 | var monday = new Date(2006, 8, 25); |
---|
44 | t.f(dojo.date.locale.isWeekend(thursday, 'en-us')); |
---|
45 | t.t(dojo.date.locale.isWeekend(saturday, 'en-us')); |
---|
46 | t.t(dojo.date.locale.isWeekend(sunday, 'en-us')); |
---|
47 | t.f(dojo.date.locale.isWeekend(monday, 'en-us')); |
---|
48 | // t.f(dojo.date.locale.isWeekend(saturday, 'en-in')); |
---|
49 | // t.t(dojo.date.locale.isWeekend(sunday, 'en-in')); |
---|
50 | // t.f(dojo.date.locale.isWeekend(monday, 'en-in')); |
---|
51 | // t.t(dojo.date.locale.isWeekend(friday, 'he-il')); |
---|
52 | // t.f(dojo.date.locale.isWeekend(sunday, 'he-il')); |
---|
53 | } |
---|
54 | }, |
---|
55 | { |
---|
56 | name: "format", |
---|
57 | runTest: function(t){ |
---|
58 | |
---|
59 | var date = new Date(2006, 7, 11, 0, 55, 12, 345); |
---|
60 | |
---|
61 | t.is("Friday, August 11, 2006", dojo.date.locale.format(date, {formatLength:'full',selector:'date', locale:'en-us'})); |
---|
62 | t.is("vendredi 11 ao\xFBt 2006", dojo.date.locale.format(date, {formatLength:'full',selector:'date', locale:'fr-fr'})); |
---|
63 | t.is("Freitag, 11. August 2006", dojo.date.locale.format(date, {formatLength:'full',selector:'date', locale:'de-at'})); |
---|
64 | t.is("2006\u5E748\u670811\u65E5\u91D1\u66DC\u65E5", dojo.date.locale.format(date, {formatLength:'full',selector:'date', locale:'ja-jp'})); |
---|
65 | |
---|
66 | t.is("8/11/06", dojo.date.locale.format(date, {formatLength:'short',selector:'date', locale:'en-us'})); |
---|
67 | t.is("11/08/06", dojo.date.locale.format(date, {formatLength:'short',selector:'date', locale:'fr-fr'})); |
---|
68 | t.is("11.08.06", dojo.date.locale.format(date, {formatLength:'short',selector:'date', locale:'de-at'})); |
---|
69 | t.is("06/08/11", dojo.date.locale.format(date, {formatLength:'short',selector:'date', locale:'ja-jp'})); |
---|
70 | |
---|
71 | t.is("6", dojo.date.locale.format(date, {datePattern:'E', selector:'date'})); |
---|
72 | |
---|
73 | t.is("12:55 AM", dojo.date.locale.format(date, {formatLength:'short',selector:'time', locale:'en-us'})); |
---|
74 | t.is("12:55:12", dojo.date.locale.format(date, {timePattern:'h:m:s',selector:'time'})); |
---|
75 | t.is("12:55:12.35", dojo.date.locale.format(date, {timePattern:'h:m:s.SS',selector:'time'})); |
---|
76 | t.is("24:55:12.35", dojo.date.locale.format(date, {timePattern:'k:m:s.SS',selector:'time'})); |
---|
77 | t.is("0:55:12.35", dojo.date.locale.format(date, {timePattern:'H:m:s.SS',selector:'time'})); |
---|
78 | t.is("0:55:12.35", dojo.date.locale.format(date, {timePattern:'K:m:s.SS',selector:'time'})); |
---|
79 | |
---|
80 | t.is("11082006", dojo.date.locale.format(date, {datePattern:"ddMMyyyy", selector:"date"})); |
---|
81 | |
---|
82 | t.is("12 o'clock AM", dojo.date.locale.format(date, {datePattern:"hh 'o''clock' a", selector:"date", locale: 'en'})); |
---|
83 | |
---|
84 | t.is("11/08/2006 12:55am", dojo.date.locale.format(date, {datePattern:"dd/MM/yyyy", timePattern:"hh:mma", locale: 'en', am:"am", pm:"pm"})); |
---|
85 | |
---|
86 | // compare without timezone |
---|
87 | t.is("\u4e0a\u534812\u65f655\u520612\u79d2", dojo.date.locale.format(date, {formatLength:'full',selector:'time', locale:'zh-cn'}).replace(/^.*(\u4e0a\u5348.*)/,"$1")); |
---|
88 | } |
---|
89 | }, |
---|
90 | { |
---|
91 | name: "parse_dates", |
---|
92 | runTest: function(t){ |
---|
93 | |
---|
94 | var aug_11_2006 = new Date(2006, 7, 11, 0); |
---|
95 | |
---|
96 | //en: 'short' fmt: M/d/yy |
---|
97 | // Tolerate either 8 or 08 for month part. |
---|
98 | t.is( aug_11_2006, dojo.date.locale.parse("08/11/06", {formatLength:'short', selector:'date', locale:'en'})); |
---|
99 | t.is( aug_11_2006, dojo.date.locale.parse("8/11/06", {formatLength:'short', selector:'date', locale:'en'})); |
---|
100 | // Tolerate yyyy input in yy part... |
---|
101 | t.is( aug_11_2006, dojo.date.locale.parse("8/11/2006", {formatLength:'short', selector:'date', locale:'en'})); |
---|
102 | // ...but not in strict mode |
---|
103 | t.f( Boolean(dojo.date.locale.parse("8/11/2006", {formatLength:'short', selector:'date', locale:'en', strict:true}))); |
---|
104 | |
---|
105 | // test dates with no spaces |
---|
106 | t.is( aug_11_2006, dojo.date.locale.parse("11Aug2006", {selector: 'date', datePattern: 'ddMMMyyyy', locale: 'en'})); |
---|
107 | t.is( new Date(2006, 7, 1), dojo.date.locale.parse("Aug2006", {selector: 'date', datePattern: 'MMMyyyy', locale: 'en'})); |
---|
108 | t.is( new Date(2010, 10, 19), dojo.date.locale.parse("111910", {fullyear: false, datePattern: "MMddyy", selector: "date"})); |
---|
109 | |
---|
110 | //en: 'medium' fmt: MMM d, yyyy |
---|
111 | // Tolerate either 8 or 08 for month part. |
---|
112 | t.is( aug_11_2006, dojo.date.locale.parse("Aug 11, 2006", {formatLength:'medium', selector:'date', locale:'en'})); |
---|
113 | t.is( aug_11_2006, dojo.date.locale.parse("Aug 11, 2006", {formatLength:'medium', selector:'date', locale:'en'})); |
---|
114 | // Tolerate abbreviating period in month part... |
---|
115 | t.is( aug_11_2006, dojo.date.locale.parse("Aug. 11, 2006", {formatLength:'medium', selector:'date', locale:'en'})); |
---|
116 | // ...but not in strict mode |
---|
117 | t.f( Boolean(dojo.date.locale.parse("Aug. 11, 2006", {formatLength:'medium', selector:'date', locale:'en', strict:true}))); |
---|
118 | |
---|
119 | // Note: 06 for year part will be translated literally as the year 6 C.E. |
---|
120 | var aug_11_06CE = new Date(2006, 7, 11, 0); |
---|
121 | aug_11_06CE.setFullYear(6); //literally the year 6 C.E. |
---|
122 | t.is( aug_11_06CE, dojo.date.locale.parse("Aug 11, 06", {selector:'date', datePattern:'MMM dd, yyyy', locale: 'en', strict:true})); |
---|
123 | |
---|
124 | //en: 'long' fmt: MMMM d, yyyy |
---|
125 | t.is( aug_11_2006, dojo.date.locale.parse("August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
126 | |
---|
127 | //en: 'full' fmt: EEEE, MMMM d, yyyy |
---|
128 | t.is( aug_11_2006, dojo.date.locale.parse("Friday, August 11, 2006", {formatLength:'full', selector:'date', locale:'en'})); |
---|
129 | //TODO: wrong day-of-week should fail |
---|
130 | //t.f( Boolean(dojo.date.locale.parse("Thursday, August 11, 2006", {formatLength:'full', selector:'date', locale:'en'}))); |
---|
131 | //TODO: Whitespace tolerance |
---|
132 | // t.is( aug_11_2006, dojo.date.locale.parse(" August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
133 | // t.is( aug_11_2006, dojo.date.locale.parse("August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
134 | // t.is( aug_11_2006, dojo.date.locale.parse("August 11 , 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
135 | // t.is( aug_11_2006, dojo.date.locale.parse("August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
136 | // t.is( aug_11_2006, dojo.date.locale.parse("August 11, 2006 ", {formatLength:'long', selector:'date', locale:'en'})); |
---|
137 | |
---|
138 | //Simple Validation Tests |
---|
139 | //catch "month" > 12 (note: month/day reversals are common when user expectation isn't met wrt european versus US formats) |
---|
140 | t.f( Boolean(dojo.date.locale.parse("15/1/2005", {formatLength:'short', selector:'date', locale:'en'}))); |
---|
141 | //day of month typo rolls over to the next month |
---|
142 | t.f( Boolean(dojo.date.locale.parse("Aug 32, 2006", {formatLength:'medium', selector:'date', locale:'en'}))); |
---|
143 | |
---|
144 | //German (de) |
---|
145 | t.is( aug_11_2006, dojo.date.locale.parse("11.08.06", {formatLength:'short', selector:'date', locale:'de'})); |
---|
146 | t.f( Boolean(dojo.date.locale.parse("11.8/06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
147 | t.f( Boolean(dojo.date.locale.parse("11.8x06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
148 | t.f( Boolean(dojo.date.locale.parse("11.13.06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
149 | t.f( Boolean(dojo.date.locale.parse("11.0.06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
150 | t.f( Boolean(dojo.date.locale.parse("32.08.06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
151 | |
---|
152 | //Spanish (es) |
---|
153 | //es: 'short' fmt: d/MM/yy |
---|
154 | t.is( aug_11_2006, dojo.date.locale.parse("11/08/06", {formatLength:'short', selector:'date', locale:'es'})); |
---|
155 | t.is( aug_11_2006, dojo.date.locale.parse("11/8/06", {formatLength:'short', selector:'date', locale:'es'})); |
---|
156 | // Tolerate yyyy input in yy part... |
---|
157 | t.is( aug_11_2006, dojo.date.locale.parse("11/8/2006", {formatLength:'short', selector:'date', locale:'es'})); |
---|
158 | // ...but not in strict mode |
---|
159 | t.f( Boolean(dojo.date.locale.parse("11/8/2006", {formatLength:'short', selector:'date', locale:'es', strict:true}))); |
---|
160 | //es: 'medium' fmt: dd-MMM-yy (not anymore as of CLDR 1.5.1) |
---|
161 | // t.is( aug_11_2006, dojo.date.locale.parse("11-ago-06", {formatLength:'medium', selector:'date', locale:'es'})); |
---|
162 | // t.is( aug_11_2006, dojo.date.locale.parse("11-ago-2006", {formatLength:'medium', selector:'date', locale:'es'})); |
---|
163 | // Tolerate abbreviating period in month part... |
---|
164 | // t.is( aug_11_2006, dojo.date.locale.parse("11-ago.-2006", {formatLength:'medium', selector:'date', locale:'es'})); |
---|
165 | // ...but not in strict mode |
---|
166 | // t.f( Boolean(dojo.date.locale.parse("11-ago.-2006", {formatLength:'medium', selector:'date', locale:'es', strict:true}))); |
---|
167 | //es: 'long' fmt: d' de 'MMMM' de 'yyyy |
---|
168 | t.is( aug_11_2006, dojo.date.locale.parse("11 de agosto de 2006", {formatLength:'long', selector:'date', locale:'es'})); |
---|
169 | //case-insensitive month... |
---|
170 | t.is( aug_11_2006, dojo.date.locale.parse("11 de Agosto de 2006", {formatLength:'long', selector:'date', locale:'es'})); |
---|
171 | //...but not in strict mode |
---|
172 | t.f( Boolean(dojo.date.locale.parse("11 de Agosto de 2006", {formatLength:'long', selector:'date', locale:'es', strict:true}))); |
---|
173 | //es 'full' fmt: EEEE d' de 'MMMM' de 'yyyy |
---|
174 | t.is( aug_11_2006, dojo.date.locale.parse("viernes 11 de agosto de 2006", {formatLength:'full', selector:'date', locale:'es'})); |
---|
175 | //case-insensitive day-of-week... |
---|
176 | t.is( aug_11_2006, dojo.date.locale.parse("Viernes 11 de agosto de 2006", {formatLength:'full', selector:'date', locale:'es'})); |
---|
177 | //...but not in strict mode |
---|
178 | t.f( Boolean(dojo.date.locale.parse("Viernes 11 de agosto de 2006", {formatLength:'full', selector:'date', locale:'es', strict:true}))); |
---|
179 | |
---|
180 | //Japanese (ja) |
---|
181 | //note: to avoid garbling from non-utf8-aware editors that may touch this file, using the \uNNNN format |
---|
182 | //for expressing double-byte chars. |
---|
183 | //toshi (year): \u5e74 |
---|
184 | //getsu (month): \u6708 |
---|
185 | //nichi (day): \u65e5 |
---|
186 | //kinyoubi (Friday): \u91d1\u66dc\u65e5 |
---|
187 | //zenkaku space: \u3000 |
---|
188 | |
---|
189 | //ja: 'short' fmt: yy/MM/dd (note: the "short" fmt isn't actually defined in the CLDR data...) |
---|
190 | t.is( aug_11_2006, dojo.date.locale.parse("06/08/11", {formatLength:'short', selector:'date', locale:'ja'})); |
---|
191 | t.is( aug_11_2006, dojo.date.locale.parse("06/8/11", {formatLength:'short', selector:'date', locale:'ja'})); |
---|
192 | // Tolerate yyyy input in yy part... |
---|
193 | t.is( aug_11_2006, dojo.date.locale.parse("2006/8/11", {formatLength:'short', selector:'date', locale:'ja'})); |
---|
194 | // ...but not in strict mode |
---|
195 | t.f( Boolean(dojo.date.locale.parse("2006/8/11", {formatLength:'short', selector:'date', locale:'ja', strict:true}))); |
---|
196 | //ja: 'medium' fmt: yyyy/MM/dd |
---|
197 | t.is( aug_11_2006, dojo.date.locale.parse("2006/08/11", {formatLength:'medium', selector:'date', locale:'ja'})); |
---|
198 | t.is( aug_11_2006, dojo.date.locale.parse("2006/8/11", {formatLength:'medium', selector:'date', locale:'ja'})); |
---|
199 | //ja: 'long' fmt: yyyy'\u5e74'\u6708'd'\u65e5' |
---|
200 | t.is( aug_11_2006, dojo.date.locale.parse("2006\u5e748\u670811\u65e5", {formatLength:'long', selector:'date', locale:'ja'})); |
---|
201 | //ja 'full' fmt: yyyy'\u5e74'M'\u6708'd'\u65e5'EEEE |
---|
202 | t.is( aug_11_2006, dojo.date.locale.parse("2006\u5e748\u670811\u65e5\u91d1\u66dc\u65e5", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
203 | |
---|
204 | //TODO: Whitespace tolerance |
---|
205 | //tolerate ascii space |
---|
206 | // t.is( aug_11_2006, dojo.date.locale.parse(" 2006\u5e748\u670811\u65e5\u91d1\u66dc\u65e5 ", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
207 | // t.is( aug_11_2006, dojo.date.locale.parse("2006\u5e74 8\u670811\u65e5 \u91d1\u66dc\u65e5", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
208 | //tolerate zenkaku space |
---|
209 | // t.is( aug_11_2006, dojo.date.locale.parse("\u30002006\u5e748\u670811\u65e5\u91d1\u66dc\u65e5\u3000", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
210 | // t.is( aug_11_2006, dojo.date.locale.parse("2006\u5e74\u30008\u670811\u65e5\u3000\u91d1\u66dc\u65e5", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
211 | |
---|
212 | var apr_11_2006 = new Date(2006, 3, 11, 0); |
---|
213 | //Roundtrip |
---|
214 | var options={formatLength:'medium',selector:'date', locale:'fr-fr'}; |
---|
215 | t.is(0, dojo.date.compare(apr_11_2006, dojo.date.locale.parse(dojo.date.locale.format(apr_11_2006, options), options))); |
---|
216 | |
---|
217 | //Tolerance for abbreviations |
---|
218 | t.is(0, dojo.date.compare(apr_11_2006, dojo.date.locale.parse("11 avr 06", options))); |
---|
219 | } |
---|
220 | }, |
---|
221 | { |
---|
222 | name: "parse_dates_neg", |
---|
223 | runTest: function(t){ |
---|
224 | t.f(Boolean(dojo.date.locale.parse("2/29/2007", {formatLength: 'short', selector: 'date', locale: 'en'}))); |
---|
225 | t.f(Boolean(dojo.date.locale.parse("4/31/2007", {formatLength: 'short', selector: 'date', locale: 'en'}))); |
---|
226 | t.f(Boolean(dojo.date.locale.parse("Decemb 30, 2007", {formatLength: 'long', selector: 'date', locale: 'en'}))); |
---|
227 | } |
---|
228 | }, |
---|
229 | { |
---|
230 | name: "parse_datetimes", |
---|
231 | runTest: function(t){ |
---|
232 | |
---|
233 | var aug_11_2006_12_30_am = new Date(2006, 7, 11, 0, 30); |
---|
234 | var aug_11_2006_12_30_pm = new Date(2006, 7, 11, 12, 30); |
---|
235 | |
---|
236 | //en: 'short' datetime fmt: M/d/yy h:mm a |
---|
237 | //note: this is concatenation of dateFormat-short and timeFormat-short, |
---|
238 | //cldr provisionally defines datetime fmts as well, but we're not using them at the moment |
---|
239 | t.is( aug_11_2006_12_30_pm, dojo.date.locale.parse("08/11/06 12:30 PM", {formatLength:'short', locale:'en'})); |
---|
240 | //case-insensitive |
---|
241 | t.is( aug_11_2006_12_30_pm, dojo.date.locale.parse("08/11/06 12:30 pm", {formatLength:'short', locale:'en'})); |
---|
242 | //...but not in strict mode |
---|
243 | t.f( Boolean(dojo.date.locale.parse("08/11/06 12:30 pm", {formatLength:'short', locale:'en', strict:true}))); |
---|
244 | |
---|
245 | t.is( aug_11_2006_12_30_am, dojo.date.locale.parse("08/11/06 12:30 AM", {formatLength:'short', locale:'en'})); |
---|
246 | |
---|
247 | t.is( new Date(2006, 7, 11), dojo.date.locale.parse("11082006", {datePattern:"ddMMyyyy", selector:"date"})); |
---|
248 | |
---|
249 | t.is( new Date(2006, 7, 31), dojo.date.locale.parse("31Aug2006", {datePattern:"ddMMMyyyy", selector:"date", locale:'en'})); |
---|
250 | |
---|
251 | t.is(new Date(1970,0,7), dojo.date.locale.parse("007", {datePattern:'DDD',selector:'date'})); |
---|
252 | t.is(new Date(1970,0,31), dojo.date.locale.parse("031", {datePattern:'DDD',selector:'date'})); |
---|
253 | t.is(new Date(1970,3,10), dojo.date.locale.parse("100", {datePattern:'DDD',selector:'date'})); |
---|
254 | |
---|
255 | } |
---|
256 | }, |
---|
257 | { |
---|
258 | name: "parse_times", |
---|
259 | runTest: function(t){ |
---|
260 | var time = new Date(2006, 7, 11, 12, 30); |
---|
261 | var tformat = {selector:'time', strict:true, timePattern:"h:mm a", locale:'en'}; |
---|
262 | |
---|
263 | t.is(time.getHours(), dojo.date.locale.parse("12:30 PM", tformat).getHours()); |
---|
264 | t.is(time.getMinutes(), dojo.date.locale.parse("12:30 PM", tformat).getMinutes()); |
---|
265 | } |
---|
266 | }, |
---|
267 | { |
---|
268 | name: "format_patterns", |
---|
269 | runTest: function(t){ |
---|
270 | var time = new Date(2006, 7, 11, 12, 30); |
---|
271 | var tformat = {selector:'time', strict:true, timePattern:"h 'o''clock'", locale:'en'}; |
---|
272 | t.is(time.getHours(), dojo.date.locale.parse("12 o'clock", tformat).getHours()); |
---|
273 | |
---|
274 | tformat = {selector:'time', strict:true, timePattern:" 'Hour is' h", locale:'en'}; |
---|
275 | t.is(time.getHours(), dojo.date.locale.parse(" Hour is 12", tformat).getHours()); |
---|
276 | |
---|
277 | tformat = {selector:'time', strict:true, timePattern:"'Hour is' h", locale:'en'}; |
---|
278 | t.is(time.getHours(), dojo.date.locale.parse("Hour is 12", tformat).getHours()); |
---|
279 | } |
---|
280 | }, |
---|
281 | { |
---|
282 | name: "parse_patterns", |
---|
283 | runTest: function(t){ |
---|
284 | var time = new Date(2006, 7, 11, 12, 30); |
---|
285 | var tformat = {selector:'time', strict:true, timePattern:"h 'o''clock'", locale:'en'}; |
---|
286 | t.is(time.getHours(), dojo.date.locale.parse("12 o'clock", tformat).getHours()); |
---|
287 | |
---|
288 | tformat = {selector:'time', strict:true, timePattern:" 'Hour is' h", locale:'en'}; |
---|
289 | t.is(time.getHours(), dojo.date.locale.parse(" Hour is 12", tformat).getHours()); |
---|
290 | tformat = {selector:'time', strict:true, timePattern:"'Hour is' h", locale:'en'}; |
---|
291 | t.is(time.getHours(), dojo.date.locale.parse("Hour is 12", tformat).getHours()); |
---|
292 | } |
---|
293 | }, |
---|
294 | { |
---|
295 | name: "day_of_year", |
---|
296 | runTest: function(t){ |
---|
297 | |
---|
298 | // t.is(23, dojo.date.setDayOfYear(new Date(2006,0,1), 23).getDate()); |
---|
299 | t.is(1, dojo.date.locale._getDayOfYear(new Date(2006,0,1))); |
---|
300 | t.is(32, dojo.date.locale._getDayOfYear(new Date(2006,1,1))); |
---|
301 | t.is(72, dojo.date.locale._getDayOfYear(new Date(2007,2,13,0,13))); |
---|
302 | t.is(72, dojo.date.locale._getDayOfYear(new Date(2007,2,13,1,13))); |
---|
303 | } |
---|
304 | }, |
---|
305 | { |
---|
306 | name: "week_of_year", |
---|
307 | runTest: function(t){ |
---|
308 | t.is(0, dojo.date.locale._getWeekOfYear(new Date(2000,0,1))); |
---|
309 | t.is(1, dojo.date.locale._getWeekOfYear(new Date(2000,0,2))); |
---|
310 | t.is(0, dojo.date.locale._getWeekOfYear(new Date(2000,0,2), 1)); |
---|
311 | t.is(0, dojo.date.locale._getWeekOfYear(new Date(2007,0,1))); |
---|
312 | t.is(1, dojo.date.locale._getWeekOfYear(new Date(2007,0,1), 1)); |
---|
313 | t.is(27, dojo.date.locale._getWeekOfYear(new Date(2007,6,14))); |
---|
314 | t.is(28, dojo.date.locale._getWeekOfYear(new Date(2007,6,14), 1)); |
---|
315 | } |
---|
316 | } |
---|
317 | ] |
---|
318 | ); |
---|
319 | |
---|
320 | /* |
---|
321 | // workaround deprecated methods. Should decide whether we should convert the tests or add a helper method (in dojo.date?) to do this. |
---|
322 | |
---|
323 | dojo_validate_isValidTime = function(str, props){ |
---|
324 | props = props || {}; |
---|
325 | if(!props.format){props.format="h:mm:ss";} |
---|
326 | if(!props.am){props.am="a.m.";} |
---|
327 | if(!props.pm){props.pm="p.m.";} |
---|
328 | var result = false; |
---|
329 | if(/[hk]/.test(props.format) && props.format.indexOf('a') == -1){ |
---|
330 | result = dojo.date.locale.parse(str, {selector: 'time', timePattern: props.format + " a"}); |
---|
331 | } |
---|
332 | return Boolean(result || dojo.date.locale.parse(str, {selector: 'time', timePattern: props.format})); |
---|
333 | } |
---|
334 | |
---|
335 | dojo_validate_is12HourTime = function(str){ |
---|
336 | return dojo_validate_isValidTime(str, {format: 'h:mm:ss'}) || dojo_validate_isValidTime(str, {format: 'h:mm'}); |
---|
337 | } |
---|
338 | |
---|
339 | dojo_validate_is24HourTime = function(str){ |
---|
340 | return dojo_validate_isValidTime(str, {format: 'H:mm:ss'}) || dojo_validate_isValidTime(str, {format: 'H:mm'}); |
---|
341 | } |
---|
342 | |
---|
343 | dojo_validate_isValidDate = function(str, fmt){ |
---|
344 | return Boolean(dojo.date.locale.parse(str, {selector: 'date', datePattern: fmt})); |
---|
345 | } |
---|
346 | |
---|
347 | function test_validate_datetime_isValidTime(){ |
---|
348 | jum.assertTrue("test1", dojo_validate_isValidTime('5:15:05 pm')); |
---|
349 | // FAILURE jum.assertTrue("test2", dojo_validate_isValidTime('5:15:05 p.m.', {pm: "P.M."} )); |
---|
350 | jum.assertFalse("test3", dojo_validate_isValidTime('5:15:05 f.m.')); |
---|
351 | jum.assertTrue("test4", dojo_validate_isValidTime('5:15 pm', {format: "h:mm a"} ) ); |
---|
352 | jum.assertFalse("test5", dojo_validate_isValidTime('5:15 fm', {}) ); |
---|
353 | jum.assertTrue("test6", dojo_validate_isValidTime('15:15:00', {format: "H:mm:ss"} ) ); |
---|
354 | // FAILURE jum.assertFalse("test7", dojo_validate_isValidTime('15:15:00', {}) ); |
---|
355 | jum.assertTrue("test8", dojo_validate_isValidTime('17:01:30', {format: "H:mm:ss"} ) ); |
---|
356 | jum.assertFalse("test9", dojo_validate_isValidTime('17:1:30', {format: "H:mm:ss"} ) ); |
---|
357 | // FAILURE jum.assertFalse("test10", dojo_validate_isValidTime('17:01:30', {format: "H:m:ss"} ) ); |
---|
358 | // Greek |
---|
359 | // FAILURE jum.assertTrue("test11", dojo_validate_isValidTime('5:01:30 \u0924\u0924', {am: "\u0928\u0924", pm: "\u0924\u0924"} ) ); |
---|
360 | // Italian |
---|
361 | jum.assertTrue("test12", dojo_validate_isValidTime('17.01.30', {format: "H.mm.ss"} ) ); |
---|
362 | // Mexico |
---|
363 | // FAILURE jum.assertTrue("test13", dojo_validate_isValidTime('05:01:30 p.m.', {format: "hh:mm:ss a", am: "a.m.", pm: "p.m."} ) ); |
---|
364 | } |
---|
365 | |
---|
366 | |
---|
367 | function test_validate_datetime_is12HourTime(){ |
---|
368 | jum.assertTrue("test1", dojo_validate_is12HourTime('5:15:05 pm')); |
---|
369 | // FAILURE jum.assertFalse("test2", dojo_validate_is12HourTime('05:15:05 pm')); |
---|
370 | jum.assertFalse("test3", dojo_validate_is12HourTime('5:5:05 pm')); |
---|
371 | jum.assertFalse("test4", dojo_validate_is12HourTime('5:15:5 pm')); |
---|
372 | // FAILURE jum.assertFalse("test5", dojo_validate_is12HourTime('13:15:05 pm')); |
---|
373 | jum.assertFalse("test6", dojo_validate_is12HourTime('5:60:05 pm')); |
---|
374 | jum.assertFalse("test7", dojo_validate_is12HourTime('5:15:60 pm')); |
---|
375 | jum.assertTrue("test8", dojo_validate_is12HourTime('5:59:05 pm')); |
---|
376 | jum.assertTrue("test9", dojo_validate_is12HourTime('5:15:59 pm')); |
---|
377 | // FAILURE jum.assertFalse("test10", dojo_validate_is12HourTime('5:15:05')); |
---|
378 | |
---|
379 | // optional seconds |
---|
380 | jum.assertTrue("test11", dojo_validate_is12HourTime('5:15 pm')); |
---|
381 | jum.assertFalse("test12", dojo_validate_is12HourTime('5:15: pm')); |
---|
382 | } |
---|
383 | |
---|
384 | function test_validate_datetime_is24HourTime(){ |
---|
385 | jum.assertTrue("test1", dojo_validate_is24HourTime('00:03:59')); |
---|
386 | jum.assertTrue("test2", dojo_validate_is24HourTime('22:03:59')); |
---|
387 | //FIXME: fix tests or code? |
---|
388 | // jum.assertFalse("test3", dojo_validate_is24HourTime('22:03:59 pm')); |
---|
389 | // jum.assertFalse("test4", dojo_validate_is24HourTime('2:03:59')); |
---|
390 | jum.assertFalse("test5", dojo_validate_is24HourTime('0:3:59')); |
---|
391 | jum.assertFalse("test6", dojo_validate_is24HourTime('00:03:5')); |
---|
392 | jum.assertFalse("test7", dojo_validate_isValidTime('24:03:59', {format: 'kk:mm:ss'})); |
---|
393 | jum.assertFalse("test8", dojo_validate_is24HourTime('02:60:59')); |
---|
394 | jum.assertFalse("test9", dojo_validate_is24HourTime('02:03:60')); |
---|
395 | |
---|
396 | // optional seconds |
---|
397 | jum.assertTrue("test10", dojo_validate_is24HourTime('22:53')); |
---|
398 | jum.assertFalse("test11", dojo_validate_is24HourTime('22:53:')); |
---|
399 | } |
---|
400 | |
---|
401 | function test_validate_datetime_isValidDate(){ |
---|
402 | |
---|
403 | // Month date year |
---|
404 | jum.assertTrue("test1", dojo_validate_isValidDate("08/06/2005", "MM/dd/yyyy")); |
---|
405 | jum.assertTrue("test2", dojo_validate_isValidDate("08.06.2005", "MM.dd.yyyy")); |
---|
406 | jum.assertTrue("test3", dojo_validate_isValidDate("08-06-2005", "MM-dd-yyyy")); |
---|
407 | jum.assertTrue("test4", dojo_validate_isValidDate("8/6/2005", "M/d/yyyy")); |
---|
408 | jum.assertTrue("test5", dojo_validate_isValidDate("8/6", "M/d")); |
---|
409 | jum.assertFalse("test6", dojo_validate_isValidDate("09/31/2005", "MM/dd/yyyy")); |
---|
410 | jum.assertFalse("test7", dojo_validate_isValidDate("02/29/2005", "MM/dd/yyyy")); |
---|
411 | jum.assertTrue("test8", dojo_validate_isValidDate("02/29/2004", "MM/dd/yyyy")); |
---|
412 | |
---|
413 | // year month date |
---|
414 | jum.assertTrue("test9", dojo_validate_isValidDate("2005-08-06", "yyyy-MM-dd")); |
---|
415 | jum.assertTrue("test10", dojo_validate_isValidDate("20050806", "yyyyMMdd")); |
---|
416 | |
---|
417 | // year month |
---|
418 | jum.assertTrue("test11", dojo_validate_isValidDate("2005-08", "yyyy-MM")); |
---|
419 | jum.assertTrue("test12", dojo_validate_isValidDate("200508", "yyyyMM")); |
---|
420 | |
---|
421 | // year |
---|
422 | jum.assertTrue("test13", dojo_validate_isValidDate("2005", "yyyy")); |
---|
423 | |
---|
424 | // year week day |
---|
425 | //TODO: need to support 'w'? |
---|
426 | // jum.assertTrue("test14", dojo_validate_isValidDate("2005-W42-3", "yyyy-'W'ww-d")); |
---|
427 | // jum.assertTrue("test15", dojo_validate_isValidDate("2005W423", "yyyy'W'wwd")); |
---|
428 | // jum.assertFalse("test16", dojo_validate_isValidDate("2005-W42-8", "yyyy-'W'ww-d")); |
---|
429 | // jum.assertFalse("test17", dojo_validate_isValidDate("2005-W54-3", "yyyy-'W'ww-d")); |
---|
430 | |
---|
431 | // year week |
---|
432 | // jum.assertTrue("test18", dojo_validate_isValidDate("2005-W42", "yyyy-'W'ww")); |
---|
433 | // jum.assertTrue("test19", dojo_validate_isValidDate("2005W42", "yyyy'W'ww")); |
---|
434 | |
---|
435 | // year ordinal-day |
---|
436 | jum.assertTrue("test20", dojo_validate_isValidDate("2005-292", "yyyy-DDD")); |
---|
437 | jum.assertTrue("test21", dojo_validate_isValidDate("2005292", "yyyyDDD")); |
---|
438 | jum.assertFalse("test22", dojo_validate_isValidDate("2005-366", "yyyy-DDD")); |
---|
439 | jum.assertTrue("test23", dojo_validate_isValidDate("2004-366", "yyyy-DDD")); |
---|
440 | |
---|
441 | // date month year |
---|
442 | jum.assertTrue("test24", dojo_validate_isValidDate("19.10.2005", "dd.MM.yyyy")); |
---|
443 | jum.assertTrue("test25", dojo_validate_isValidDate("19-10-2005", "d-M-yyyy")); |
---|
444 | } |
---|
445 | */ |
---|