Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / date / posix.js @ 9

History | View | Annotate | Download (4.51 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.posix"]){
9
dojo._hasResource["dojox.date.posix"]=true;
10
dojo.provide("dojox.date.posix");
11
dojo.require("dojo.date");
12
dojo.require("dojo.date.locale");
13
dojo.require("dojo.string");
14
dojox.date.posix.strftime=function(_1,_2,_3){
15
var _4=null;
16
var _5=function(s,n){
17
return dojo.string.pad(s,n||2,_4||"0");
18
};
19
var _6=dojo.date.locale._getGregorianBundle(_3);
20
var $=function(_7){
21
switch(_7){
22
case "a":
23
return dojo.date.locale.getNames("days","abbr","format",_3)[_1.getDay()];
24
case "A":
25
return dojo.date.locale.getNames("days","wide","format",_3)[_1.getDay()];
26
case "b":
27
case "h":
28
return dojo.date.locale.getNames("months","abbr","format",_3)[_1.getMonth()];
29
case "B":
30
return dojo.date.locale.getNames("months","wide","format",_3)[_1.getMonth()];
31
case "c":
32
return dojo.date.locale.format(_1,{formatLength:"full",locale:_3});
33
case "C":
34
return _5(Math.floor(_1.getFullYear()/100));
35
case "d":
36
return _5(_1.getDate());
37
case "D":
38
return $("m")+"/"+$("d")+"/"+$("y");
39
case "e":
40
if(_4==null){
41
_4=" ";
42
}
43
return _5(_1.getDate());
44
case "f":
45
if(_4==null){
46
_4=" ";
47
}
48
return _5(_1.getMonth()+1);
49
case "g":
50
break;
51
case "G":
52
dojo.unimplemented("unimplemented modifier 'G'");
53
break;
54
case "F":
55
return $("Y")+"-"+$("m")+"-"+$("d");
56
case "H":
57
return _5(_1.getHours());
58
case "I":
59
return _5(_1.getHours()%12||12);
60
case "j":
61
return _5(dojo.date.locale._getDayOfYear(_1),3);
62
case "k":
63
if(_4==null){
64
_4=" ";
65
}
66
return _5(_1.getHours());
67
case "l":
68
if(_4==null){
69
_4=" ";
70
}
71
return _5(_1.getHours()%12||12);
72
case "m":
73
return _5(_1.getMonth()+1);
74
case "M":
75
return _5(_1.getMinutes());
76
case "n":
77
return "\n";
78
case "p":
79
return _6["dayPeriods-format-wide-"+(_1.getHours()<12?"am":"pm")];
80
case "r":
81
return $("I")+":"+$("M")+":"+$("S")+" "+$("p");
82
case "R":
83
return $("H")+":"+$("M");
84
case "S":
85
return _5(_1.getSeconds());
86
case "t":
87
return "\t";
88
case "T":
89
return $("H")+":"+$("M")+":"+$("S");
90
case "u":
91
return String(_1.getDay()||7);
92
case "U":
93
return _5(dojo.date.locale._getWeekOfYear(_1));
94
case "V":
95
return _5(dojox.date.posix.getIsoWeekOfYear(_1));
96
case "W":
97
return _5(dojo.date.locale._getWeekOfYear(_1,1));
98
case "w":
99
return String(_1.getDay());
100
case "x":
101
return dojo.date.locale.format(_1,{selector:"date",formatLength:"full",locale:_3});
102
case "X":
103
return dojo.date.locale.format(_1,{selector:"time",formatLength:"full",locale:_3});
104
case "y":
105
return _5(_1.getFullYear()%100);
106
case "Y":
107
return String(_1.getFullYear());
108
case "z":
109
var _8=_1.getTimezoneOffset();
110
return (_8>0?"-":"+")+_5(Math.floor(Math.abs(_8)/60))+":"+_5(Math.abs(_8)%60);
111
case "Z":
112
return dojo.date.getTimezoneName(_1);
113
case "%":
114
return "%";
115
}
116
};
117
var _9="";
118
var i=0;
119
var _a=0;
120
var _b=null;
121
while((_a=_2.indexOf("%",i))!=-1){
122
_9+=_2.substring(i,_a++);
123
switch(_2.charAt(_a++)){
124
case "_":
125
_4=" ";
126
break;
127
case "-":
128
_4="";
129
break;
130
case "0":
131
_4="0";
132
break;
133
case "^":
134
_b="upper";
135
break;
136
case "*":
137
_b="lower";
138
break;
139
case "#":
140
_b="swap";
141
break;
142
default:
143
_4=null;
144
_a--;
145
break;
146
}
147
var _c=$(_2.charAt(_a++));
148
switch(_b){
149
case "upper":
150
_c=_c.toUpperCase();
151
break;
152
case "lower":
153
_c=_c.toLowerCase();
154
break;
155
case "swap":
156
var _d=_c.toLowerCase();
157
var _e="";
158
var ch="";
159
for(var j=0;j<_c.length;j++){
160
ch=_c.charAt(j);
161
_e+=(ch==_d.charAt(j))?ch.toUpperCase():ch.toLowerCase();
162
}
163
_c=_e;
164
break;
165
default:
166
break;
167
}
168
_b=null;
169
_9+=_c;
170
i=_a;
171
}
172
_9+=_2.substring(i);
173
return _9;
174
};
175
dojox.date.posix.getStartOfWeek=function(_f,_10){
176
if(isNaN(_10)){
177
_10=dojo.cldr.supplemental.getFirstDayOfWeek?dojo.cldr.supplemental.getFirstDayOfWeek():0;
178
}
179
var _11=_10;
180
if(_f.getDay()>=_10){
181
_11-=_f.getDay();
182
}else{
183
_11-=(7-_f.getDay());
184
}
185
var _12=new Date(_f);
186
_12.setHours(0,0,0,0);
187
return dojo.date.add(_12,"day",_11);
188
};
189
dojox.date.posix.setIsoWeekOfYear=function(_13,_14){
190
if(!_14){
191
return _13;
192
}
193
var _15=dojox.date.posix.getIsoWeekOfYear(_13);
194
var _16=_14-_15;
195
if(_14<0){
196
var _17=dojox.date.posix.getIsoWeeksInYear(_13);
197
_16=(_17+_14+1)-_15;
198
}
199
return dojo.date.add(_13,"week",_16);
200
};
201
dojox.date.posix.getIsoWeekOfYear=function(_18){
202
var _19=dojox.date.posix.getStartOfWeek(_18,1);
203
var _1a=new Date(_18.getFullYear(),0,4);
204
_1a=dojox.date.posix.getStartOfWeek(_1a,1);
205
var _1b=_19.getTime()-_1a.getTime();
206
if(_1b<0){
207
return dojox.date.posix.getIsoWeeksInYear(_19);
208
}
209
return Math.ceil(_1b/604800000)+1;
210
};
211
dojox.date.posix.getIsoWeeksInYear=function(_1c){
212
function p(y){
213
return y+Math.floor(y/4)-Math.floor(y/100)+Math.floor(y/400);
214
};
215
var y=_1c.getFullYear();
216
return (p(y)%7==4||p(y-1)%7==3)?53:52;
217
};
218
}