Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / date / hebrew / locale.js @ 11

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