1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/pgo/js-input/date-format-tofte.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,349 @@ 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-tofte</title> 1.32 + 1.33 +</head> 1.34 + 1.35 +<body> 1.36 +<h3>date-format-tofte</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 +function arrayExists(array, x) { 1.45 + for (var i = 0; i < array.length; i++) { 1.46 + if (array[i] == x) return true; 1.47 + } 1.48 + return false; 1.49 +} 1.50 + 1.51 +Date.prototype.formatDate = function (input,time) { 1.52 + // formatDate : 1.53 + // a PHP date like function, for formatting date strings 1.54 + // See: http://www.php.net/date 1.55 + // 1.56 + // input : format string 1.57 + // time : epoch time (seconds, and optional) 1.58 + // 1.59 + // if time is not passed, formatting is based on 1.60 + // the current "this" date object's set time. 1.61 + // 1.62 + // supported: 1.63 + // a, A, B, d, D, F, g, G, h, H, i, j, l (lowercase L), L, 1.64 + // m, M, n, O, r, s, S, t, U, w, W, y, Y, z 1.65 + // 1.66 + // unsupported: 1.67 + // I (capital i), T, Z 1.68 + 1.69 + var switches = ["a", "A", "B", "d", "D", "F", "g", "G", "h", "H", 1.70 + "i", "j", "l", "L", "m", "M", "n", "O", "r", "s", 1.71 + "S", "t", "U", "w", "W", "y", "Y", "z"]; 1.72 + var daysLong = ["Sunday", "Monday", "Tuesday", "Wednesday", 1.73 + "Thursday", "Friday", "Saturday"]; 1.74 + var daysShort = ["Sun", "Mon", "Tue", "Wed", 1.75 + "Thu", "Fri", "Sat"]; 1.76 + var monthsShort = ["Jan", "Feb", "Mar", "Apr", 1.77 + "May", "Jun", "Jul", "Aug", "Sep", 1.78 + "Oct", "Nov", "Dec"]; 1.79 + var monthsLong = ["January", "February", "March", "April", 1.80 + "May", "June", "July", "August", "September", 1.81 + "October", "November", "December"]; 1.82 + var daysSuffix = ["st", "nd", "rd", "th", "th", "th", "th", // 1st - 7th 1.83 + "th", "th", "th", "th", "th", "th", "th", // 8th - 14th 1.84 + "th", "th", "th", "th", "th", "th", "st", // 15th - 21st 1.85 + "nd", "rd", "th", "th", "th", "th", "th", // 22nd - 28th 1.86 + "th", "th", "st"]; // 29th - 31st 1.87 + 1.88 + function a() { 1.89 + // Lowercase Ante meridiem and Post meridiem 1.90 + return self.getHours() > 11? "pm" : "am"; 1.91 + } 1.92 + function A() { 1.93 + // Uppercase Ante meridiem and Post meridiem 1.94 + return self.getHours() > 11? "PM" : "AM"; 1.95 + } 1.96 + 1.97 + function B(){ 1.98 + // Swatch internet time. code simply grabbed from ppk, 1.99 + // since I was feeling lazy: 1.100 + // http://www.xs4all.nl/~ppk/js/beat.html 1.101 + var off = (self.getTimezoneOffset() + 60)*60; 1.102 + var theSeconds = (self.getHours() * 3600) + 1.103 + (self.getMinutes() * 60) + 1.104 + self.getSeconds() + off; 1.105 + var beat = Math.floor(theSeconds/86.4); 1.106 + if (beat > 1000) beat -= 1000; 1.107 + if (beat < 0) beat += 1000; 1.108 + if ((""+beat).length == 1) beat = "00"+beat; 1.109 + if ((""+beat).length == 2) beat = "0"+beat; 1.110 + return beat; 1.111 + } 1.112 + 1.113 + function d() { 1.114 + // Day of the month, 2 digits with leading zeros 1.115 + return new String(self.getDate()).length == 1? 1.116 + "0"+self.getDate() : self.getDate(); 1.117 + } 1.118 + function D() { 1.119 + // A textual representation of a day, three letters 1.120 + return daysShort[self.getDay()]; 1.121 + } 1.122 + function F() { 1.123 + // A full textual representation of a month 1.124 + return monthsLong[self.getMonth()]; 1.125 + } 1.126 + function g() { 1.127 + // 12-hour format of an hour without leading zeros 1.128 + return self.getHours() > 12? self.getHours()-12 : self.getHours(); 1.129 + } 1.130 + function G() { 1.131 + // 24-hour format of an hour without leading zeros 1.132 + return self.getHours(); 1.133 + } 1.134 + function h() { 1.135 + // 12-hour format of an hour with leading zeros 1.136 + if (self.getHours() > 12) { 1.137 + var s = new String(self.getHours()-12); 1.138 + return s.length == 1? 1.139 + "0"+ (self.getHours()-12) : self.getHours()-12; 1.140 + } else { 1.141 + var s = new String(self.getHours()); 1.142 + return s.length == 1? 1.143 + "0"+self.getHours() : self.getHours(); 1.144 + } 1.145 + } 1.146 + function H() { 1.147 + // 24-hour format of an hour with leading zeros 1.148 + return new String(self.getHours()).length == 1? 1.149 + "0"+self.getHours() : self.getHours(); 1.150 + } 1.151 + function i() { 1.152 + // Minutes with leading zeros 1.153 + return new String(self.getMinutes()).length == 1? 1.154 + "0"+self.getMinutes() : self.getMinutes(); 1.155 + } 1.156 + function j() { 1.157 + // Day of the month without leading zeros 1.158 + return self.getDate(); 1.159 + } 1.160 + function l() { 1.161 + // A full textual representation of the day of the week 1.162 + return daysLong[self.getDay()]; 1.163 + } 1.164 + function L() { 1.165 + // leap year or not. 1 if leap year, 0 if not. 1.166 + // the logic should match iso's 8601 standard. 1.167 + var y_ = Y(); 1.168 + if ( 1.169 + (y_ % 4 == 0 && y_ % 100 != 0) || 1.170 + (y_ % 4 == 0 && y_ % 100 == 0 && y_ % 400 == 0) 1.171 + ) { 1.172 + return 1; 1.173 + } else { 1.174 + return 0; 1.175 + } 1.176 + } 1.177 + function m() { 1.178 + // Numeric representation of a month, with leading zeros 1.179 + return self.getMonth() < 9? 1.180 + "0"+(self.getMonth()+1) : 1.181 + self.getMonth()+1; 1.182 + } 1.183 + function M() { 1.184 + // A short textual representation of a month, three letters 1.185 + return monthsShort[self.getMonth()]; 1.186 + } 1.187 + function n() { 1.188 + // Numeric representation of a month, without leading zeros 1.189 + return self.getMonth()+1; 1.190 + } 1.191 + function O() { 1.192 + // Difference to Greenwich time (GMT) in hours 1.193 + var os = Math.abs(self.getTimezoneOffset()); 1.194 + var h = ""+Math.floor(os/60); 1.195 + var m = ""+(os%60); 1.196 + h.length == 1? h = "0"+h:1; 1.197 + m.length == 1? m = "0"+m:1; 1.198 + return self.getTimezoneOffset() < 0 ? "+"+h+m : "-"+h+m; 1.199 + } 1.200 + function r() { 1.201 + // RFC 822 formatted date 1.202 + var r; // result 1.203 + // Thu , 21 Dec 2000 1.204 + r = D() + ", " + j() + " " + M() + " " + Y() + 1.205 + // 16 : 01 : 07 +0200 1.206 + " " + H() + ":" + i() + ":" + s() + " " + O(); 1.207 + return r; 1.208 + } 1.209 + function S() { 1.210 + // English ordinal suffix for the day of the month, 2 characters 1.211 + return daysSuffix[self.getDate()-1]; 1.212 + } 1.213 + function s() { 1.214 + // Seconds, with leading zeros 1.215 + return new String(self.getSeconds()).length == 1? 1.216 + "0"+self.getSeconds() : self.getSeconds(); 1.217 + } 1.218 + function t() { 1.219 + 1.220 + // thanks to Matt Bannon for some much needed code-fixes here! 1.221 + var daysinmonths = [null,31,28,31,30,31,30,31,31,30,31,30,31]; 1.222 + if (L()==1 && n()==2) return 29; // leap day 1.223 + return daysinmonths[n()]; 1.224 + } 1.225 + function U() { 1.226 + // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1.227 + return Math.round(self.getTime()/1000); 1.228 + } 1.229 + function W() { 1.230 + // Weeknumber, as per ISO specification: 1.231 + // http://www.cl.cam.ac.uk/~mgk25/iso-time.html 1.232 + 1.233 + // if the day is three days before newyears eve, 1.234 + // there's a chance it's "week 1" of next year. 1.235 + // here we check for that. 1.236 + var beforeNY = 364+L() - z(); 1.237 + var afterNY = z(); 1.238 + var weekday = w()!=0?w()-1:6; // makes sunday (0), into 6. 1.239 + if (beforeNY <= 2 && weekday <= 2-beforeNY) { 1.240 + return 1; 1.241 + } 1.242 + // similarly, if the day is within threedays of newyears 1.243 + // there's a chance it belongs in the old year. 1.244 + var ny = new Date("January 1 " + Y() + " 00:00:00"); 1.245 + var nyDay = ny.getDay()!=0?ny.getDay()-1:6; 1.246 + if ( 1.247 + (afterNY <= 2) && 1.248 + (nyDay >=4) && 1.249 + (afterNY >= (6-nyDay)) 1.250 + ) { 1.251 + // Since I'm not sure we can just always return 53, 1.252 + // i call the function here again, using the last day 1.253 + // of the previous year, as the date, and then just 1.254 + // return that week. 1.255 + var prevNY = new Date("December 31 " + (Y()-1) + " 00:00:00"); 1.256 + return prevNY.formatDate("W"); 1.257 + } 1.258 + 1.259 + // week 1, is the week that has the first thursday in it. 1.260 + // note that this value is not zero index. 1.261 + if (nyDay <= 3) { 1.262 + // first day of the year fell on a thursday, or earlier. 1.263 + return 1 + Math.floor( ( z() + nyDay ) / 7 ); 1.264 + } else { 1.265 + // first day of the year fell on a friday, or later. 1.266 + return 1 + Math.floor( ( z() - ( 7 - nyDay ) ) / 7 ); 1.267 + } 1.268 + } 1.269 + function w() { 1.270 + // Numeric representation of the day of the week 1.271 + return self.getDay(); 1.272 + } 1.273 + 1.274 + function Y() { 1.275 + // A full numeric representation of a year, 4 digits 1.276 + 1.277 + // we first check, if getFullYear is supported. if it 1.278 + // is, we just use that. ppks code is nice, but wont 1.279 + // work with dates outside 1900-2038, or something like that 1.280 + if (self.getFullYear) { 1.281 + var newDate = new Date("January 1 2001 00:00:00 +0000"); 1.282 + var x = newDate .getFullYear(); 1.283 + if (x == 2001) { 1.284 + // i trust the method now 1.285 + return self.getFullYear(); 1.286 + } 1.287 + } 1.288 + // else, do this: 1.289 + // codes thanks to ppk: 1.290 + // http://www.xs4all.nl/~ppk/js/introdate.html 1.291 + var x = self.getYear(); 1.292 + var y = x % 100; 1.293 + y += (y < 38) ? 2000 : 1900; 1.294 + return y; 1.295 + } 1.296 + function y() { 1.297 + // A two-digit representation of a year 1.298 + var y = Y()+""; 1.299 + return y.substring(y.length-2,y.length); 1.300 + } 1.301 + function z() { 1.302 + // The day of the year, zero indexed! 0 through 366 1.303 + var t = new Date("January 1 " + Y() + " 00:00:00"); 1.304 + var diff = self.getTime() - t.getTime(); 1.305 + return Math.floor(diff/1000/60/60/24); 1.306 + } 1.307 + 1.308 + var self = this; 1.309 + if (time) { 1.310 + // save time 1.311 + var prevTime = self.getTime(); 1.312 + self.setTime(time); 1.313 + } 1.314 + 1.315 + var ia = input.split(""); 1.316 + var ij = 0; 1.317 + while (ia[ij]) { 1.318 + if (ia[ij] == "\\") { 1.319 + // this is our way of allowing users to escape stuff 1.320 + ia.splice(ij,1); 1.321 + } else { 1.322 + if (arrayExists(switches,ia[ij])) { 1.323 + ia[ij] = eval(ia[ij] + "()"); 1.324 + } 1.325 + } 1.326 + ij++; 1.327 + } 1.328 + // reset time, back to what it was 1.329 + if (prevTime) { 1.330 + self.setTime(prevTime); 1.331 + } 1.332 + return ia.join(""); 1.333 +} 1.334 + 1.335 +var date = new Date("1/1/2007 1:11:11"); 1.336 + 1.337 +for (i = 0; i < 500; ++i) { 1.338 + var shortFormat = date.formatDate("Y-m-d"); 1.339 + var longFormat = date.formatDate("l, F d, Y g:i:s A"); 1.340 + date.setTime(date.getTime() + 84266956); 1.341 +} 1.342 + 1.343 + 1.344 + 1.345 +var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 1.346 + 1.347 +document.getElementById("console").innerHTML = _sunSpiderInterval; 1.348 +</script> 1.349 + 1.350 + 1.351 +</body> 1.352 +</html>