Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / testing / performance / talos / page_load_test / sunspider / date-format-xparb.html
blob0e8b14f714548ad3b6c500df810e5133d5f9b922
1 <!DOCTYPE html>
2 <head>
3 <!--
4 Copyright (C) 2007 Apple Inc. All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
15 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 -->
28 <title>SunSpider date-format-xparb</title>
29 <link rel="stylesheet" href="sunspider.css"></link>
30 </head>
32 <body>
33 <h3>date-format-xparb</h3>
34 <div id="console">
35 </div>
36 <script>
40 * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
42 * This program is free software; you can redistribute it and/or modify it
43 * under the terms of the GNU Lesser General Public License as published by the
44 * Free Software Foundation, version 2.1.
46 * This program is distributed in the hope that it will be useful, but WITHOUT
47 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
48 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
49 * details.
52 Date.parseFunctions = {count:0};
53 Date.parseRegexes = [];
54 Date.formatFunctions = {count:0};
56 Date.prototype.dateFormat = function(format) {
57 if (Date.formatFunctions[format] == null) {
58 Date.createNewFormat(format);
60 var func = Date.formatFunctions[format];
61 return this[func]();
64 Date.createNewFormat = function(format) {
65 var funcName = "format" + Date.formatFunctions.count++;
66 Date.formatFunctions[format] = funcName;
67 var code = "Date.prototype." + funcName + " = function(){return ";
68 var special = false;
69 var ch = '';
70 for (var i = 0; i < format.length; ++i) {
71 ch = format.charAt(i);
72 if (!special && ch == "\\") {
73 special = true;
75 else if (special) {
76 special = false;
77 code += "'" + String.escape(ch) + "' + ";
79 else {
80 code += Date.getFormatCode(ch);
83 eval(code.substring(0, code.length - 3) + ";}");
86 Date.getFormatCode = function(character) {
87 switch (character) {
88 case "d":
89 return "String.leftPad(this.getDate(), 2, '0') + ";
90 case "D":
91 return "Date.dayNames[this.getDay()].substring(0, 3) + ";
92 case "j":
93 return "this.getDate() + ";
94 case "l":
95 return "Date.dayNames[this.getDay()] + ";
96 case "S":
97 return "this.getSuffix() + ";
98 case "w":
99 return "this.getDay() + ";
100 case "z":
101 return "this.getDayOfYear() + ";
102 case "W":
103 return "this.getWeekOfYear() + ";
104 case "F":
105 return "Date.monthNames[this.getMonth()] + ";
106 case "m":
107 return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
108 case "M":
109 return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
110 case "n":
111 return "(this.getMonth() + 1) + ";
112 case "t":
113 return "this.getDaysInMonth() + ";
114 case "L":
115 return "(this.isLeapYear() ? 1 : 0) + ";
116 case "Y":
117 return "this.getFullYear() + ";
118 case "y":
119 return "('' + this.getFullYear()).substring(2, 4) + ";
120 case "a":
121 return "(this.getHours() < 12 ? 'am' : 'pm') + ";
122 case "A":
123 return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
124 case "g":
125 return "((this.getHours() %12) ? this.getHours() % 12 : 12) + ";
126 case "G":
127 return "this.getHours() + ";
128 case "h":
129 return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";
130 case "H":
131 return "String.leftPad(this.getHours(), 2, '0') + ";
132 case "i":
133 return "String.leftPad(this.getMinutes(), 2, '0') + ";
134 case "s":
135 return "String.leftPad(this.getSeconds(), 2, '0') + ";
136 case "O":
137 return "this.getGMTOffset() + ";
138 case "T":
139 return "this.getTimezone() + ";
140 case "Z":
141 return "(this.getTimezoneOffset() * -60) + ";
142 default:
143 return "'" + String.escape(character) + "' + ";
147 Date.parseDate = function(input, format) {
148 if (Date.parseFunctions[format] == null) {
149 Date.createParser(format);
151 var func = Date.parseFunctions[format];
152 return Date[func](input);
155 Date.createParser = function(format) {
156 var funcName = "parse" + Date.parseFunctions.count++;
157 var regexNum = Date.parseRegexes.length;
158 var currentGroup = 1;
159 Date.parseFunctions[format] = funcName;
161 var code = "Date." + funcName + " = function(input){\n"
162 + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n"
163 + "var d = new Date();\n"
164 + "y = d.getFullYear();\n"
165 + "m = d.getMonth();\n"
166 + "d = d.getDate();\n"
167 + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
168 + "if (results && results.length > 0) {"
169 var regex = "";
171 var special = false;
172 var ch = '';
173 for (var i = 0; i < format.length; ++i) {
174 ch = format.charAt(i);
175 if (!special && ch == "\\") {
176 special = true;
178 else if (special) {
179 special = false;
180 regex += String.escape(ch);
182 else {
183 obj = Date.formatCodeToRegex(ch, currentGroup);
184 currentGroup += obj.g;
185 regex += obj.s;
186 if (obj.g && obj.c) {
187 code += obj.c;
192 code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
193 + "{return new Date(y, m, d, h, i, s);}\n"
194 + "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
195 + "{return new Date(y, m, d, h, i);}\n"
196 + "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n"
197 + "{return new Date(y, m, d, h);}\n"
198 + "else if (y > 0 && m >= 0 && d > 0)\n"
199 + "{return new Date(y, m, d);}\n"
200 + "else if (y > 0 && m >= 0)\n"
201 + "{return new Date(y, m);}\n"
202 + "else if (y > 0)\n"
203 + "{return new Date(y);}\n"
204 + "}return null;}";
206 Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
207 eval(code);
210 Date.formatCodeToRegex = function(character, currentGroup) {
211 switch (character) {
212 case "D":
213 return {g:0,
214 c:null,
215 s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
216 case "j":
217 case "d":
218 return {g:1,
219 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
220 s:"(\\d{1,2})"};
221 case "l":
222 return {g:0,
223 c:null,
224 s:"(?:" + Date.dayNames.join("|") + ")"};
225 case "S":
226 return {g:0,
227 c:null,
228 s:"(?:st|nd|rd|th)"};
229 case "w":
230 return {g:0,
231 c:null,
232 s:"\\d"};
233 case "z":
234 return {g:0,
235 c:null,
236 s:"(?:\\d{1,3})"};
237 case "W":
238 return {g:0,
239 c:null,
240 s:"(?:\\d{2})"};
241 case "F":
242 return {g:1,
243 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
244 s:"(" + Date.monthNames.join("|") + ")"};
245 case "M":
246 return {g:1,
247 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
248 s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
249 case "n":
250 case "m":
251 return {g:1,
252 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
253 s:"(\\d{1,2})"};
254 case "t":
255 return {g:0,
256 c:null,
257 s:"\\d{1,2}"};
258 case "L":
259 return {g:0,
260 c:null,
261 s:"(?:1|0)"};
262 case "Y":
263 return {g:1,
264 c:"y = parseInt(results[" + currentGroup + "], 10);\n",
265 s:"(\\d{4})"};
266 case "y":
267 return {g:1,
268 c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
269 + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
270 s:"(\\d{1,2})"};
271 case "a":
272 return {g:1,
273 c:"if (results[" + currentGroup + "] == 'am') {\n"
274 + "if (h == 12) { h = 0; }\n"
275 + "} else { if (h < 12) { h += 12; }}",
276 s:"(am|pm)"};
277 case "A":
278 return {g:1,
279 c:"if (results[" + currentGroup + "] == 'AM') {\n"
280 + "if (h == 12) { h = 0; }\n"
281 + "} else { if (h < 12) { h += 12; }}",
282 s:"(AM|PM)"};
283 case "g":
284 case "G":
285 case "h":
286 case "H":
287 return {g:1,
288 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
289 s:"(\\d{1,2})"};
290 case "i":
291 return {g:1,
292 c:"i = parseInt(results[" + currentGroup + "], 10);\n",
293 s:"(\\d{2})"};
294 case "s":
295 return {g:1,
296 c:"s = parseInt(results[" + currentGroup + "], 10);\n",
297 s:"(\\d{2})"};
298 case "O":
299 return {g:0,
300 c:null,
301 s:"[+-]\\d{4}"};
302 case "T":
303 return {g:0,
304 c:null,
305 s:"[A-Z]{3}"};
306 case "Z":
307 return {g:0,
308 c:null,
309 s:"[+-]\\d{1,5}"};
310 default:
311 return {g:0,
312 c:null,
313 s:String.escape(character)};
317 Date.prototype.getTimezone = function() {
318 return this.toString().replace(
319 /^.*? ([A-Z]{3}) [0-9]{4}.*$/, "$1").replace(
320 /^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, "$1$2$3");
323 Date.prototype.getGMTOffset = function() {
324 return (this.getTimezoneOffset() > 0 ? "-" : "+")
325 + String.leftPad(Math.floor(this.getTimezoneOffset() / 60), 2, "0")
326 + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
329 Date.prototype.getDayOfYear = function() {
330 var num = 0;
331 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
332 for (var i = 0; i < this.getMonth(); ++i) {
333 num += Date.daysInMonth[i];
335 return num + this.getDate() - 1;
338 Date.prototype.getWeekOfYear = function() {
339 // Skip to Thursday of this week
340 var now = this.getDayOfYear() + (4 - this.getDay());
341 // Find the first Thursday of the year
342 var jan1 = new Date(this.getFullYear(), 0, 1);
343 var then = (7 - jan1.getDay() + 4);
344 document.write(then);
345 return String.leftPad(((now - then) / 7) + 1, 2, "0");
348 Date.prototype.isLeapYear = function() {
349 var year = this.getFullYear();
350 return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
353 Date.prototype.getFirstDayOfMonth = function() {
354 var day = (this.getDay() - (this.getDate() - 1)) % 7;
355 return (day < 0) ? (day + 7) : day;
358 Date.prototype.getLastDayOfMonth = function() {
359 var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
360 return (day < 0) ? (day + 7) : day;
363 Date.prototype.getDaysInMonth = function() {
364 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
365 return Date.daysInMonth[this.getMonth()];
368 Date.prototype.getSuffix = function() {
369 switch (this.getDate()) {
370 case 1:
371 case 21:
372 case 31:
373 return "st";
374 case 2:
375 case 22:
376 return "nd";
377 case 3:
378 case 23:
379 return "rd";
380 default:
381 return "th";
385 String.escape = function(string) {
386 return string.replace(/('|\\)/g, "\\$1");
389 String.leftPad = function (val, size, ch) {
390 var result = new String(val);
391 if (ch == null) {
392 ch = " ";
394 while (result.length < size) {
395 result = ch + result;
397 return result;
400 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
401 Date.monthNames =
402 ["January",
403 "February",
404 "March",
405 "April",
406 "May",
407 "June",
408 "July",
409 "August",
410 "September",
411 "October",
412 "November",
413 "December"];
414 Date.dayNames =
415 ["Sunday",
416 "Monday",
417 "Tuesday",
418 "Wednesday",
419 "Thursday",
420 "Friday",
421 "Saturday"];
422 Date.y2kYear = 50;
423 Date.monthNumbers = {
424 Jan:0,
425 Feb:1,
426 Mar:2,
427 Apr:3,
428 May:4,
429 Jun:5,
430 Jul:6,
431 Aug:7,
432 Sep:8,
433 Oct:9,
434 Nov:10,
435 Dec:11};
436 Date.patterns = {
437 ISO8601LongPattern:"Y-m-d H:i:s",
438 ISO8601ShortPattern:"Y-m-d",
439 ShortDatePattern: "n/j/Y",
440 LongDatePattern: "l, F d, Y",
441 FullDateTimePattern: "l, F d, Y g:i:s A",
442 MonthDayPattern: "F d",
443 ShortTimePattern: "g:i A",
444 LongTimePattern: "g:i:s A",
445 SortableDateTimePattern: "Y-m-d\\TH:i:s",
446 UniversalSortableDateTimePattern: "Y-m-d H:i:sO",
447 YearMonthPattern: "F, Y"};
449 var date = new Date("1/1/2007 1:11:11");
451 for (i = 0; i < 4000; ++i) {
452 var shortFormat = date.dateFormat("Y-m-d");
453 var longFormat = date.dateFormat("l, F d, Y g:i:s A");
454 date.setTime(date.getTime() + 84266956);
459 </script>
462 </body>
463 </html>