root / trunk / web / dojo / dojox / date / islamic / locale.js @ 12
History | View | Annotate | Download (7.21 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.date.islamic.locale"]){ |
||
9 | dojo._hasResource["dojox.date.islamic.locale"]=true; |
||
10 | dojo.provide("dojox.date.islamic.locale");
|
||
11 | dojo.require("dojox.date.islamic.Date");
|
||
12 | dojo.require("dojo.regexp");
|
||
13 | dojo.require("dojo.string");
|
||
14 | dojo.require("dojo.i18n");
|
||
15 | dojo.require("dojo.date");
|
||
16 | dojo.requireLocalization("dojo.cldr","islamic",null,"ROOT,ar,he"); |
||
17 | (function(){
|
||
18 | function _1(_2,_3,_4,_5,_6){ |
||
19 | return _6.replace(/([a-z])\1*/ig,function(_7){ |
||
20 | var s,_8;
|
||
21 | var c=_7.charAt(0); |
||
22 | var l=_7.length;
|
||
23 | var _9=["abbr","wide","narrow"]; |
||
24 | switch(c){
|
||
25 | case "G": |
||
26 | s=_3["eraAbbr"][0]; |
||
27 | break;
|
||
28 | case "y": |
||
29 | s=String(_2.getFullYear()); |
||
30 | break;
|
||
31 | case "M": |
||
32 | var m=_2.getMonth();
|
||
33 | if(l<3){ |
||
34 | s=m+1;
|
||
35 | _8=true;
|
||
36 | }else{
|
||
37 | var _a=["months","format",_9[l-3]].join("-"); |
||
38 | s=_3[_a][m]; |
||
39 | } |
||
40 | break;
|
||
41 | case "d": |
||
42 | s=_2.getDate(true);
|
||
43 | _8=true;
|
||
44 | break;
|
||
45 | case "E": |
||
46 | var d=_2.getDay();
|
||
47 | if(l<3){ |
||
48 | s=d+1;
|
||
49 | _8=true;
|
||
50 | }else{
|
||
51 | var _b=["days","format",_9[l-3]].join("-"); |
||
52 | s=_3[_b][d]; |
||
53 | } |
||
54 | break;
|
||
55 | case "a": |
||
56 | var _c=(_2.getHours()<12)?"am":"pm"; |
||
57 | s=_3["dayPeriods-format-wide-"+_c];
|
||
58 | break;
|
||
59 | case "h": |
||
60 | case "H": |
||
61 | case "K": |
||
62 | case "k": |
||
63 | var h=_2.getHours();
|
||
64 | switch(c){
|
||
65 | case "h": |
||
66 | s=(h%12)||12; |
||
67 | break;
|
||
68 | case "H": |
||
69 | s=h; |
||
70 | break;
|
||
71 | case "K": |
||
72 | s=(h%12);
|
||
73 | break;
|
||
74 | case "k": |
||
75 | s=h||24;
|
||
76 | break;
|
||
77 | } |
||
78 | _8=true;
|
||
79 | break;
|
||
80 | case "m": |
||
81 | s=_2.getMinutes(); |
||
82 | _8=true;
|
||
83 | break;
|
||
84 | case "s": |
||
85 | s=_2.getSeconds(); |
||
86 | _8=true;
|
||
87 | break;
|
||
88 | case "S": |
||
89 | s=Math.round(_2.getMilliseconds()*Math.pow(10,l-3)); |
||
90 | _8=true;
|
||
91 | break;
|
||
92 | case "z": |
||
93 | s=dojo.date.getTimezoneName(_2.toGregorian()); |
||
94 | if(s){
|
||
95 | break;
|
||
96 | } |
||
97 | l=4;
|
||
98 | case "Z": |
||
99 | var _d=_2.toGregorian().getTimezoneOffset();
|
||
100 | var tz=[(_d<=0?"+":"-"),dojo.string.pad(Math.floor(Math.abs(_d)/60),2),dojo.string.pad(Math.abs(_d)%60,2)]; |
||
101 | if(l==4){ |
||
102 | tz.splice(0,0,"GMT"); |
||
103 | tz.splice(3,0,":"); |
||
104 | } |
||
105 | s=tz.join("");
|
||
106 | break;
|
||
107 | default:
|
||
108 | throw new Error("dojox.date.islamic.locale.formatPattern: invalid pattern char: "+_6); |
||
109 | } |
||
110 | if(_8){
|
||
111 | s=dojo.string.pad(s,l); |
||
112 | } |
||
113 | return s;
|
||
114 | }); |
||
115 | }; |
||
116 | dojox.date.islamic.locale.format=function(_e,_f){ |
||
117 | _f=_f||{}; |
||
118 | var _10=dojo.i18n.normalizeLocale(_f.locale);
|
||
119 | var _11=_f.formatLength||"short"; |
||
120 | var _12=dojox.date.islamic.locale._getIslamicBundle(_10);
|
||
121 | var str=[];
|
||
122 | var _13=dojo.hitch(this,_1,_e,_12,_10,_f.fullYear); |
||
123 | if(_f.selector=="year"){ |
||
124 | var _14=_e.getFullYear();
|
||
125 | return _14;
|
||
126 | } |
||
127 | if(_f.selector!="time"){ |
||
128 | var _15=_f.datePattern||_12["dateFormat-"+_11]; |
||
129 | if(_15){
|
||
130 | str.push(_16(_15,_13)); |
||
131 | } |
||
132 | } |
||
133 | if(_f.selector!="date"){ |
||
134 | var _17=_f.timePattern||_12["timeFormat-"+_11]; |
||
135 | if(_17){
|
||
136 | str.push(_16(_17,_13)); |
||
137 | } |
||
138 | } |
||
139 | var _18=str.join(" "); |
||
140 | return _18;
|
||
141 | }; |
||
142 | dojox.date.islamic.locale.regexp=function(_19){ |
||
143 | return dojox.date.islamic.locale._parseInfo(_19).regexp;
|
||
144 | }; |
||
145 | dojox.date.islamic.locale._parseInfo=function(_1a){ |
||
146 | _1a=_1a||{}; |
||
147 | var _1b=dojo.i18n.normalizeLocale(_1a.locale);
|
||
148 | var _1c=dojox.date.islamic.locale._getIslamicBundle(_1b);
|
||
149 | var _1d=_1a.formatLength||"short"; |
||
150 | var _1e=_1a.datePattern||_1c["dateFormat-"+_1d]; |
||
151 | var _1f=_1a.timePattern||_1c["timeFormat-"+_1d]; |
||
152 | var _20;
|
||
153 | if(_1a.selector=="date"){ |
||
154 | _20=_1e; |
||
155 | }else{
|
||
156 | if(_1a.selector=="time"){ |
||
157 | _20=_1f; |
||
158 | }else{
|
||
159 | _20=(typeof (_1f)=="undefined")?_1e:_1e+" "+_1f; |
||
160 | } |
||
161 | } |
||
162 | var _21=[];
|
||
163 | var re=_16(_20,dojo.hitch(this,_22,_21,_1c,_1a)); |
||
164 | return {regexp:re,tokens:_21,bundle:_1c}; |
||
165 | }; |
||
166 | dojox.date.islamic.locale.parse=function(_23,_24){ |
||
167 | _23=_23.replace(/[\u200E\u200F\u202A\u202E]/g,""); |
||
168 | if(!_24){
|
||
169 | _24={}; |
||
170 | } |
||
171 | var _25=dojox.date.islamic.locale._parseInfo(_24);
|
||
172 | var _26=_25.tokens,_27=_25.bundle;
|
||
173 | var _28=_25.regexp.replace(/[\u200E\u200F\u202A\u202E]/g,""); |
||
174 | var re=new RegExp("^"+_28+"$"); |
||
175 | var _29=re.exec(_23);
|
||
176 | var _2a=dojo.i18n.normalizeLocale(_24.locale);
|
||
177 | if(!_29){
|
||
178 | return null; |
||
179 | } |
||
180 | var _2b,_2c;
|
||
181 | var _2d=[1389,0,1,0,0,0,0]; |
||
182 | var _2e=""; |
||
183 | var _2f=0; |
||
184 | var _30=["abbr","wide","narrow"]; |
||
185 | var _31=dojo.every(_29,function(v,i){ |
||
186 | if(!i){
|
||
187 | return true; |
||
188 | } |
||
189 | var _32=_26[i-1]; |
||
190 | var l=_32.length;
|
||
191 | switch(_32.charAt(0)){ |
||
192 | case "y": |
||
193 | _2d[0]=Number(v);
|
||
194 | break;
|
||
195 | case "M": |
||
196 | if(l>2){ |
||
197 | var _33=_27["months-format-"+_30[l-3]].concat(); |
||
198 | if(!_24.strict){
|
||
199 | v=v.replace(".","").toLowerCase(); |
||
200 | _33=dojo.map(_33,function(s){
|
||
201 | return s?s.replace(".","").toLowerCase():s; |
||
202 | }); |
||
203 | } |
||
204 | v=dojo.indexOf(_33,v); |
||
205 | if(v==-1){ |
||
206 | return false; |
||
207 | } |
||
208 | _2f=l; |
||
209 | }else{
|
||
210 | v--; |
||
211 | } |
||
212 | _2d[1]=Number(v);
|
||
213 | break;
|
||
214 | case "D": |
||
215 | _2d[1]=0; |
||
216 | case "d": |
||
217 | _2d[2]=Number(v);
|
||
218 | break;
|
||
219 | case "a": |
||
220 | var am=_24.am||_27["dayPeriods-format-wide-am"],pm=_24.pm||_27["dayPeriods-format-wide-pm"]; |
||
221 | if(!_24.strict){
|
||
222 | var _34=/\./g; |
||
223 | v=v.replace(_34,"").toLowerCase();
|
||
224 | am=am.replace(_34,"").toLowerCase();
|
||
225 | pm=pm.replace(_34,"").toLowerCase();
|
||
226 | } |
||
227 | if(_24.strict&&v!=am&&v!=pm){
|
||
228 | return false; |
||
229 | } |
||
230 | _2e=(v==pm)?"p":(v==am)?"a":""; |
||
231 | break;
|
||
232 | case "K": |
||
233 | if(v==24){ |
||
234 | v=0;
|
||
235 | } |
||
236 | case "h": |
||
237 | case "H": |
||
238 | case "k": |
||
239 | _2d[3]=Number(v);
|
||
240 | break;
|
||
241 | case "m": |
||
242 | _2d[4]=Number(v);
|
||
243 | break;
|
||
244 | case "s": |
||
245 | _2d[5]=Number(v);
|
||
246 | break;
|
||
247 | case "S": |
||
248 | _2d[6]=Number(v);
|
||
249 | } |
||
250 | return true; |
||
251 | }); |
||
252 | var _35=+_2d[3]; |
||
253 | if(_2e==="p"&&_35<12){ |
||
254 | _2d[3]=_35+12; |
||
255 | }else{
|
||
256 | if(_2e==="a"&&_35==12){ |
||
257 | _2d[3]=0; |
||
258 | } |
||
259 | } |
||
260 | var _36=new dojox.date.islamic.Date(_2d[0],_2d[1],_2d[2],_2d[3],_2d[4],_2d[5],_2d[6]); |
||
261 | return _36;
|
||
262 | }; |
||
263 | function _16(_37,_38,_39,_3a){ |
||
264 | var _3b=function(x){ |
||
265 | return x;
|
||
266 | }; |
||
267 | _38=_38||_3b; |
||
268 | _39=_39||_3b; |
||
269 | _3a=_3a||_3b; |
||
270 | var _3c=_37.match(/(''|[^'])+/g); |
||
271 | var _3d=_37.charAt(0)=="'"; |
||
272 | dojo.forEach(_3c,function(_3e,i){
|
||
273 | if(!_3e){
|
||
274 | _3c[i]="";
|
||
275 | }else{
|
||
276 | _3c[i]=(_3d?_39:_38)(_3e); |
||
277 | _3d=!_3d; |
||
278 | } |
||
279 | }); |
||
280 | return _3a(_3c.join("")); |
||
281 | }; |
||
282 | function _22(_3f,_40,_41,_42){ |
||
283 | _42=dojo.regexp.escapeString(_42); |
||
284 | var _43=dojo.i18n.normalizeLocale(_41.locale);
|
||
285 | return _42.replace(/([a-z])\1*/ig,function(_44){ |
||
286 | var s;
|
||
287 | var c=_44.charAt(0); |
||
288 | var l=_44.length;
|
||
289 | var p2="",p3=""; |
||
290 | if(_41.strict){
|
||
291 | if(l>1){ |
||
292 | p2="0"+"{"+(l-1)+"}"; |
||
293 | } |
||
294 | if(l>2){ |
||
295 | p3="0"+"{"+(l-2)+"}"; |
||
296 | } |
||
297 | }else{
|
||
298 | p2="0?";
|
||
299 | p3="0{0,2}";
|
||
300 | } |
||
301 | switch(c){
|
||
302 | case "y": |
||
303 | s="\\d+";
|
||
304 | break;
|
||
305 | case "M": |
||
306 | s=(l>2)?"\\S+ ?\\S+":p2+"[1-9]|1[0-2]"; |
||
307 | break;
|
||
308 | case "d": |
||
309 | s="[12]\\d|"+p2+"[1-9]|3[01]"; |
||
310 | break;
|
||
311 | case "E": |
||
312 | s="\\S+";
|
||
313 | break;
|
||
314 | case "h": |
||
315 | s=p2+"[1-9]|1[0-2]";
|
||
316 | break;
|
||
317 | case "k": |
||
318 | s=p2+"\\d|1[01]";
|
||
319 | break;
|
||
320 | case "H": |
||
321 | s=p2+"\\d|1\\d|2[0-3]";
|
||
322 | break;
|
||
323 | case "K": |
||
324 | s=p2+"[1-9]|1\\d|2[0-4]";
|
||
325 | break;
|
||
326 | case "m": |
||
327 | case "s": |
||
328 | s=p2+"\\d|[0-5]\\d";
|
||
329 | break;
|
||
330 | case "S": |
||
331 | s="\\d{"+l+"}"; |
||
332 | break;
|
||
333 | case "a": |
||
334 | var am=_41.am||_40["dayPeriods-format-wide-am"],pm=_41.pm||_40["dayPeriods-format-wide-pm"]; |
||
335 | if(_41.strict){
|
||
336 | s=am+"|"+pm;
|
||
337 | }else{
|
||
338 | s=am+"|"+pm;
|
||
339 | if(am!=am.toLowerCase()){
|
||
340 | s+="|"+am.toLowerCase();
|
||
341 | } |
||
342 | if(pm!=pm.toLowerCase()){
|
||
343 | s+="|"+pm.toLowerCase();
|
||
344 | } |
||
345 | } |
||
346 | break;
|
||
347 | default:
|
||
348 | s=".*";
|
||
349 | } |
||
350 | if(_3f){
|
||
351 | _3f.push(_44); |
||
352 | } |
||
353 | return "("+s+")"; |
||
354 | }).replace(/[\xa0 ]/g,"[\\s\\xa0]"); |
||
355 | }; |
||
356 | })(); |
||
357 | (function(){
|
||
358 | var _45=[];
|
||
359 | dojox.date.islamic.locale.addCustomFormats=function(_46,_47){ |
||
360 | _45.push({pkg:_46,name:_47}); |
||
361 | }; |
||
362 | dojox.date.islamic.locale._getIslamicBundle=function(_48){ |
||
363 | var _49={};
|
||
364 | dojo.forEach(_45,function(_4a){
|
||
365 | var _4b=dojo.i18n.getLocalization(_4a.pkg,_4a.name,_48);
|
||
366 | _49=dojo.mixin(_49,_4b); |
||
367 | },this);
|
||
368 | return _49;
|
||
369 | }; |
||
370 | })(); |
||
371 | dojox.date.islamic.locale.addCustomFormats("dojo.cldr","islamic"); |
||
372 | dojox.date.islamic.locale.getNames=function(_4c,_4d,_4e,_4f,_50){ |
||
373 | var _51;
|
||
374 | var _52=dojox.date.islamic.locale._getIslamicBundle;
|
||
375 | var _53=[_4c,_4e,_4d];
|
||
376 | if(_4e=="standAlone"){ |
||
377 | var key=_53.join("-"); |
||
378 | _51=_52(_4f)[key]; |
||
379 | if(_51===_52("ROOT")[key]){ |
||
380 | _51=undefined;
|
||
381 | } |
||
382 | } |
||
383 | _53[1]="format"; |
||
384 | return (_51||_52(_4f)[_53.join("-")]).concat(); |
||
385 | }; |
||
386 | dojox.date.islamic.locale.weekDays=dojox.date.islamic.locale.getNames("days","wide","format"); |
||
387 | dojox.date.islamic.locale.months=dojox.date.islamic.locale.getNames("months","wide","format"); |
||
388 | } |