1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/pgo/js-input/date-format-xparb.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,467 @@ 1.4 +<!DOCTYPE html> 1.5 +<head> 1.6 +<!-- 1.7 + Copyright (C) 2007 Apple Inc. All rights reserved. 1.8 + 1.9 + Redistribution and use in source and binary forms, with or without 1.10 + modification, are permitted provided that the following conditions 1.11 + are met: 1.12 + 1. Redistributions of source code must retain the above copyright 1.13 + notice, this list of conditions and the following disclaimer. 1.14 + 2. Redistributions in binary form must reproduce the above copyright 1.15 + notice, this list of conditions and the following disclaimer in the 1.16 + documentation and/or other materials provided with the distribution. 1.17 + 1.18 + THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 1.19 + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.20 + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.21 + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 1.22 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.23 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.24 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.25 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 1.26 + OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.27 + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.28 + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.29 +--> 1.30 + 1.31 +<title>SunSpider date-format-xparb</title> 1.32 + 1.33 +</head> 1.34 + 1.35 +<body> 1.36 +<h3>date-format-xparb</h3> 1.37 +<div id="console"> 1.38 +</div> 1.39 + 1.40 +<script> 1.41 + 1.42 +var _sunSpiderStartDate = new Date(); 1.43 + 1.44 +/* 1.45 + * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org> 1.46 + * 1.47 + * This program is free software; you can redistribute it and/or modify it 1.48 + * under the terms of the GNU Lesser General Public License as published by the 1.49 + * Free Software Foundation, version 2.1. 1.50 + * 1.51 + * This program is distributed in the hope that it will be useful, but WITHOUT 1.52 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 1.53 + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 1.54 + * details. 1.55 + */ 1.56 + 1.57 +Date.parseFunctions = {count:0}; 1.58 +Date.parseRegexes = []; 1.59 +Date.formatFunctions = {count:0}; 1.60 + 1.61 +Date.prototype.dateFormat = function(format) { 1.62 + if (Date.formatFunctions[format] == null) { 1.63 + Date.createNewFormat(format); 1.64 + } 1.65 + var func = Date.formatFunctions[format]; 1.66 + return this[func](); 1.67 +} 1.68 + 1.69 +Date.createNewFormat = function(format) { 1.70 + var funcName = "format" + Date.formatFunctions.count++; 1.71 + Date.formatFunctions[format] = funcName; 1.72 + var code = "Date.prototype." + funcName + " = function(){return "; 1.73 + var special = false; 1.74 + var ch = ''; 1.75 + for (var i = 0; i < format.length; ++i) { 1.76 + ch = format.charAt(i); 1.77 + if (!special && ch == "\\") { 1.78 + special = true; 1.79 + } 1.80 + else if (special) { 1.81 + special = false; 1.82 + code += "'" + String.escape(ch) + "' + "; 1.83 + } 1.84 + else { 1.85 + code += Date.getFormatCode(ch); 1.86 + } 1.87 + } 1.88 + eval(code.substring(0, code.length - 3) + ";}"); 1.89 +} 1.90 + 1.91 +Date.getFormatCode = function(character) { 1.92 + switch (character) { 1.93 + case "d": 1.94 + return "String.leftPad(this.getDate(), 2, '0') + "; 1.95 + case "D": 1.96 + return "Date.dayNames[this.getDay()].substring(0, 3) + "; 1.97 + case "j": 1.98 + return "this.getDate() + "; 1.99 + case "l": 1.100 + return "Date.dayNames[this.getDay()] + "; 1.101 + case "S": 1.102 + return "this.getSuffix() + "; 1.103 + case "w": 1.104 + return "this.getDay() + "; 1.105 + case "z": 1.106 + return "this.getDayOfYear() + "; 1.107 + case "W": 1.108 + return "this.getWeekOfYear() + "; 1.109 + case "F": 1.110 + return "Date.monthNames[this.getMonth()] + "; 1.111 + case "m": 1.112 + return "String.leftPad(this.getMonth() + 1, 2, '0') + "; 1.113 + case "M": 1.114 + return "Date.monthNames[this.getMonth()].substring(0, 3) + "; 1.115 + case "n": 1.116 + return "(this.getMonth() + 1) + "; 1.117 + case "t": 1.118 + return "this.getDaysInMonth() + "; 1.119 + case "L": 1.120 + return "(this.isLeapYear() ? 1 : 0) + "; 1.121 + case "Y": 1.122 + return "this.getFullYear() + "; 1.123 + case "y": 1.124 + return "('' + this.getFullYear()).substring(2, 4) + "; 1.125 + case "a": 1.126 + return "(this.getHours() < 12 ? 'am' : 'pm') + "; 1.127 + case "A": 1.128 + return "(this.getHours() < 12 ? 'AM' : 'PM') + "; 1.129 + case "g": 1.130 + return "((this.getHours() %12) ? this.getHours() % 12 : 12) + "; 1.131 + case "G": 1.132 + return "this.getHours() + "; 1.133 + case "h": 1.134 + return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + "; 1.135 + case "H": 1.136 + return "String.leftPad(this.getHours(), 2, '0') + "; 1.137 + case "i": 1.138 + return "String.leftPad(this.getMinutes(), 2, '0') + "; 1.139 + case "s": 1.140 + return "String.leftPad(this.getSeconds(), 2, '0') + "; 1.141 + case "O": 1.142 + return "this.getGMTOffset() + "; 1.143 + case "T": 1.144 + return "this.getTimezone() + "; 1.145 + case "Z": 1.146 + return "(this.getTimezoneOffset() * -60) + "; 1.147 + default: 1.148 + return "'" + String.escape(character) + "' + "; 1.149 + } 1.150 +} 1.151 + 1.152 +Date.parseDate = function(input, format) { 1.153 + if (Date.parseFunctions[format] == null) { 1.154 + Date.createParser(format); 1.155 + } 1.156 + var func = Date.parseFunctions[format]; 1.157 + return Date[func](input); 1.158 +} 1.159 + 1.160 +Date.createParser = function(format) { 1.161 + var funcName = "parse" + Date.parseFunctions.count++; 1.162 + var regexNum = Date.parseRegexes.length; 1.163 + var currentGroup = 1; 1.164 + Date.parseFunctions[format] = funcName; 1.165 + 1.166 + var code = "Date." + funcName + " = function(input){\n" 1.167 + + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n" 1.168 + + "var d = new Date();\n" 1.169 + + "y = d.getFullYear();\n" 1.170 + + "m = d.getMonth();\n" 1.171 + + "d = d.getDate();\n" 1.172 + + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n" 1.173 + + "if (results && results.length > 0) {" 1.174 + var regex = ""; 1.175 + 1.176 + var special = false; 1.177 + var ch = ''; 1.178 + for (var i = 0; i < format.length; ++i) { 1.179 + ch = format.charAt(i); 1.180 + if (!special && ch == "\\") { 1.181 + special = true; 1.182 + } 1.183 + else if (special) { 1.184 + special = false; 1.185 + regex += String.escape(ch); 1.186 + } 1.187 + else { 1.188 + obj = Date.formatCodeToRegex(ch, currentGroup); 1.189 + currentGroup += obj.g; 1.190 + regex += obj.s; 1.191 + if (obj.g && obj.c) { 1.192 + code += obj.c; 1.193 + } 1.194 + } 1.195 + } 1.196 + 1.197 + code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n" 1.198 + + "{return new Date(y, m, d, h, i, s);}\n" 1.199 + + "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n" 1.200 + + "{return new Date(y, m, d, h, i);}\n" 1.201 + + "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n" 1.202 + + "{return new Date(y, m, d, h);}\n" 1.203 + + "else if (y > 0 && m >= 0 && d > 0)\n" 1.204 + + "{return new Date(y, m, d);}\n" 1.205 + + "else if (y > 0 && m >= 0)\n" 1.206 + + "{return new Date(y, m);}\n" 1.207 + + "else if (y > 0)\n" 1.208 + + "{return new Date(y);}\n" 1.209 + + "}return null;}"; 1.210 + 1.211 + Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$"); 1.212 + eval(code); 1.213 +} 1.214 + 1.215 +Date.formatCodeToRegex = function(character, currentGroup) { 1.216 + switch (character) { 1.217 + case "D": 1.218 + return {g:0, 1.219 + c:null, 1.220 + s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"}; 1.221 + case "j": 1.222 + case "d": 1.223 + return {g:1, 1.224 + c:"d = parseInt(results[" + currentGroup + "], 10);\n", 1.225 + s:"(\\d{1,2})"}; 1.226 + case "l": 1.227 + return {g:0, 1.228 + c:null, 1.229 + s:"(?:" + Date.dayNames.join("|") + ")"}; 1.230 + case "S": 1.231 + return {g:0, 1.232 + c:null, 1.233 + s:"(?:st|nd|rd|th)"}; 1.234 + case "w": 1.235 + return {g:0, 1.236 + c:null, 1.237 + s:"\\d"}; 1.238 + case "z": 1.239 + return {g:0, 1.240 + c:null, 1.241 + s:"(?:\\d{1,3})"}; 1.242 + case "W": 1.243 + return {g:0, 1.244 + c:null, 1.245 + s:"(?:\\d{2})"}; 1.246 + case "F": 1.247 + return {g:1, 1.248 + c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n", 1.249 + s:"(" + Date.monthNames.join("|") + ")"}; 1.250 + case "M": 1.251 + return {g:1, 1.252 + c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n", 1.253 + s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"}; 1.254 + case "n": 1.255 + case "m": 1.256 + return {g:1, 1.257 + c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n", 1.258 + s:"(\\d{1,2})"}; 1.259 + case "t": 1.260 + return {g:0, 1.261 + c:null, 1.262 + s:"\\d{1,2}"}; 1.263 + case "L": 1.264 + return {g:0, 1.265 + c:null, 1.266 + s:"(?:1|0)"}; 1.267 + case "Y": 1.268 + return {g:1, 1.269 + c:"y = parseInt(results[" + currentGroup + "], 10);\n", 1.270 + s:"(\\d{4})"}; 1.271 + case "y": 1.272 + return {g:1, 1.273 + c:"var ty = parseInt(results[" + currentGroup + "], 10);\n" 1.274 + + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n", 1.275 + s:"(\\d{1,2})"}; 1.276 + case "a": 1.277 + return {g:1, 1.278 + c:"if (results[" + currentGroup + "] == 'am') {\n" 1.279 + + "if (h == 12) { h = 0; }\n" 1.280 + + "} else { if (h < 12) { h += 12; }}", 1.281 + s:"(am|pm)"}; 1.282 + case "A": 1.283 + return {g:1, 1.284 + c:"if (results[" + currentGroup + "] == 'AM') {\n" 1.285 + + "if (h == 12) { h = 0; }\n" 1.286 + + "} else { if (h < 12) { h += 12; }}", 1.287 + s:"(AM|PM)"}; 1.288 + case "g": 1.289 + case "G": 1.290 + case "h": 1.291 + case "H": 1.292 + return {g:1, 1.293 + c:"h = parseInt(results[" + currentGroup + "], 10);\n", 1.294 + s:"(\\d{1,2})"}; 1.295 + case "i": 1.296 + return {g:1, 1.297 + c:"i = parseInt(results[" + currentGroup + "], 10);\n", 1.298 + s:"(\\d{2})"}; 1.299 + case "s": 1.300 + return {g:1, 1.301 + c:"s = parseInt(results[" + currentGroup + "], 10);\n", 1.302 + s:"(\\d{2})"}; 1.303 + case "O": 1.304 + return {g:0, 1.305 + c:null, 1.306 + s:"[+-]\\d{4}"}; 1.307 + case "T": 1.308 + return {g:0, 1.309 + c:null, 1.310 + s:"[A-Z]{3}"}; 1.311 + case "Z": 1.312 + return {g:0, 1.313 + c:null, 1.314 + s:"[+-]\\d{1,5}"}; 1.315 + default: 1.316 + return {g:0, 1.317 + c:null, 1.318 + s:String.escape(character)}; 1.319 + } 1.320 +} 1.321 + 1.322 +Date.prototype.getTimezone = function() { 1.323 + return this.toString().replace( 1.324 + /^.*? ([A-Z]{3}) [0-9]{4}.*$/, "$1").replace( 1.325 + /^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, "$1$2$3"); 1.326 +} 1.327 + 1.328 +Date.prototype.getGMTOffset = function() { 1.329 + return (this.getTimezoneOffset() > 0 ? "-" : "+") 1.330 + + String.leftPad(Math.floor(this.getTimezoneOffset() / 60), 2, "0") 1.331 + + String.leftPad(this.getTimezoneOffset() % 60, 2, "0"); 1.332 +} 1.333 + 1.334 +Date.prototype.getDayOfYear = function() { 1.335 + var num = 0; 1.336 + Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28; 1.337 + for (var i = 0; i < this.getMonth(); ++i) { 1.338 + num += Date.daysInMonth[i]; 1.339 + } 1.340 + return num + this.getDate() - 1; 1.341 +} 1.342 + 1.343 +Date.prototype.getWeekOfYear = function() { 1.344 + // Skip to Thursday of this week 1.345 + var now = this.getDayOfYear() + (4 - this.getDay()); 1.346 + // Find the first Thursday of the year 1.347 + var jan1 = new Date(this.getFullYear(), 0, 1); 1.348 + var then = (7 - jan1.getDay() + 4); 1.349 + document.write(then); 1.350 + return String.leftPad(((now - then) / 7) + 1, 2, "0"); 1.351 +} 1.352 + 1.353 +Date.prototype.isLeapYear = function() { 1.354 + var year = this.getFullYear(); 1.355 + return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year))); 1.356 +} 1.357 + 1.358 +Date.prototype.getFirstDayOfMonth = function() { 1.359 + var day = (this.getDay() - (this.getDate() - 1)) % 7; 1.360 + return (day < 0) ? (day + 7) : day; 1.361 +} 1.362 + 1.363 +Date.prototype.getLastDayOfMonth = function() { 1.364 + var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7; 1.365 + return (day < 0) ? (day + 7) : day; 1.366 +} 1.367 + 1.368 +Date.prototype.getDaysInMonth = function() { 1.369 + Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28; 1.370 + return Date.daysInMonth[this.getMonth()]; 1.371 +} 1.372 + 1.373 +Date.prototype.getSuffix = function() { 1.374 + switch (this.getDate()) { 1.375 + case 1: 1.376 + case 21: 1.377 + case 31: 1.378 + return "st"; 1.379 + case 2: 1.380 + case 22: 1.381 + return "nd"; 1.382 + case 3: 1.383 + case 23: 1.384 + return "rd"; 1.385 + default: 1.386 + return "th"; 1.387 + } 1.388 +} 1.389 + 1.390 +String.escape = function(string) { 1.391 + return string.replace(/('|\\)/g, "\\$1"); 1.392 +} 1.393 + 1.394 +String.leftPad = function (val, size, ch) { 1.395 + var result = new String(val); 1.396 + if (ch == null) { 1.397 + ch = " "; 1.398 + } 1.399 + while (result.length < size) { 1.400 + result = ch + result; 1.401 + } 1.402 + return result; 1.403 +} 1.404 + 1.405 +Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31]; 1.406 +Date.monthNames = 1.407 + ["January", 1.408 + "February", 1.409 + "March", 1.410 + "April", 1.411 + "May", 1.412 + "June", 1.413 + "July", 1.414 + "August", 1.415 + "September", 1.416 + "October", 1.417 + "November", 1.418 + "December"]; 1.419 +Date.dayNames = 1.420 + ["Sunday", 1.421 + "Monday", 1.422 + "Tuesday", 1.423 + "Wednesday", 1.424 + "Thursday", 1.425 + "Friday", 1.426 + "Saturday"]; 1.427 +Date.y2kYear = 50; 1.428 +Date.monthNumbers = { 1.429 + Jan:0, 1.430 + Feb:1, 1.431 + Mar:2, 1.432 + Apr:3, 1.433 + May:4, 1.434 + Jun:5, 1.435 + Jul:6, 1.436 + Aug:7, 1.437 + Sep:8, 1.438 + Oct:9, 1.439 + Nov:10, 1.440 + Dec:11}; 1.441 +Date.patterns = { 1.442 + ISO8601LongPattern:"Y-m-d H:i:s", 1.443 + ISO8601ShortPattern:"Y-m-d", 1.444 + ShortDatePattern: "n/j/Y", 1.445 + LongDatePattern: "l, F d, Y", 1.446 + FullDateTimePattern: "l, F d, Y g:i:s A", 1.447 + MonthDayPattern: "F d", 1.448 + ShortTimePattern: "g:i A", 1.449 + LongTimePattern: "g:i:s A", 1.450 + SortableDateTimePattern: "Y-m-d\\TH:i:s", 1.451 + UniversalSortableDateTimePattern: "Y-m-d H:i:sO", 1.452 + YearMonthPattern: "F, Y"}; 1.453 + 1.454 +var date = new Date("1/1/2007 1:11:11"); 1.455 + 1.456 +for (i = 0; i < 4000; ++i) { 1.457 + var shortFormat = date.dateFormat("Y-m-d"); 1.458 + var longFormat = date.dateFormat("l, F d, Y g:i:s A"); 1.459 + date.setTime(date.getTime() + 84266956); 1.460 +} 1.461 + 1.462 + 1.463 +var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 1.464 + 1.465 +document.getElementById("console").innerHTML = _sunSpiderInterval; 1.466 +</script> 1.467 + 1.468 + 1.469 +</body> 1.470 +</html>