build/pgo/js-input/date-format-xparb.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial