Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / date / buddhist / locale.js

History | View | Annotate | Download (6.7 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.buddhist.locale"]){
9
dojo._hasResource["dojox.date.buddhist.locale"]=true;
10
dojo.provide("dojox.date.buddhist.locale");
11
dojo.experimental("dojox.date.buddhist.locale");
12
dojo.require("dojox.date.buddhist.Date");
13
dojo.require("dojo.regexp");
14
dojo.require("dojo.string");
15
dojo.require("dojo.i18n");
16
dojo.requireLocalization("dojo.cldr","buddhist",null,"ROOT,th");
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
default:
93
throw new Error("dojox.date.buddhist.locale.formatPattern: invalid pattern char: "+_6);
94
}
95
if(_8){
96
s=dojo.string.pad(s,l);
97
}
98
return s;
99
});
100
};
101
dojox.date.buddhist.locale.format=function(_d,_e){
102
_e=_e||{};
103
var _f=dojo.i18n.normalizeLocale(_e.locale);
104
var _10=_e.formatLength||"short";
105
var _11=dojox.date.buddhist.locale._getBuddhistBundle(_f);
106
var str=[];
107
var _12=dojo.hitch(this,_1,_d,_11,_f,_e.fullYear);
108
if(_e.selector=="year"){
109
var _13=_d.getFullYear();
110
return _13;
111
}
112
if(_e.selector!="time"){
113
var _14=_e.datePattern||_11["dateFormat-"+_10];
114
if(_14){
115
str.push(_15(_14,_12));
116
}
117
}
118
if(_e.selector!="date"){
119
var _16=_e.timePattern||_11["timeFormat-"+_10];
120
if(_16){
121
str.push(_15(_16,_12));
122
}
123
}
124
var _17=str.join(" ");
125
return _17;
126
};
127
dojox.date.buddhist.locale.regexp=function(_18){
128
return dojox.date.buddhist.locale._parseInfo(_18).regexp;
129
};
130
dojox.date.buddhist.locale._parseInfo=function(_19){
131
_19=_19||{};
132
var _1a=dojo.i18n.normalizeLocale(_19.locale);
133
var _1b=dojox.date.buddhist.locale._getBuddhistBundle(_1a);
134
var _1c=_19.formatLength||"short";
135
var _1d=_19.datePattern||_1b["dateFormat-"+_1c];
136
var _1e=_19.timePattern||_1b["timeFormat-"+_1c];
137
var _1f;
138
if(_19.selector=="date"){
139
_1f=_1d;
140
}else{
141
if(_19.selector=="time"){
142
_1f=_1e;
143
}else{
144
_1f=(typeof (_1e)=="undefined")?_1d:_1d+" "+_1e;
145
}
146
}
147
var _20=[];
148
var re=_15(_1f,dojo.hitch(this,_21,_20,_1b,_19));
149
return {regexp:re,tokens:_20,bundle:_1b};
150
};
151
dojox.date.buddhist.locale.parse=function(_22,_23){
152
_22=_22.replace(/[\u200E\u200F\u202A-\u202E]/g,"");
153
if(!_23){
154
_23={};
155
}
156
var _24=dojox.date.buddhist.locale._parseInfo(_23);
157
var _25=_24.tokens,_26=_24.bundle;
158
var re=new RegExp("^"+_24.regexp+"$");
159
var _27=re.exec(_22);
160
var _28=dojo.i18n.normalizeLocale(_23.locale);
161
if(!_27){
162
return null;
163
}
164
var _29,_2a;
165
var _2b=[2513,0,1,0,0,0,0];
166
var _2c="";
167
var _2d=0;
168
var _2e=["abbr","wide","narrow"];
169
var _2f=dojo.every(_27,function(v,i){
170
if(!i){
171
return true;
172
}
173
var _30=_25[i-1];
174
var l=_30.length;
175
switch(_30.charAt(0)){
176
case "y":
177
_2b[0]=Number(v);
178
break;
179
case "M":
180
if(l>2){
181
var _31=_26["months-format-"+_2e[l-3]].concat();
182
if(!_23.strict){
183
v=v.replace(".","").toLowerCase();
184
_31=dojo.map(_31,function(s){
185
return s?s.replace(".","").toLowerCase():s;
186
});
187
}
188
v=dojo.indexOf(_31,v);
189
if(v==-1){
190
return false;
191
}
192
_2d=l;
193
}else{
194
v--;
195
}
196
_2b[1]=Number(v);
197
break;
198
case "D":
199
_2b[1]=0;
200
case "d":
201
_2b[2]=Number(v);
202
break;
203
case "a":
204
var am=_23.am||_26["dayPeriods-format-wide-am"],pm=_23.pm||_26["dayPeriods-format-wide-pm"];
205
if(!_23.strict){
206
var _32=/\./g;
207
v=v.replace(_32,"").toLowerCase();
208
am=am.replace(_32,"").toLowerCase();
209
pm=pm.replace(_32,"").toLowerCase();
210
}
211
if(_23.strict&&v!=am&&v!=pm){
212
return false;
213
}
214
_2c=(v==pm)?"p":(v==am)?"a":"";
215
break;
216
case "K":
217
if(v==24){
218
v=0;
219
}
220
case "h":
221
case "H":
222
case "k":
223
_2b[3]=Number(v);
224
break;
225
case "m":
226
_2b[4]=Number(v);
227
break;
228
case "s":
229
_2b[5]=Number(v);
230
break;
231
case "S":
232
_2b[6]=Number(v);
233
}
234
return true;
235
});
236
var _33=+_2b[3];
237
if(_2c==="p"&&_33<12){
238
_2b[3]=_33+12;
239
}else{
240
if(_2c==="a"&&_33==12){
241
_2b[3]=0;
242
}
243
}
244
var _34=new dojox.date.buddhist.Date(_2b[0],_2b[1],_2b[2],_2b[3],_2b[4],_2b[5],_2b[6]);
245
return _34;
246
};
247
function _15(_35,_36,_37,_38){
248
var _39=function(x){
249
return x;
250
};
251
_36=_36||_39;
252
_37=_37||_39;
253
_38=_38||_39;
254
var _3a=_35.match(/(''|[^'])+/g);
255
var _3b=_35.charAt(0)=="'";
256
dojo.forEach(_3a,function(_3c,i){
257
if(!_3c){
258
_3a[i]="";
259
}else{
260
_3a[i]=(_3b?_37:_36)(_3c);
261
_3b=!_3b;
262
}
263
});
264
return _38(_3a.join(""));
265
};
266
function _21(_3d,_3e,_3f,_40){
267
_40=dojo.regexp.escapeString(_40);
268
var _41=dojo.i18n.normalizeLocale(_3f.locale);
269
return _40.replace(/([a-z])\1*/ig,function(_42){
270
var s;
271
var c=_42.charAt(0);
272
var l=_42.length;
273
var p2="",p3="";
274
if(_3f.strict){
275
if(l>1){
276
p2="0"+"{"+(l-1)+"}";
277
}
278
if(l>2){
279
p3="0"+"{"+(l-2)+"}";
280
}
281
}else{
282
p2="0?";
283
p3="0{0,2}";
284
}
285
switch(c){
286
case "y":
287
s="\\d+";
288
break;
289
case "M":
290
s=(l>2)?"\\S+":p2+"[1-9]|1[0-2]";
291
break;
292
case "d":
293
s="[12]\\d|"+p2+"[1-9]|3[01]";
294
break;
295
case "E":
296
s="\\S+";
297
break;
298
case "h":
299
s=p2+"[1-9]|1[0-2]";
300
break;
301
case "k":
302
s=p2+"\\d|1[01]";
303
break;
304
case "H":
305
s=p2+"\\d|1\\d|2[0-3]";
306
break;
307
case "K":
308
s=p2+"[1-9]|1\\d|2[0-4]";
309
break;
310
case "m":
311
case "s":
312
s=p2+"\\d|[0-5]\\d";
313
break;
314
case "S":
315
s="\\d{"+l+"}";
316
break;
317
case "a":
318
var am=_3f.am||_3e["dayPeriods-format-wide-am"],pm=_3f.pm||_3e["dayPeriods-format-wide-pm"];
319
if(_3f.strict){
320
s=am+"|"+pm;
321
}else{
322
s=am+"|"+pm;
323
if(am!=am.toLowerCase()){
324
s+="|"+am.toLowerCase();
325
}
326
if(pm!=pm.toLowerCase()){
327
s+="|"+pm.toLowerCase();
328
}
329
}
330
break;
331
default:
332
s=".*";
333
}
334
if(_3d){
335
_3d.push(_42);
336
}
337
return "("+s+")";
338
}).replace(/[\xa0 ]/g,"[\\s\\xa0]");
339
};
340
})();
341
(function(){
342
var _43=[];
343
dojox.date.buddhist.locale.addCustomFormats=function(_44,_45){
344
_43.push({pkg:_44,name:_45});
345
};
346
dojox.date.buddhist.locale._getBuddhistBundle=function(_46){
347
var _47={};
348
dojo.forEach(_43,function(_48){
349
var _49=dojo.i18n.getLocalization(_48.pkg,_48.name,_46);
350
_47=dojo.mixin(_47,_49);
351
},this);
352
return _47;
353
};
354
})();
355
dojox.date.buddhist.locale.addCustomFormats("dojo.cldr","buddhist");
356
dojox.date.buddhist.locale.getNames=function(_4a,_4b,_4c,_4d,_4e){
357
var _4f;
358
var _50=dojox.date.buddhist.locale._getBuddhistBundle;
359
var _51=[_4a,_4c,_4b];
360
if(_4c=="standAlone"){
361
var key=_51.join("-");
362
_4f=_50(_4d)[key];
363
if(_4f===_50("ROOT")[key]){
364
_4f=undefined;
365
}
366
}
367
_51[1]="format";
368
return (_4f||_50(_4d)[_51.join("-")]).concat();
369
};
370
}