1function date (format, timestamp) { 2 // http://kevin.vanzonneveld.net 3 // + original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com) 4 // + parts by: Peter-Paul Koch (http://www.quirksmode.org/js/beat.html) 5 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 6 // + improved by: MeEtc (http://yass.meetcweb.com) 7 // + improved by: Brad Touesnard 8 // + improved by: Tim Wiel 9 // + improved by: Bryan Elliott 10 // 11 // + improved by: Brett Zamir (http://brett-zamir.me) 12 // + improved by: David Randall 13 // + input by: Brett Zamir (http://brett-zamir.me) 14 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 15 // + improved by: Brett Zamir (http://brett-zamir.me) 16 // + improved by: Brett Zamir (http://brett-zamir.me) 17 // + improved by: Theriault 18 // + derived from: gettimeofday 19 // + input by: majak 20 // + bugfixed by: majak 21 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 22 // + input by: Alex 23 // + bugfixed by: Brett Zamir (http://brett-zamir.me) 24 // + improved by: Theriault 25 // + improved by: Brett Zamir (http://brett-zamir.me) 26 // + improved by: Theriault 27 // + improved by: Thomas Beaucourt (http://www.webapp.fr) 28 // + improved by: JT 29 // + improved by: Theriault 30 // + improved by: RafaÅ Kukawski (http://blog.kukawski.pl) 31 // + bugfixed by: omid (http://phpjs.org/functions/380:380#comment_137122) 32 // + input by: Martin 33 // + input by: Alex Wilson 34 // + bugfixed by: Chris (http://www.devotis.nl/) 35 // % note 1: Uses global: php_js to store the default timezone 36 // % note 2: Although the function potentially allows timezone info (see notes), it currently does not set 37 // % note 2: per a timezone specified by date_default_timezone_set(). Implementers might use 38 // % note 2: this.php_js.currentTimezoneOffset and this.php_js.currentTimezoneDST set by that function 39 // % note 2: in order to adjust the dates in this function (or our other date functions!) accordingly 40 // * example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400); 41 // * returns 1: '09:09:40 m is month' 42 // * example 2: date('F j, Y, g:i a', 1062462400); 43 // * returns 2: 'September 2, 2003, 2:26 am' 44 // * example 3: date('Y W o', 1062462400); 45 // * returns 3: '2003 36 2003' 46 // * example 4: x = date('Y m d', (new Date()).getTime()/1000); 47 // * example 4: (x+'').length == 10 // 2009 01 09 48 // * returns 4: true 49 // * example 5: date('W', 1104534000); 50 // * returns 5: '53' 51 // * example 6: date('B t', 1104534000); 52 // * returns 6: '999 31' 53 // * example 7: date('W U', 1293750000.82); // 2010-12-31 54 // * returns 7: '52 1293750000' 55 // * example 8: date('W', 1293836400); // 2011-01-01 56 // * returns 8: '52' 57 // * example 9: date('W Y-m-d', 1293974054); // 2011-01-02 58 // * returns 9: '52 2011-01-02' 59 var that = this, 60 jsdate, 61 f, 62 formatChr = /\\?([a-z])/gi, 63 formatChrCb, 64 // Keep this here (works, but for code commented-out 65 // below for file size reasons) 66 //, tal= [], 67 _pad = function (n, c) { 68 n = n.toString(); 69 return n.length < c ? _pad('0' + n, c, '0') : n; 70 }, 71 txt_words = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
71November", "December"]; 72 formatChrCb = function (t, s) { 73 return f[t] ? f[t]() : s; 74 }; 75 f = { 76 // Day 77 d: function () { // Day of month w/leading 0; 01..31 78 return _pad(f.j(), 2); 79 }, 80 D: function () { // Shorthand day name; Mon...Sun 81 return f.l().slice(0, 3); 82 }, 83 j: function () { // Day of month; 1..31 84 return jsdate.getDate(); 85 }, 86 l: function () { // Full day name; Monday...Sunday 87 return txt_words[f.w()] + 'day'; 88 }, 89 N: function () { // ISO-8601 day of week; 1[Mon]..7[Sun] 90 return f.w() || 7; 91 }, 92 S: function(){ // Ordinal suffix for day of month; st, nd, rd, th 93 var j = f.j() 94 i = j%10; 95 if (i <= 3 && parseInt((j%100)/10) == 1) i = 0; 96 return ['st', 'nd', 'rd'][i - 1] || 'th'; 97 }, 98 w: function () { // Day of week; 0[Sun]..6[Sat] 99 return jsdate.getDay(); 100 }, 101 z: function () { // Day of year; 0..365 102 var a = new Date(f.Y(), f.n() - 1, f.j()), 103 b = new Date(f.Y(), 0, 1); 104 return Math.round((a - b) / 864e5); 105 }, 106 107 // Week 108 W: function () { // ISO-8601 week number 109 var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3), 110 b = new Date(a.getFullYear(), 0, 4); 111 return _pad(1 + Math.round((a - b) / 864e5 / 7), 2); 112 }, 113 114 // Month 115 F: function () { // Full month name; January...December 116 return txt_words[6 + f.n()]; 117 }, 118 m: function () { // Month w/leading 0; 01...12 119 return _pad(f.n(), 2); 120 }, 121 M: function () { // Shorthand month name; Jan...Dec 122 return f.F().slice(0, 3); 123 }, 124 n: function () { // Month; 1...12 125 return jsdate.getMonth() + 1; 126 }, 127 t: function () { // Days in month; 28...31 128 return (new Date(f.Y(), f.n(), 0)).getDate(); 129 }, 130 131 // Year 132 L: function () { // Is leap year?; 0 or 1 133 var j = f.Y(); 134 return j % 4 === 0 & j % 100 !== 0 | j % 400 === 0; 135 }, 136 o: function () { // ISO-8601 year 137 var n = f.n(), 138 W = f.W(), 139 Y = f.Y(); 140 return Y + (n === 12 && W < 9 ? 1 : n === 1 && W > 9 ? -1 : 0); 141 }, 142 Y: function () { // Full year; e.g. 1980...2010 143 return jsdate.getFullYear(); 144 }, 145 y: function () { // Last two digits of year; 00...99 146 return f.Y().toString().slice(-2); 147 }, 148 149 // Time 150 a: function () { // am or pm 151 return jsdate.getHours() > 11 ? "pm" : "am"; 152 }, 153 A: function () { // AM or PM 154 return f.a().toUpperCase(); 155 }, 156 B: function () { // Swatch Internet time; 000..999 157 var H = jsdate.getUTCHours() * 36e2, 158 // Hours 159 i = jsdate.getUTCMinutes() * 60, 160 // Minutes 161 s = jsdate.getUTCSeconds(); // Seconds 162 return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3); 163 }, 164 g: function () { // 12-Hours; 1..12 165 return f.G() % 12 || 12; 166 }, 167 G: function () { // 24-Hours; 0..23 168 return jsdate.getHours(); 169 }, 170 h: function () { // 12-Hours w/leading 0; 01..12 171 return _pad(f.g(), 2); 172 }, 173 H: function () { // 24-Hours w/leading 0; 00..23 174 return _pad(f.G(), 2); 175 }, 176 i: function () { // Minutes w/leading 0; 00..59 177 return _pad(jsdate.getMinutes(), 2); 178 }, 179 s: function () { // Seconds w/leading 0; 00..59 180 return _pad(jsdate.getSeconds(), 2); 181 }, 182 u: function () { // Microseconds; 000000-999000 183 return _pad(jsdate.getMilliseconds() * 1000, 6); 184 }, 185 186 // Timezone 187 e: function () { // Timezone identifier; e.g. Atlantic/Azores, ... 188 // The following works, but requires inclusion of the very large 189 // timezone_abbreviations_list() function. 190/* return that.date_default_timezone_get(); 191*/ 192 throw 'Not supported (see source code of date() for timezone on how to add support)'; 193 }, 194 I: function () { // DST observed?; 0 or 1 195 // Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC. 196 // If they are not equal, then DST is observed. 197 var a = new Date(f.Y(), 0), 198 // Jan 1 199 c = Date.UTC(f.Y(), 0), 200 // Jan 1 UTC 201 b = new Date(f.Y(), 6), 202 // Jul 1 203 d = Date.UTC(f.Y(), 6); // Jul 1 UTC 204 return ((a - c) !== (b - d)) ? 1 : 0; 205 }, 206 O: function () { // Difference to GMT in hour format; e.g. +0200 207 var tzo = jsdate.getTimezoneOffset(), 208 a = Math.abs(tzo); 209 return (tzo > 0 ? "-" : "+") + _pad(Math.floor(a / 60) * 100 + a % 60, 4); 210 }, 211 P: function () { // Difference to GMT w/colon; e.g. +02:00 212 var O = f.O(); 213 return (O.substr(0, 3) + ":" + O.substr(3, 2)); 214 }, 215 T: function () { // Timezone abbreviation; e.g. EST, MDT, ... 216 // The following works, but requires inclusion of the very 217 // large timezone_abbreviations_list() function. 218/* var abbr = '', i = 0, os = 0, default = 0; 219 if (!tal.length) { 220 tal = that.timezone_abbreviations_list(); 221 } 222 if (that.php_js && that.php_js.default_timezone) { 223 default = that.php_js.default_timezone; 224 for (abbr in tal) { 225 for (i=0; i < tal[abbr].length; i++) { 226 if (tal[abbr][i].timezone_id === default) { 227 return abbr.toUpperCase(); 228 } 229 } 230 } 231 } 232 for (abbr in tal) { 233 for (i = 0; i < tal[abbr].length; i++) { 234 os = -jsdate.getTimezoneOffset() * 60; 235 if (tal[abbr][i].offset === os) { 236 return abbr.toUpperCase(); 237 } 238 } 239 } 240*/ 241 return 'UTC'; 242 }, 243 Z: function () { // Timezone offset in seconds (-43200...50400) 244 return -jsdate.getTimezoneOffset() * 60; 245 }, 246 247 // Full Date/Time 248 c: function () { // ISO-8601 date. 249 return 'Y-m-d\\TH:i:sP'.replace(formatChr, formatChrCb); 250 }, 251 r: function () { // RFC 2822 252 return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb); 253 }, 254 U: function () { // Seconds since UNIX epoch 255 return jsdate / 1000 | 0; 256 } 257 }; 258 this.date = function (format, timestamp) { 259 that = this; 260 jsdate = (timestamp === undefined ? new Date() : // Not provided 261 (timestamp instanceof Date) ? new Date(timestamp) : // JS Date() 262 new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int) 263 ); 264 return format.replace(formatChr, formatChrCb); 265 }; 266 return this.date(format, timestamp); 267}
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.