Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (4.64 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.php"]){
9
dojo._hasResource["dojox.date.php"]=true;
10
dojo.provide("dojox.date.php");
11
dojo.require("dojo.date");
12
dojo.require("dojox.string.tokenize");
13
dojox.date.php.format=function(_1,_2){
14
var df=new dojox.date.php.DateFormat(_2);
15
return df.format(_1);
16
};
17
dojox.date.php.DateFormat=function(_3){
18
if(!this.regex){
19
var _4=[];
20
for(var _5 in this.constructor.prototype){
21
if(dojo.isString(_5)&&_5.length==1&&dojo.isFunction(this[_5])){
22
_4.push(_5);
23
}
24
}
25
this.constructor.prototype.regex=new RegExp("(?:(\\\\.)|(["+_4.join("")+"]))","g");
26
}
27
var _6=[];
28
this.tokens=dojox.string.tokenize(_3,this.regex,function(_7,_8,i){
29
if(_8){
30
_6.push([i,_8]);
31
return _8;
32
}
33
if(_7){
34
return _7.charAt(1);
35
}
36
});
37
this.replacements=_6;
38
};
39
dojo.extend(dojox.date.php.DateFormat,{weekdays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdays_3:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],months_3:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],monthdays:[31,28,31,30,31,30,31,31,30,31,30,31],format:function(_9){
40
this.date=_9;
41
for(var i=0,_a;_a=this.replacements[i];i++){
42
this.tokens[_a[0]]=this[_a[1]]();
43
}
44
return this.tokens.join("");
45
},d:function(){
46
var j=this.j();
47
return (j.length==1)?"0"+j:j;
48
},D:function(){
49
return this.weekdays_3[this.date.getDay()];
50
},j:function(){
51
return this.date.getDate()+"";
52
},l:function(){
53
return this.weekdays[this.date.getDay()];
54
},N:function(){
55
var w=this.w();
56
return (!w)?7:w;
57
},S:function(){
58
switch(this.date.getDate()){
59
case 11:
60
case 12:
61
case 13:
62
return "th";
63
case 1:
64
case 21:
65
case 31:
66
return "st";
67
case 2:
68
case 22:
69
return "nd";
70
case 3:
71
case 23:
72
return "rd";
73
default:
74
return "th";
75
}
76
},w:function(){
77
return this.date.getDay()+"";
78
},z:function(){
79
var _b=this.date.getTime()-new Date(this.date.getFullYear(),0,1).getTime();
80
return Math.floor(_b/86400000)+"";
81
},W:function(){
82
var _c;
83
var _d=new Date(this.date.getFullYear(),0,1).getDay()+1;
84
var w=this.date.getDay()+1;
85
var z=parseInt(this.z());
86
if(z<=(8-_d)&&_d>4){
87
var _e=new Date(this.date.getFullYear()-1,this.date.getMonth(),this.date.getDate());
88
if(_d==5||(_d==6&&dojo.date.isLeapYear(_e))){
89
_c=53;
90
}else{
91
_c=52;
92
}
93
}else{
94
var i;
95
if(Boolean(this.L())){
96
i=366;
97
}else{
98
i=365;
99
}
100
if((i-z)<(4-w)){
101
_c=1;
102
}else{
103
var j=z+(7-w)+(_d-1);
104
_c=Math.ceil(j/7);
105
if(_d>4){
106
--_c;
107
}
108
}
109
}
110
return _c;
111
},F:function(){
112
return this.months[this.date.getMonth()];
113
},m:function(){
114
var n=this.n();
115
return (n.length==1)?"0"+n:n;
116
},M:function(){
117
return this.months_3[this.date.getMonth()];
118
},n:function(){
119
return this.date.getMonth()+1+"";
120
},t:function(){
121
return (Boolean(this.L())&&this.date.getMonth()==1)?29:this.monthdays[this.getMonth()];
122
},L:function(){
123
return (dojo.date.isLeapYear(this.date))?"1":"0";
124
},o:function(){
125
},Y:function(){
126
return this.date.getFullYear()+"";
127
},y:function(){
128
return this.Y().slice(-2);
129
},a:function(){
130
return this.date.getHours()>=12?"pm":"am";
131
},b:function(){
132
return this.a().toUpperCase();
133
},B:function(){
134
var _f=this.date.getTimezoneOffset()+60;
135
var _10=(this.date.getHours()*3600)+(this.date.getMinutes()*60)+this.getSeconds()+(_f*60);
136
var _11=Math.abs(Math.floor(_10/86.4)%1000)+"";
137
while(_11.length<2){
138
_11="0"+_11;
139
}
140
return _11;
141
},g:function(){
142
return (this.date.getHours()>12)?this.date.getHours()-12+"":this.date.getHours()+"";
143
},G:function(){
144
return this.date.getHours()+"";
145
},h:function(){
146
var g=this.g();
147
return (g.length==1)?"0"+g:g;
148
},H:function(){
149
var G=this.G();
150
return (G.length==1)?"0"+G:G;
151
},i:function(){
152
var _12=this.date.getMinutes()+"";
153
return (_12.length==1)?"0"+_12:_12;
154
},s:function(){
155
var _13=this.date.getSeconds()+"";
156
return (_13.length==1)?"0"+_13:_13;
157
},e:function(){
158
return dojo.date.getTimezoneName(this.date);
159
},I:function(){
160
},O:function(){
161
var off=Math.abs(this.date.getTimezoneOffset());
162
var _14=Math.floor(off/60)+"";
163
var _15=(off%60)+"";
164
if(_14.length==1){
165
_14="0"+_14;
166
}
167
if(_15.length==1){
168
_14="0"+_15;
169
}
170
return ((this.date.getTimezoneOffset()<0)?"+":"-")+_14+_15;
171
},P:function(){
172
var O=this.O();
173
return O.substring(0,2)+":"+O.substring(2,4);
174
},T:function(){
175
return this.e().substring(0,3);
176
},Z:function(){
177
return this.date.getTimezoneOffset()*-60;
178
},c:function(){
179
return this.Y()+"-"+this.m()+"-"+this.d()+"T"+this.h()+":"+this.i()+":"+this.s()+this.P();
180
},r:function(){
181
return this.D()+", "+this.d()+" "+this.M()+" "+this.Y()+" "+this.H()+":"+this.i()+":"+this.s()+" "+this.O();
182
},U:function(){
183
return Math.floor(this.date.getTime()/1000);
184
}});
185
}