1/* 2 * More info at: http://phpjs.org 3 * 4 * This is version: 2.71 5 * php.js is copyright 2009 Kevin van Zonneveld. 6 * 7 * Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld 8 * (http://kevin.vanzonneveld.net), Onno Marsman, Michael White 9 * (http://getsprink.com), Waldo Malqui Silva, Paulo Ricardo F. Santos, Jack, 10 * Philip Peterson, Jonas Raoni Soares Silva (http://www.jsfromhell.com), 11 * Legaev Andrey, Ates Goral (http://magnetiq.com), Martijn Wieringa, Nate, 12 * Enrique Gonzalez, Philippe Baumann, Webtoolkit.info 13 * (http://www.webtoolkit.info/), Theriault, Jani Hartikainen, Ash Searle 14 * (http://hexmen.com/blog/), Carlos R. L. Rodrigues 15 * (http://www.jsfromhell.com), Ole Vrijenhoek, travc, Michael Grier, GeekFG 16 * (http://geekfg.blogspot.com), Johnny Mast (http://www.phpvrouwen.nl), Alex, 17 * d3x, stag019, Andrea Giammarchi (http://webreflection.blogspot.com), 18 * marrtins, Erkekjetter, Steve Hilder, Oleg Eremeev, David, Marc Palau, 19 * Steven Levithan (http://blog.stevenlevithan.com), gorthaur, Arpad Ray 20 * (mailto:[email protected]), Public Domain (http://www.json.org/json2.js), 21 * gettimeofday, mdsjack (http://www.mdsjack.bo.it), Thunder.m, Alfonso 22 * Jimenez (http://www.alfonsojimenez.com), KELAN, Tyler Akins 23 * (http://rumkin.com), Mirek Slugen, Kankrelune 24 * (http://www.webfaktory.info/), Karol Kowalski, AJ, Lars Fischer, Caio 25 * Ariede (http://caioariede.com), Aman Gupta, Sakimori, Pellentesque 26 * Malesuada, Breaking Par Consulting Inc 27 * (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7), 28 * Josh Fraser 29 * (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/), 30 * Paul, madipta, Douglas Crockford (http://javascript.crockford.com), Ole 31 * Vrijenhoek (http://www.nervous.nl/), Hyam Singer 32 * (http://www.impact-computing.com/), Raphael (Ao RUDLER), kenneth, T. Wild, 33 * nobbler, class_exists, noname, Marco, David James, Steve Clay, marc andreu, 34 * ger, john (http://www.jd-tech.net), mktime, Brad Touesnard, J A R, djmix, 35 * Lincoln Ramsay, Linuxworld, Thiago Mata (http://thiagomata.blog.com), 36 * Pyerre, Jon Hohle, Bayron Guevara, duncan, Sanjoy Roy, sankai, 0m3r, Felix 37 * Geisendoerfer (http://www.debuggable.com/felix), Gilbert, Subhasis Deb, 38 * Soren Hansen, T0bsn, Eugene Bulkin (http://doubleaw.com/), Der Simon 39 * (http://innerdom.sourceforge.net/), JB, LH, Marc Jansen, Francesco, echo is 40 * bad, XoraX (http://www.xorax.info), MeEtc (http://yass.meetcweb.com), 41 * Peter-Paul Koch (http://www.quirksmode.org/js/beat.html), Nathan, Tim Wiel, 42 * Ozh, David Randall, Bryan Elliott, Jalal Berrami, Arno, Rick Waldron, 43 * Mick@el, rezna, Kirk Strobeck, Martin Pool, Daniel Esteban, Saulo Vallory, 44 * Kristof Coomans (SCK-CEN Belgian Nucleair Research Centre), Pierre-Luc 45 * Paour, Eric Nagel, Bobby Drake, penutbutterjelly, Christian Doebler, 46 * setcookie, Gabriel Paderni, Simon Willison (http://simonwillison.net), Pul, 47 * Luke Godfrey, Blues (http://tech.bluesmoon.info/), Anton Ongson, Jason Wong 48 * (http://carrot.org/), Valentina De Rosa, sowberry, hitwork, Norman "zEh" 49 * Fuchs, Yves Sucaet, johnrembo, Nick Callen, ejsanders, Aidan Lister 50 * (http://aidanlister.com/), Philippe Jausions 51 * (http://pear.php.net/user/jausions), dptr1988, Pedro Tainha 52 * (http://www.pedrotainha.com), Alan C, uestla, Wagner B. Soares, T.Wild, 53 * strcasecmp, strcmp, DxGx, Alexander Ermolaev 54 * (http://snippets.dzone.com/user/AlexanderErmolaev), ChaosNo1, metjay, YUI 55 * Library: http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, 56 * Blues at http://hacks.bluesmoon.info/strftime/strftime.js, taith, Robin, 57 * Matt Bradley, Tim de Koning, Luis Salazar (http://www.freaky-media.com/), 58 * FGFEmperor, baris ozdil, Tod Gentille, FremyCompany, Manish, Cord, Slawomir 59 * Kaniecki, ReverseSyntax, Mateusz "loonquawl" Zalega, Scott Cariss, 60 * Francois, Victor, stensi, vlado houba, date, gabriel paderni, Yannoo, 61 * mk.keck, Leslie Hoare, Ben Bryan, Dino, Andrej Pavlovic, Andreas, DtTvB 62 * (http://dt.in.th/2008-09-16.string-length-in-bytes.html), Russell Walker, 63 * Garagoth, booeyOH, Cagri Ekin, Benjamin Lupton, davook, Atli Ãór, jakes, 64 * Allan Jensen (http://www.winternet.no), Howard Yeend, Kheang Hok Chin
65 * (http://www.distantia.ca/), Luke Smith (http://lucassmith.name), Rival, 66 * Diogo Resende 67 * 68 * Dual licensed under the MIT (MIT-LICENSE.txt) 69 * and GPL (GPL-LICENSE.txt) licenses. 70 * 71 * Permission is hereby granted, free of charge, to any person obtaining a 72 * copy of this software and associated documentation files (the 73 * "Software"), to deal in the Software without restriction, including 74 * without limitation the rights to use, copy, modify, merge, publish, 75 * distribute, sublicense, and/or sell copies of the Software, and to 76 * permit persons to whom the Software is furnished to do so, subject to 77 * the following conditions: 78 * 79 * The above copyright notice and this permission notice shall be included 80 * in all copies or substantial portions of the Software. 81 * 82 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 83 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 84 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 85 * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES 86 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 87 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 88 * OTHER DEALINGS IN THE SOFTWARE. 89 */ 90 91 if ("undefined" == typeof PHPJS) { 92 93 PHPJS = 1; 94 95 96 function date(format, timestamp) { 97 // http://kevin.vanzonneveld.net 98 // + original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com) 99 // + parts by: Peter-Paul Koch (http://www.quirksmode.org/js/beat.html) 100 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 101 // + improved by: MeEtc (http://yass.meetcweb.com) 102 // + improved by: Brad Touesnard 103 // + improved by: Tim Wiel 104 // + improved by: Bryan Elliott 105 // 106 // + improved by: Brett Zamir (http://brett-zamir.me) 107 // + improved by: David Randall 108 // + input by: Brett Zamir (http://brett-zamir.me) 109 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 110 // + improved by: Brett Zamir (http://brett-zamir.me) 111 // + improved by: Brett Zamir (http://brett-zamir.me) 112 // + improved by: Theriault 113 // + derived from: gettimeofday 114 // + input by: majak 115 // + bugfixed by: majak 116 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 117 // + input by: Alex 118 // + bugfixed by: Brett Zamir (http://brett-zamir.me) 119 // + improved by: Theriault 120 // + improved by: Brett Zamir (http://brett-zamir.me) 121 // + improved by: Theriault 122 // + improved by: Thomas Beaucourt (http://www.webapp.fr) 123 // + improved by: JT 124 // + improved by: Theriault 125 // + improved by: RafaÅ Kukawski (http://blog.kukawski.pl) 126 // % note 1: Uses global: php_js to store the default timezone 127 // % note 2: Although the function potentially allows timezone info (see notes), it currently does not set 128 // % note 2: per a timezone specified by date_default_timezone_set(). Implementers might use 129 // % note 2: this.php_js.currentTimezoneOffset and this.php_js.currentTimezoneDST set by that function 130 // % note 2: in order to adjust the dates in this function (or our other date functions!) accordingly 131 // * example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400); 132 // * returns 1: '09:09:40 m is month' 133 // * example 2: date('F j, Y, g:i a', 1062462400); 134 // * returns 2: 'September 2, 2003, 2:26 am' 135 // * example 3: date('Y W o', 1062462400); 136 // * returns 3: '2003 36 2003' 137 // * example 4: x = date('Y m d', (new Date()).getTime()/1000); 138 // * example 4: (x+'').length == 10 // 2009 01 09 139 // * returns 4: true 140 // * example 5: date('W', 1104534000); 141 // * returns 5: '53' 142 // * example 6: date('B t', 1104534000); 143 // * returns 6: '999 31' 144 // * example 7: date('W U', 1293750000.82); // 2010-12-31 145 // * returns 7: '52 1293750000' 146 // * example 8: date('W', 1293836400); // 2011-01-01 147 // * returns 8: '52' 148 // * example 9: date('W Y-m-d', 1293974054); // 2011-01-02 149 // * returns 9: '52 2011-01-02' 150 var that = this, 151 jsdate, f, formatChr = /\\?([a-z])/gi, formatChrCb, 152 // Keep this here (works, but for code commented-out 153 // below for file size reasons) 154 //, tal= [], 155 _pad = function (n, c) { 156 if ((n = n + "").length < c) { 157 return new Array((++c) - n.length).join("0") + n; 158 } else { 159 return n; 160 } 161 }, 162 txt_words = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", 163 "January", "February", "March", "April", "May", "June", "July",
164 "August", "September", "October", "November", "December"], 165 txt_ordin = { 166 1: "st", 167 2: "nd", 168 3: "rd", 169 21: "st", 170 22: "nd", 171 23: "rd", 172 31: "st" 173 }; 174 formatChrCb = function (t, s) { 175 return f[t] ? f[t]() : s; 176 }; 177 f = { 178 // Day 179 d: function () { // Day of month w/leading 0; 01..31 180 return _pad(f.j(), 2); 181 }, 182 D: function () { // Shorthand day name; Mon...Sun 183 return f.l().slice(0, 3); 184 }, 185 j: function () { // Day of month; 1..31 186 return jsdate.getDate(); 187 }, 188 l: function () { // Full day name; Monday...Sunday 189 return txt_words[f.w()] + 'day'; 190 }, 191 N: function () { // ISO-8601 day of week; 1[Mon]..7[Sun] 192 return f.w() || 7; 193 }, 194 S: function () { // Ordinal suffix for day of month; st, nd, rd, th 195 return txt_ordin[f.j()] || 'th'; 196 }, 197 w: function () { // Day of week; 0[Sun]..6[Sat] 198 return jsdate.getDay(); 199 }, 200 z: function () { // Day of year; 0..365 201 var a = new Date(f.Y(), f.n() - 1, f.j()), 202 b = new Date(f.Y(), 0, 1); 203 return Math.round((a - b) / 864e5) + 1; 204 }, 205 206 // Week 207 W: function () { // ISO-8601 week number 208 var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3), 209 b = new Date(a.getFullYear(), 0, 4); 210 return 1 + Math.round((a - b) / 864e5 / 7); 211 }, 212 213 // Month 214 F: function () { // Full month name; January...December 215 return txt_words[6 + f.n()]; 216 }, 217 m: function () { // Month w/leading 0; 01...12 218 return _pad(f.n(), 2); 219 }, 220 M: function () { // Shorthand month name; Jan...Dec 221 return f.F().slice(0, 3); 222 }, 223 n: function () { // Month; 1...12 224 return jsdate.getMonth() + 1; 225 }, 226 t: function () { // Days in month; 28...31 227 return (new Date(f.Y(), f.n(), 0)).getDate(); 228 }, 229 230 // Year 231 L: function () { // Is leap year?; 0 or 1 232 var y = f.Y(), a = y & 3, b = y % 4e2, c = y % 1e2; 233 return 0 + (!a && (c || !b)); 234 }, 235 o: function () { // ISO-8601 year 236 var n = f.n(), W = f.W(), Y = f.Y(); 237 return Y + (n === 12 && W < 9 ? -1 : n === 1 && W > 9); 238 }, 239 Y: function () { // Full year; e.g. 1980...2010 240 return jsdate.getFullYear(); 241 }, 242 y: function () { // Last two digits of year; 00...99 243 return (f.Y() + "").slice(-2); 244 }, 245 246 // Time 247 a: function () { // am or pm 248 return jsdate.getHours() > 11 ? "pm" : "am"; 249 }, 250 A: function () { // AM or PM 251 return f.a().toUpperCase(); 252 }, 253 B: function () { // Swatch Internet time; 000..999 254 var H = jsdate.getUTCHours() * 36e2, // Hours 255 i = jsdate.getUTCMinutes() * 60, // Minutes 256 s = jsdate.getUTCSeconds(); // Seconds 257 return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3); 258 }, 259 g: function () { // 12-Hours; 1..12 260 return f.G() % 12 || 12; 261 }, 262 G: function () { // 24-Hours; 0..23 263 return jsdate.getHours(); 264 }, 265 h: function () { // 12-Hours w/leading 0; 01..12 266 return _pad(f.g(), 2); 267 }, 268 H: function () { // 24-Hours w/leading 0; 00..23 269 return _pad(f.G(), 2); 270 }, 271 i: function () { // Minutes w/leading 0; 00..59 272 return _pad(jsdate.getMinutes(), 2); 273 }, 274 s: function () { // Seconds w/leading 0; 00..59 275 return _pad(jsdate.getSeconds(), 2); 276 }, 277 u: function () { // Microseconds; 000000-999000 278 return _pad(jsdate.getMilliseconds() * 1000, 6); 279 }, 280 281 // Timezone 282 e: function () { // Timezone identifier; e.g. Atlantic/Azores, ... 283 // The following works, but requires inclusion of the very large 284 // timezone_abbreviations_list() function. 285 /* return this.date_default_timezone_get(); 286 */ 287 throw 'Not supported (see source code of date() for timezone on how to add support)'; 288 }, 289 I: function () { // DST observed?; 0 or 1 290 // Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC. 291 // If they are not equal, then DST is observed. 292 var a = new Date(f.Y(), 0), // Jan 1 293 c = Date.UTC(f.Y(), 0), // Jan 1 UTC 294 b = new Date(f.Y(), 6), // Jul 1 295 d = Date.UTC(f.Y(), 6); // Jul 1 UTC 296 return 0 + ((a - c) !== (b - d)); 297 }, 298 O: function () { // Difference to GMT in hour format; e.g. +0200 299 var a = jsdate.getTimezoneOffset(); 300 return (a > 0 ? "-" : "+") + _pad(Math.abs(a / 60 * 100), 4); 301 }, 302 P: function () { // Difference to GMT w/colon; e.g. +02:00 303 var O = f.O(); 304 return (O.substr(0, 3) + ":" + O.substr(3, 2)); 305 }, 306 T: function () { // Timezone abbreviation; e.g. EST, MDT, ... 307 // The following works, but requires inclusion of the very 308 // large timezone_abbreviations_list() function. 309 /* var abbr = '', i = 0, os = 0, default = 0; 310 if (!tal.length) { 311 tal = that.timezone_abbreviations_list(); 312 } 313 if (that.php_js && that.php_js.default_timezone) { 314 default = that.php_js.default_timezone; 315 for (abbr in tal) { 316 for (i=0; i < tal[abbr].length; i++) { 317 if (tal[abbr][i].timezone_id === default) { 318 return abbr.toUpperCase(); 319 } 320 } 321 } 322 } 323 for (abbr in tal) { 324 for (i = 0; i < tal[abbr].length; i++) { 325 os = -jsdate.getTimezoneOffset() * 60; 326 if (tal[abbr][i].offset === os) { 327 return abbr.toUpperCase(); 328 } 329 } 330 } 331 */ 332 return 'UTC'; 333 }, 334 Z: function () { // Timezone offset in seconds (-43200...50400) 335 return -jsdate.getTimezoneOffset() * 60; 336 }, 337 338 // Full Date/Time 339 c: function () { // ISO-8601 date. 340 return 'Y-m-d\\Th:i:sP'.replace(formatChr, formatChrCb); 341 }, 342 r: function () { // RFC 2822 343 return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb); 344 }, 345 U: function () { // Seconds since UNIX epoch 346 return jsdate.getTime() / 1000 | 0; 347 } 348 }; 349 this.date = function (format, timestamp) { 350 that = this; 351 jsdate = ( 352 (typeof timestamp === 'undefined') ? new Date() : // Not provided 353 (timestamp instanceof Date) ? new Date(timestamp) : // JS Date() 354 new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int) 355 ); 356 return format.replace(formatChr, formatChrCb); 357 }; 358 return this.date(format, timestamp); 359 } 360 361 362 function mktime() { 363 // Get UNIX timestamp for a date 364 // 365 // version: 1008.1718 366 // discuss at: http://phpjs.org/functions/mktime // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 367 // + improved by: baris ozdil 368 // + input by: gabriel paderni 369 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 370 // + improved by: FGFEmperor // + input by: Yannoo 371 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 372 // + input by: jakes 373 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 374 // + bugfixed by: Marc Palau // + improved by: Brett Zamir (http://brett-zamir.me) 375 // + input by: 3D-GRAF 376 // + bugfixed by: Brett Zamir (http://brett-zamir.me) 377 // + input by: Chris 378 // + revised by: Theriault // % note 1: The return values of the following examples are 379 // % note 1: received only if your system's timezone is UTC. 380 // * example 1: mktime(14, 10, 2, 2, 1, 2008); 381 // * returns 1: 1201875002 382 // * example 2: mktime(0, 0, 0, 0, 1, 2008); // * returns 2: 1196467200 383 // * example 3: make = mktime(); 384 // * example 3: td = new Date(); 385 // * example 3: real = Math.floor(td.getTime() / 1000); 386 // * example 3: diff = (real - make); // * results 3: diff < 5 387 // * example 4: mktime(0, 0, 0, 13, 1, 1997) 388 // * returns 4: 883612800 389 // * example 5: mktime(0, 0, 0, 1, 1, 1998) 390 // * returns 5: 883612800 // * example 6: mktime(0, 0, 0, 1, 1, 98) 391 // * returns 6: 883612800 392 // * example 7: mktime(23, 59, 59, 13, 0, 2010) 393 // * returns 7: 1293839999 394 // * example 8: mktime(0, 0, -1, 1, 1, 1970) // * returns 8: -1 395 var d = new Date(), r = arguments, i = 0, 396 e = ['Hours', 'Minutes', 'Seconds', 'Month', 'Date', 'FullYear']; 397 398 for (i = 0; i < e.length; i++) { if (typeof r[i] === 'undefined') { 399 r[i] = d['get' + e[i]](); 400 r[i] += (i === 3); // +1 to fix JS months. 401 } else { 402 r[i] = parseInt(r[i], 10); if (isNaN(r[i])) { 403 return false;
404 } 405 } 406 } 407 408 // Map years 0-69 to 2000-2069 and years 70-100 to 1970-2000. 409 r[5] += (r[5] >= 0 ? (r[5] <= 69 ? 2e3 : (r[5] <= 100 ? 1900 : 0)) : 0); 410 411 /* DEPRECATED 412 // Set year, month (-1 to fix JS months), and date. // !This must come before the call to setHours! 413 d.setFullYear(r[5], r[3] - 1, r[4]); 414 */ 415 d.setYear(r[5]); 416 d.setMonth(r[3] - 1); 417 d.setDate(r[4]); 418 // Set hours, minutes, and seconds. 419 d.setHours(r[0], r[1], r[2]); 420 // Divide milliseconds by 1000 to return seconds and drop decimal. 421 // Add 1 second if negative or it'll be off from PHP by 1 second. 422 return (d.getTime() / 1e3 >> 0) - (d.getTime() < 0); 423 } 424 425}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.