1/*************************************************************************************************************************************************************** 2 * _ ________ __ ________ _________ 3 * (_) ____/ /___ _____/ /_______/ ____/ |/ /_ __/ 4 * / / / / / __ \/ ___/ //_/ ___/ / __/ /|_/ / / / 5 * / / /___/ / /_/ / /__/ ,< (__ ) /_/ / / / / / / 6 * __/ /\____/_/\____/\___/_/|_/____/\____/_/ /_/ /_/ 7 * /___/ 8 * 9 * NAME: jClocksGMT.js 10 * VERSION: 2.0.2 11 * LAST UPDATE: 2016.04.26 12 * 13 * Author Information: 14 * Name: Richard McMaster 15 * Email: [email protected] 16 * Location: Houston, Texas, United States 17 * Website: http://kingkode.com/jclocksgmt-js/ 18 * __ _ __ __ 19 * / /__(_)___ ____ _/ /______ ____/ /__ 20 * / //_/ / __ \/ __ `/ //_/ __ \/ __ / _ \ 21 * / ,< / / / / / /_/ / ,< / /_/ / /_/ / __/ 22 * /_/|_/_/_/ /_/\__, /_/|_|\____/\__,_/\___/ 23 * /____/ 24 * 25 * Plugin Website: http://www.github.com/mcmastermind/jClocksGMT 26 * 27 * Change Log: 28 * 2.0.2: Fixed digital only display 29 * 2.0.1: Added image path parameter for images not in plugin directory 30 * 2.0: Complete overhaul of code for increased accuracy and stability 31 * - NEW! 5 clock skins to choose from 32 * - NEW! Timestamp formatting options 33 * - NEW! Date display with formatting options 34 * - NEW! DST parameter for those locations that do not observe DST 35 * - Addressed international DST issues 36 * - Minimized initial markup 37 * - Unique class names to avoid common class declarations 38 * 1.2: Fixed severely flawed Daylight Saving Time calculation 39 * 1.1: Added automatic Daylight Saving Time calculation 40 * 41 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 42 * 43 * Description: 44 * jQuery based analog and digital clock(s) using GMT offsets. Requires jQuery Rotate plugin. 45 * 46 * Documentation: 47 * Default options: 48 * title: 'Greenwich, England', String: Title of location (defaults to Greenwich, England) 49 * offset: '0', String: Set Standard GMT offset (+5.5, -4, 0, etc) (do not consider daylight savings time) 50 * dst: true, Boolean: Does the location observe daylight savings time (set FALSE if location does not need to observe dst ) 51 * digital: true, Boolean: Display digital clock 52 * analog: true, Boolean: Display analog clock 53 * timeformat: 'hh:mm A', String: Time format (see below for formatting options) 54 * date: false, Boolean: Display date 55 * dateformat: 'MM/DD/YYYY', String: Date format (see below for formatting options) 56 * angleSec: 0, Integer: Starting angle of second hand 57 * angleMin: 0, Integer: Starting angle of minute hand 58 * angleHour: 0, Integer: Starting angle of hour hand 59 * skin: 1, Integer: Set 1 of 5 included skins for the analog clock 60 * imgpath: '' String: Set path of images 61 * 62 * Common offsets by time zone: (only use the number after GMT: GMT-2 = offset: '-2' 63 * Daylight Saving Time converted automatically) 64 * GMT-12 Eniwetok 65 * GMT-11 Samoa 66 * GMT-10 Hawaii 67 * GMT-9 Alaska 68 * GMT-8 PST, Pacific US 69 * GMT-7 MST, Mountain US 70 * GMT-6 CST, Central US 71 * GMT-5 EST, Eastern US 72 * GMT-4 Atlantic, Canada 73 * GMT-3 Brazilia, Buenos Aries 74 * GMT-2 Mid-Atlantic 75 * GMT-1 Cape Verdes 76 * GMT 0 Greenwich Mean Time 77 * GMT+1 Berlin, Rome 78 * GMT+2 Israel, Cairo 79 * GMT+3 Moscow, Kuwait 80 * GMT+4 Abu Dhabi, Muscat 81 * GMT+5 Islamabad, Karachi 82 * GMT+6 Almaty, Dhaka 83 * GMT+7 Bangkok, Jakarta 84 * GMT+8 Hong Kong, Beijing 85 * GMT+9 Tokyo, Osaka 86 * GMT+10 Sydney, Melbourne, Guam 87 * GMT+11 Magadan, Soloman Is. 88 * GMT+12 Fiji, Wellington, Auckland 89 * 90 * To find specific GMT offsets, 91 * goto: http://www.timeanddate.com/time/zone/ 92 * search: location 93 * use: Current Offset 94 * if location is currently observing DST, add 1 to offset 95 * 96 * Time Formatting: 97 * HH 19 24-hour format of hour with leading zero (two digits long). 98 * hh 07 12-hour format of hour with leading zero (two digits long). 99 * H 19 24-hour format of hour without leading zeros. 100 * h 7 12-hour format of hour without leading zeros. 101 * mm 01 Minutes with the leading zero (two digits long). 102 * m 1 Minutes without the leading zero. 103 * ss 08 Seconds with the leading zero (two digits long). 104 * s 8 Seconds without the leading zero. 105 * a pm Lowercase am or pm. 106 * A PM Uppercase AM or PM. 107 * SSS 095 Milliseconds with leading zeros (three digits long). 108 * S 95 Milliseconds without leading zeros. 109 * 110 * Date Formatting: 111 * YYYY 2016 Four-digit representation of the year. 112 * YY 16 Two-digit representation of the year. 113 * MMMM April Full textual representation of the month. 114 * MMM Apr Three letter representation of the month. 115 * MM 04 Month with the leading zero (two digits long). 116 * M 4 Month without the leading zero. 117 * DDDD Friday Full textual representation of the day of the week. 118 * DDD Fri Three letter representation of the day of the week. 119 * DD 01 Day of the month with leading zero (two digits long). 120 * D 1 Day of the month without leading zeros. 121 * 122 * Initialization: 123 * Javascript: 124 * $('#clock_hou').jClocksGMT({ title: 'Houston, TX, USA', offset: '-6', skin: 2 }); 125 * Markup: 126 * <div id="clock_hou"></div> 127 * 128 **************************************************************************************************************************************************************/ 129 130 (function($) { 131 132 $.fn.extend({ 133 134 jClocksGMT: function( options ) 135 { 136 // plugin default options 137 var defaults = 138 { 139 title: 'Greenwich, England', 140 offset: '0', 141 dst: true, 142 digital: true, 143 analog: true, 144 timeformat: 'hh:mm A', 145 date: false, 146 dateformat: 'MM/DD/YYYY', 147 angleSec: 0, 148 angleMin: 0, 149 angleHour: 0, 150 skin: 1, 151 imgpath: '' 152 } 153 154 // merge user options with defaults 155 var options = $.extend(defaults, options); 156 157 return this.each(function() 158 { 159 // set offset variable per instance 160 var offset = parseFloat(options.offset); 161 // get id of element 162 var id = $(this).attr('id'); 163 164 // add class to main element 165 $(this).addClass('jcgmt-container'); 166 167 // create label 168 $("<div />", { text: options.title, class: "jcgmt-lbl" }).appendTo("#" + id); 169 170 if( options.analog ) 171 { 172 // create clock container 173 $("<div />", { class: "jcgmt-clockHolder" }).appendTo("#" + id); 174 // create hour hand 175 $("<div />", { class: "jcgmt-rotatingWrapper" }).append($("<img />", { class: "jcgmt-hour", src: options.imgpath + "images/jcgmt-" + options.skin + "-clock_hour.png" })).appendTo("#" + id + ' .jcgmt-clockHolder'); 176 // create min hand 177 $("<div />", { class: "jcgmt-rotatingWrapper" }).append($("<img />", { class: "jcgmt-min", src: options.imgpath + "images/jcgmt-" + options.skin + "-clock_min.png" })).appendTo("#" + id + ' .jcgmt-clockHolder'); 178 // create sec hand 179 $("<div />", { class: "jcgmt-rotatingWrapper" }).append($("<img />", { class: "jcgmt-sec", src: options.imgpath + "images/jcgmt-" + options.skin + "-clock_sec.png" })).appendTo("#" + id + ' .jcgmt-clockHolder'); 180 // create clock face 181 $("<img />", { class: "jcgmt-clock", src: options.imgpath + 'images/jcgmt-' + options.skin + '-clock_face.png' }).appendTo("#" + id + ' .jcgmt-clockHolder'); 182 } 183 184 // create digital clock container 185 $("<div />", { class: "jcgmt-digital" }).appendTo("#" + id); 186 187 //create date container 188 $("<div />", { class: "jcgmt-date" }).appendTo("#" + id); 189 190 // initial hand rotation 191 $('#' + id + ' .jcgmt-sec').rotate( options.angleSec ); 192 $('#' + id + ' .jcgmt-min').rotate( options.angleMin ); 193 $('#' + id + ' .jcgmt-hour').rotate( options.angleHour ); 194 195 // get timezone by gmt offset 196 Date.prototype.getTimezoneByOffset = function( offset, y, m, d ) 197 { 198 var date = new Date; // get date 199 200 if( y ) // if has date params 201 { 202 date = new Date( y, m, d ); // get date with params 203 } 204 205 var utc = date.getTime() + ( date.getTimezoneOffset() * 60000 ); // get local offset 206 207 var dateGMT = new Date( utc + ( 3600000 * offset ) ); // get requested offset based on local 208 209 return dateGMT; 210 } 211 212 // check if daylight saving time is in effect 213 Date.prototype.stdTimezoneOffset = function() 214 { 215 var jan = this.getTimezoneByOffset( offset, this.getFullYear(), 0, 1 ); 216 217 var jul = this.getTimezoneByOffset( offset, this.getFullYear(), 6, 1 ); 218 219 return Math.max( jan.getTimezoneOffset(), jul.getTimezoneOffset() ); 220 } 221 222 // checkes if DST is in effect 223 Date.prototype.isDST = function() 224 { 225 var date = this.getTimezoneByOffset(offset); 226 227 return date.getTimezoneOffset() < this.stdTimezoneOffset(); 228 } 229 230 // date formatter 231 Date.prototype.format = function( format ) 232 { 233 var D = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","), 234 M = "January,February,March,April,May,June,July,August,September,October,November,December".split(","); 235 236 var self = this; 237 return format.replace(/a|A|Z|S(SS)?|ss?|mm?|HH?|hh?|D{1,4}|M{1,4}|YY(YY)?|'([^']|'')*'/g, function(str) { 238 var c1 = str.charAt(0), 239 ret = str.charAt(0) == "'" 240 ? (c1=0) || str.slice(1, -1).replace(/''/g, "'") 241 : str == "a" 242 ? (self.getHours() < 12 ? "am" : "pm") 243 : str == "A" 244 ? (self.getHours() < 12 ? "AM" : "PM") 245 : str == "Z"
246 ? (("+" + -self.getTimezoneOffset() / 60).replace(/^\D?(\D)/, "$1").replace(/^(.)(.)$/, "$10$2") + "00") 247 : c1 == "S" 248 ? self.getMilliseconds() 249 : c1 == "s" 250 ? self.getSeconds() 251 : c1 == "H" 252 ? self.getHours() 253 : c1 == "h" 254 ? (self.getHours() % 12) || 12 255 : (c1 == "D" && str.length > 2) 256 ? D[self.getDay()].slice(0, str.length > 3 ? 9 : 3) 257 : c1 == "D" 258 ? self.getDate() 259 : (c1 == "M" && str.length > 2) 260 ? M[self.getMonth()].slice(0, str.length > 3 ? 9 : 3) 261 : c1 == "m" 262 ? self.getMinutes() 263 : c1 == "M" 264 ? self.getMonth() + 1 265 : ("" + self.getFullYear()).slice(-str.length); 266 return c1 && str.length < 4 && ("" + ret).length < str.length 267 ? ("00" + ret).slice(-str.length) 268 : ret; 269 }); 270 } 271 272 // create new date object 273 var dateCheck = new Date().getTimezoneByOffset( offset ); 274 275 // check for DST 276 if( options.dst && dateCheck.isDST() ) 277 { 278 offset = offset + 1; 279 } 280 281 // clock interval 282 setInterval(function () 283 { 284 // create new date object 285 var nd = new Date().getTimezoneByOffset( offset ); 286 287 // time string variable 288 var timeStr = nd.format( options.timeformat ); 289 290 // update analog clock if enabled 291 if( options.analog ) 292 { 293 // rotate second hand 294 $('#' + id + ' .jcgmt-sec').rotate( nd.getSeconds() * 6 ); 295 // rotate minute hand 296 $('#' + id + ' .jcgmt-min').rotate( nd.getMinutes() * 6 ) ; 297 // rotate hour hand 298 $('#' + id + ' .jcgmt-hour').rotate( ( nd.getHours() * 5 + nd.getMinutes() / 12 ) * 6 ); 299 300 // update title for tooltip 301 $('#' + id + ' .jcgmt-clockHolder').attr( 'title', timeStr ); 302 } 303 304 // update digital clock if enabled 305 if( options.digital ) 306 { 307 $('#' + id + ' .jcgmt-digital').html( timeStr ); 308 $('#' + id + ' .jcgmt-digital').attr( 'title', timeStr ); 309 } 310 311 // update date if enabled 312 if( options.date ) 313 { 314 var dateStamp = nd.format( options.dateformat ); 315 $('#' + id + ' .jcgmt-date').html( dateStamp ); 316 $('#' + id + ' .jcgmt-date').attr( 'title', dateStamp ); 317 } 318 319 }, 1000); 320 321 }); 322 323 } 324 325 }); 326 327})(jQuery);
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.