2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.date.php"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.date.php"] = true;
|
|
|
3 |
dojo.provide("dojox.date.php");
|
|
|
4 |
dojo.require("dojo.date");
|
|
|
5 |
|
|
|
6 |
dojox.date.php.format = function(/*Date*/ date, /*String*/ format, /*Object?*/ overrides){
|
|
|
7 |
// summary: Get a formatted string for a given date object
|
|
|
8 |
var df = new dojox.date.php.DateFormat(date);
|
|
|
9 |
return df.format(format, overrides);
|
|
|
10 |
}
|
|
|
11 |
|
|
|
12 |
dojox.date.php.DateFormat = function(/*Date*/ date){
|
|
|
13 |
this.date = date;
|
|
|
14 |
}
|
|
|
15 |
dojo.extend(dojox.date.php.DateFormat, {
|
|
|
16 |
weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
|
|
17 |
weekdays_3: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
|
18 |
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
|
|
19 |
months_3: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
|
|
20 |
monthdays: [31,28,31,30,31,30,31,31,30,31,30,31],
|
|
|
21 |
|
|
|
22 |
format: function(/*String*/ format, /*Object?*/ overrides){
|
|
|
23 |
// summary: Format the internal date object
|
|
|
24 |
var parts = [];
|
|
|
25 |
for(var i = 0; i < format.length; i++){
|
|
|
26 |
var chr = format.charAt(i);
|
|
|
27 |
if(overrides && typeof overrides[chr] == "function"){
|
|
|
28 |
parts.push(overrides[chr].call(this));
|
|
|
29 |
}else if(typeof this[chr] == "function"){
|
|
|
30 |
parts.push(this[chr]());
|
|
|
31 |
}else{
|
|
|
32 |
parts.push(chr);
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
return parts.join("");
|
|
|
36 |
},
|
|
|
37 |
|
|
|
38 |
// Day
|
|
|
39 |
|
|
|
40 |
d: function(){
|
|
|
41 |
// summary: Day of the month, 2 digits with leading zeros
|
|
|
42 |
var j = this.j();
|
|
|
43 |
return (j.length == 1) ? "0" + j : j;
|
|
|
44 |
},
|
|
|
45 |
|
|
|
46 |
D: function(){
|
|
|
47 |
// summary: A textual representation of a day, three letters
|
|
|
48 |
return this.weekdays_3[this.date.getDay()];
|
|
|
49 |
},
|
|
|
50 |
|
|
|
51 |
j: function(){
|
|
|
52 |
// summary: Day of the month without leading zeros
|
|
|
53 |
return this.date.getDate() + "";
|
|
|
54 |
},
|
|
|
55 |
|
|
|
56 |
l: function(){
|
|
|
57 |
// summary: A full textual representation of the day of the week
|
|
|
58 |
return this.weekdays[this.date.getDay()];
|
|
|
59 |
},
|
|
|
60 |
|
|
|
61 |
N: function(){
|
|
|
62 |
// summary: ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)
|
|
|
63 |
var w = this.w();
|
|
|
64 |
return (!w) ? 7 : w;
|
|
|
65 |
},
|
|
|
66 |
|
|
|
67 |
S: function(){
|
|
|
68 |
// summary: English ordinal suffix for the day of the month, 2 characters
|
|
|
69 |
switch(this.date.getDate()){
|
|
|
70 |
case 11: case 12: case 13: return "th";
|
|
|
71 |
case 1: case 21: case 31: return "st";
|
|
|
72 |
case 2: case 22: return "nd";
|
|
|
73 |
case 3: case 23: return "rd";
|
|
|
74 |
default: return "th";
|
|
|
75 |
}
|
|
|
76 |
},
|
|
|
77 |
|
|
|
78 |
w: function(){
|
|
|
79 |
// summary: Numeric representation of the day of the week
|
|
|
80 |
return this.date.getDay() + "";
|
|
|
81 |
},
|
|
|
82 |
|
|
|
83 |
z: function(){
|
|
|
84 |
// summary: The day of the year (starting from 0)
|
|
|
85 |
var millis = this.date.getTime() - new Date(this.date.getFullYear(), 0, 1).getTime();
|
|
|
86 |
return Math.floor(millis/86400000) + "";
|
|
|
87 |
},
|
|
|
88 |
|
|
|
89 |
// Week
|
|
|
90 |
|
|
|
91 |
W: function(){
|
|
|
92 |
// summary: ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
|
|
|
93 |
var week;
|
|
|
94 |
var jan1_w = new Date(this.date.getFullYear(), 0, 1).getDay() + 1;
|
|
|
95 |
var w = this.date.getDay() + 1;
|
|
|
96 |
var z = parseInt(this.z());
|
|
|
97 |
|
|
|
98 |
if(z <= (8 - jan1_w) && jan1_w > 4){
|
|
|
99 |
var last_year = new Date(this.date.getFullYear() - 1, this.date.getMonth(), this.date.getDate());
|
|
|
100 |
if(jan1_w == 5 || (jan1_w == 6 && dojo.date.isLeapYear(last_year))){
|
|
|
101 |
week = 53;
|
|
|
102 |
}else{
|
|
|
103 |
week = 52;
|
|
|
104 |
}
|
|
|
105 |
}else{
|
|
|
106 |
var i;
|
|
|
107 |
if(Boolean(this.L())){
|
|
|
108 |
i = 366;
|
|
|
109 |
}else{
|
|
|
110 |
i = 365;
|
|
|
111 |
}
|
|
|
112 |
if((i - z) < (4 - w)){
|
|
|
113 |
week = 1;
|
|
|
114 |
}else{
|
|
|
115 |
var j = z + (7 - w) + (jan1_w - 1);
|
|
|
116 |
week = Math.ceil(j / 7);
|
|
|
117 |
if(jan1_w > 4){
|
|
|
118 |
--week;
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
return week;
|
|
|
124 |
},
|
|
|
125 |
|
|
|
126 |
// Month
|
|
|
127 |
|
|
|
128 |
F: function(){
|
|
|
129 |
// summary: A full textual representation of a month, such as January or March
|
|
|
130 |
return this.months[this.date.getMonth()];
|
|
|
131 |
},
|
|
|
132 |
|
|
|
133 |
m: function(){
|
|
|
134 |
// summary: Numeric representation of a month, with leading zeros
|
|
|
135 |
var n = this.n();
|
|
|
136 |
return (n.length == 1) ? "0" + n : n;
|
|
|
137 |
},
|
|
|
138 |
|
|
|
139 |
M: function(){
|
|
|
140 |
// summary: A short textual representation of a month, three letters
|
|
|
141 |
return months_3[this.date.getMonth()];
|
|
|
142 |
},
|
|
|
143 |
|
|
|
144 |
n: function(){
|
|
|
145 |
// summary: Numeric representation of a month, without leading zeros
|
|
|
146 |
return this.date.getMonth() + 1 + "";
|
|
|
147 |
},
|
|
|
148 |
|
|
|
149 |
t: function(){
|
|
|
150 |
// summary: Number of days in the given month
|
|
|
151 |
return (Boolean(this.L()) && this.date.getMonth() == 1) ? 29 : this.monthdays[this.getMonth()];
|
|
|
152 |
},
|
|
|
153 |
|
|
|
154 |
// Year
|
|
|
155 |
|
|
|
156 |
L: function(){
|
|
|
157 |
// summary: Whether it's a leap year
|
|
|
158 |
return (dojo.date.isLeapYear(this.date)) ? "1" : "0";
|
|
|
159 |
},
|
|
|
160 |
|
|
|
161 |
o: function(){
|
|
|
162 |
// summary:
|
|
|
163 |
// ISO-8601 year number. This has the same value as Y, except that if
|
|
|
164 |
// the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
|
|
|
165 |
// TODO: Figure out what this means
|
|
|
166 |
},
|
|
|
167 |
|
|
|
168 |
Y: function(){
|
|
|
169 |
// summary: A full numeric representation of a year, 4 digits
|
|
|
170 |
return this.date.getFullYear() + "";
|
|
|
171 |
},
|
|
|
172 |
|
|
|
173 |
y: function(){
|
|
|
174 |
// summary: A two digit representation of a year
|
|
|
175 |
return this.date.getFullYear.substsring(2, 4);
|
|
|
176 |
},
|
|
|
177 |
|
|
|
178 |
// Time
|
|
|
179 |
|
|
|
180 |
a: function(){
|
|
|
181 |
// summary: Lowercase Ante meridiem and Post meridiem
|
|
|
182 |
return this.date.getHours() >= 12 ? "pm" : "am";
|
|
|
183 |
},
|
|
|
184 |
|
|
|
185 |
b: function(){
|
|
|
186 |
// summary: Uppercase Ante meridiem and Post meridiem
|
|
|
187 |
return this.a().toUpperCase();
|
|
|
188 |
},
|
|
|
189 |
|
|
|
190 |
B: function(){
|
|
|
191 |
// summary:
|
|
|
192 |
// Swatch Internet time
|
|
|
193 |
// A day is 1,000 beats. All time is measured from GMT + 1
|
|
|
194 |
var off = this.date.getTimezoneOffset() + 60;
|
|
|
195 |
var secs = (this.date.getHours() * 3600) + (this.date.getMinutes() * 60) + this.getSeconds() + (off * 60);
|
|
|
196 |
var beat = Math.abs(Math.floor(secs / 86.4) % 1000) + "";
|
|
|
197 |
while(beat.length < 2) beat = "0" + beat;
|
|
|
198 |
return beat;
|
|
|
199 |
},
|
|
|
200 |
|
|
|
201 |
g: function(){
|
|
|
202 |
// summary: 12-hour format of an hour without leading zeros
|
|
|
203 |
return (this.date.getHours() > 12) ? this.date.getHours() - 12 + "" : this.date.getHours() + "";
|
|
|
204 |
},
|
|
|
205 |
|
|
|
206 |
G: function(){
|
|
|
207 |
// summary: 24-hour format of an hour without leading zeros
|
|
|
208 |
return this.date.getHours() + "";
|
|
|
209 |
},
|
|
|
210 |
|
|
|
211 |
h: function(){
|
|
|
212 |
// summary: 12-hour format of an hour with leading zeros
|
|
|
213 |
var g = this.g();
|
|
|
214 |
return (g.length == 1) ? "0" + g : g;
|
|
|
215 |
},
|
|
|
216 |
|
|
|
217 |
H: function(){
|
|
|
218 |
// summary: 24-hour format of an hour with leading zeros
|
|
|
219 |
var G = this.G();
|
|
|
220 |
return (G.length == 1) ? "0" + G : G;
|
|
|
221 |
},
|
|
|
222 |
|
|
|
223 |
i: function(){
|
|
|
224 |
// summary: Minutes with leading zeros
|
|
|
225 |
var mins = this.date.getMinutes() + "";
|
|
|
226 |
return (mins.length == 1) ? "0" + mins : mins;
|
|
|
227 |
},
|
|
|
228 |
|
|
|
229 |
s: function(){
|
|
|
230 |
// summary: Seconds, with leading zeros
|
|
|
231 |
var secs = this.date.getSeconds() + "";
|
|
|
232 |
return (secs.length == 1) ? "0" + secs : secs;
|
|
|
233 |
},
|
|
|
234 |
|
|
|
235 |
// Timezone
|
|
|
236 |
|
|
|
237 |
e: function(){
|
|
|
238 |
// summary: Timezone identifier (added in PHP 5.1.0)
|
|
|
239 |
return dojo.date.getTimezoneName(this.date);
|
|
|
240 |
},
|
|
|
241 |
|
|
|
242 |
I: function(){
|
|
|
243 |
// summary: Whether or not the date is in daylight saving time
|
|
|
244 |
// TODO: Can dojo.date do this?
|
|
|
245 |
},
|
|
|
246 |
|
|
|
247 |
O: function(){
|
|
|
248 |
// summary: Difference to Greenwich time (GMT) in hours
|
|
|
249 |
var off = Math.abs(this.date.getTimezoneOffset());
|
|
|
250 |
var hours = Math.floor(off / 60) + "";
|
|
|
251 |
var mins = (off % 60) + "";
|
|
|
252 |
if(hours.length == 1) hours = "0" + hours;
|
|
|
253 |
if(mins.length == 1) hours = "0" + mins;
|
|
|
254 |
return ((this.date.getTimezoneOffset() < 0) ? "+" : "-") + hours + mins;
|
|
|
255 |
},
|
|
|
256 |
|
|
|
257 |
P: function(){
|
|
|
258 |
// summary: Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)
|
|
|
259 |
var O = this.O();
|
|
|
260 |
return O.substring(0, 2) + ":" + O.substring(2, 4);
|
|
|
261 |
},
|
|
|
262 |
|
|
|
263 |
T: function(){
|
|
|
264 |
// summary: Timezone abbreviation
|
|
|
265 |
|
|
|
266 |
// Guess...
|
|
|
267 |
return this.e().substring(0, 3);
|
|
|
268 |
},
|
|
|
269 |
|
|
|
270 |
Z: function(){
|
|
|
271 |
// summary:
|
|
|
272 |
// Timezone offset in seconds. The offset for timezones west of UTC is always negative,
|
|
|
273 |
// and for those east of UTC is always positive.
|
|
|
274 |
return this.date.getTimezoneOffset() * -60;
|
|
|
275 |
},
|
|
|
276 |
|
|
|
277 |
// Full Date/Time
|
|
|
278 |
|
|
|
279 |
c: function(){
|
|
|
280 |
// summary: ISO 8601 date (added in PHP 5)
|
|
|
281 |
return this.Y() + "-" + this.m() + "-" + this.d() + "T" + this.h() + ":" + this.i() + ":" + this.s() + this.P();
|
|
|
282 |
},
|
|
|
283 |
|
|
|
284 |
r: function(){
|
|
|
285 |
// summary: RFC 2822 formatted date
|
|
|
286 |
return this.D() + ", " + this.d() + " " + this.M() + " " + this.Y() + " " + this.H() + ":" + this.i() + ":" + this.s() + " " + this.O();
|
|
|
287 |
},
|
|
|
288 |
|
|
|
289 |
U: function(){
|
|
|
290 |
// summary: Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
|
|
|
291 |
return Math.floor(this.date.getTime() / 1000);
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
});
|
|
|
295 |
|
|
|
296 |
}
|