diff --git a/jqClock-lite.js b/jqClock-lite.js index 8bc5a7a..d089faf 100644 --- a/jqClock-lite.js +++ b/jqClock-lite.js @@ -10,16 +10,16 @@ * Possible options parameters: * @timestamp defaults to clients current time, using the performance API * @timezone defaults to detection of client timezone, but can be passed in as a string such as "UTC-6" when using server generated timestamps - * @langSet defaults to navigator language else "en", possible values are: "af", "am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en", "es", "et", "fa", "fi", "fr", "gu", "he", "hi", "hr", "hu", "id", "in", "it", "iw", "ja", "kn", "ko", "lt", "lv", "ml", "mo", "mr", "ms", "nb", "nl", "no", "pl", "pt", "ro", "ru", "sh", "sk", "sl", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "ur", "vi", "zh", "arb", "cmn", "cnr", "drw", "ekk", "fil", "lvs", "pes", "prs", "swc", "swh", "tnf", "zsm" (can optionally add region) + * @locale defaults to navigator language else "en", possible values are: "af", "am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en", "es", "et", "fa", "fi", "fr", "gu", "he", "hi", "hr", "hu", "id", "in", "it", "iw", "ja", "kn", "ko", "lt", "lv", "ml", "mo", "mr", "ms", "nb", "nl", "no", "pl", "pt", "ro", "ru", "sh", "sk", "sl", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "ur", "vi", "zh", "arb", "cmn", "cnr", "drw", "ekk", "fil", "lvs", "pes", "prs", "swc", "swh", "tnf", "zsm" (can optionally add region) * @calendar defaults to "true", possible value are: boolean "true" or "false" - * @dateFormat defaults to "l, F j, Y" when langSet==="en", else to "l, j F Y" - * @timeFormat defaults to "h:i:s A" when langSet==="en", else to "H:i:s" + * @dateFormat defaults to Intl.DateTimeFormat options object { "dateStyle": "full" }; can take string with PHP style format characters; if set to false @calendar will be false + * @timeFormat defaults to Intl.DateTimeFormat options object { "timeStyle": "medium" }; can take string with PHP style format characters; * @isDST possible values are boolean `true` or `false`, if not passed in will be calculated based on client time (default) * * $("#mydiv").clock(); >> will display in English and in 12 hour format - * $("#mydiv").clock({"langSet":"it"}); >> will display in Italian and in 24 hour format - * $("#mydiv").clock({"langSet":"en","timeFormat":"H:i:s"}); >> will display in English but in 24 hour format - * $("#mydiv").clock({"calendar":false}); >> will remove the date from the clock and display only the time + * $("#mydiv").clock({"locale":"it"}); >> will display in Italian and in 24 hour format + * $("#mydiv").clock({"locale":"en","timeFormat":"H:i:s"}); >> will display in English but in 24 hour format + * $("#mydiv").clock({"dateFormat":false}); >> will remove the date from the clock and display only the time * * Custom timestamp example, say we have a hidden input with id='timestmp' the value of which is determined server-side with server's current time: * @@ -173,6 +173,7 @@ if (!Number.prototype.map) { this.destroy = () => _this.each((idx,selfRef) => { pluginMethods.destroy(selfRef); }); + this.stop = () => _this.each((idx,selfRef) => { pluginMethods.stop(selfRef); }); @@ -181,20 +182,22 @@ if (!Number.prototype.map) { pluginMethods.start(selfRef); }); + const isObject = ( myVar ) => Object.prototype.toString.call( myVar ) === '[object Object]'; + const dateFormatCharacters = { //DAY //Day of the Month, 2 digits with leading zeros "d": ( clk ) => ("" + clk.dt).padStart(2, "0"), //A textual representation of a day, three letters "D": ( clk ) => new Intl.DateTimeFormat( - clk.myoptions.langSet, + clk.myoptions.locale, { weekday: "short" } ).format(clk.mytimestamp_sysdiff), //Day of the month without leading zeros "j": ( clk ) => clk.dt, //A full textual representation of the day of the week "l": ( clk ) => new Intl.DateTimeFormat( - clk.myoptions.langSet, + clk.myoptions.locale, { weekday: "long" } ).format(clk.mytimestamp_sysdiff), // ISO-8601 numeric representation of the day of the week (1-7, 1=Monday) @@ -213,14 +216,14 @@ if (!Number.prototype.map) { //MONTH //A full textual representation of a month, such as January or March "F": ( clk ) => new Intl.DateTimeFormat( - clk.myoptions.langSet, + clk.myoptions.locale, { month: "long" } ).format(clk.mytimestamp_sysdiff), //Numeric representation of a month, with leading zeros "m": ( clk ) => (clk.mo + 1 + "").padStart(2, "0"), //A short textual representation of a month, three letters "M": ( clk ) => new Intl.DateTimeFormat( - clk.myoptions.langSet, + clk.myoptions.locale, { month: "short" } ).format(clk.mytimestamp_sysdiff), //Numeric representation of a month, without leading zeros @@ -285,7 +288,10 @@ if (!Number.prototype.map) { : "+00" ) + ":00", //Timezone abbreviation - /*"T": ( clk ) => timezone_abbrev...*/ + "T": ( clk ) => new Intl.DateTimeFormat( clk.myoptions.locale, { + timeZone: clk.myoptions.timezone, + timeZoneName: "short" + } ).format( clk.mytimestamp_sysdiff ), //Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. "Z": ( clk ) => clk.tzS < 0 ? "" + Math.abs(clk.tzS) @@ -315,13 +321,13 @@ if (!Number.prototype.map) { ) + ":00", //ยป RFC 2822 formatted date | Example: Thu, 21 Dec 2000 16:01:07 +0200 - "r": ( clk ) => new Intl.DateTimeFormat(clk.myoptions.langSet, { + "r": ( clk ) => new Intl.DateTimeFormat(clk.myoptions.locale, { weekday: "short", }).format(clk.mytimestamp_sysdiff) + ", " + clk.dt + " " + - new Intl.DateTimeFormat(clk.myoptions.langSet, { + new Intl.DateTimeFormat(clk.myoptions.locale, { month: "short", }).format(clk.mytimestamp_sysdiff) + " " + @@ -344,6 +350,12 @@ if (!Number.prototype.map) { //Seconds since the Unix Epoch "U": ( clk ) => Math.floor(clk.mytimestamp / 1000) }, + dateFormatOptions = [ + "calendar", "numberingSystem", "weekday", "era", "year", "month", "day", "dateStyle" + ], + timeFormatOptions = [ + "numberingSystem", "hour12", "hourCycle", "timeZone", "timeZoneName", "hour", "minute", "second", "fractionalSecondDigits", "dayPeriod", "timeStyle" + ], pluginMethods = { "destroy": ( selfRef ) => { let el_id = $(selfRef).attr("id"); @@ -372,7 +384,7 @@ if (!Number.prototype.map) { _jqClock.hasOwnProperty(el_id) === false ) { _jqClock[el_id] = setTimeout( - () => { _updateClock($(selfRef)); }, + () => { _updateClock( selfRef ); }, current_options.rate ); } @@ -461,15 +473,18 @@ if (!Number.prototype.map) { $(el).html(clk.calendElem + clk.clockElem); let el_id = $(el).attr("id"); _jqClock[el_id] = setTimeout( - () => { _updateClock( $(el) ); }, + () => { _updateClock( el ); }, clk.myoptions.rate ); }, formatDateString = ( clk ) => { + let dateStr = ""; + let chr; + const { myoptions } = clk; + if( isObject( myoptions.dateFormat ) ) { + dateStr = new Intl.DateTimeFormat(myoptions.locale, myoptions.dateFormat).format(clk.mytimestamp_sysdiff); + } else { /* Format Date String according to PHP style Format Characters http://php.net/manual/en/function.date.php */ - let dateStr = ""; - let chr; - const { myoptions } = clk; for (let n = 0; n <= myoptions.dateFormat.length; n++) { chr = myoptions.dateFormat.charAt(n); if( chr in dateFormatCharacters ) { @@ -487,27 +502,32 @@ if (!Number.prototype.map) { } } } - return '' + dateStr + ""; + } + return '' + dateStr + ""; }, formatTimeString = ( clk ) => { - /* Prepare Time String using PHP style Format Characters http://php.net/manual/en/function.date.php */ let timeStr = ""; let chr; const { myoptions } = clk; - for (let n = 0; n <= myoptions.timeFormat.length; n++) { - chr = myoptions.timeFormat.charAt(n); - if( chr in timeFormatCharacters ) { - timeStr += timeFormatCharacters[chr]( clk ); - } else { - switch (chr) { - case String.fromCharCode(92): //backslash character, which would have to be a double backslash in the original string!!! - timeStr += myoptions.timeFormat.charAt(++n); - break; - case "%": - [ timeStr, n ] = processLiterals( myoptions, n, false, timeStr, chr ); - break; - default: - timeStr += chr; + if( isObject( myoptions.timeFormat ) ) { + timeStr = new Intl.DateTimeFormat(myoptions.locale, myoptions.timeFormat).format(clk.mytimestamp_sysdiff); + } else { + /* Prepare Time String using PHP style Format Characters http://php.net/manual/en/function.date.php */ + for (let n = 0; n <= myoptions.timeFormat.length; n++) { + chr = myoptions.timeFormat.charAt(n); + if( chr in timeFormatCharacters ) { + timeStr += timeFormatCharacters[chr]( clk ); + } else { + switch (chr) { + case String.fromCharCode(92): //backslash character, which would have to be a double backslash in the original string!!! + timeStr += myoptions.timeFormat.charAt(++n); + break; + case "%": + [ timeStr, n ] = processLiterals( myoptions, n, false, timeStr, chr ); + break; + default: + timeStr += chr; + } } } } @@ -517,16 +537,22 @@ if (!Number.prototype.map) { options = options || {}; /* I prefer this method to jQuery.extend because we can dynamically set each option based on a preceding option's value */ options.timestamp = options.timestamp || "localsystime"; - options.langSet = options.langSet || navigator.language || "en"; + if( options.hasOwnProperty( "langSet" ) ) { + console.warn( 'the `langSet` option has been changed to `locale` since v2.3.7 and will be removed in a future release. Please use `locale` in place of `langSet`.' ); + } + options.locale = options.locale || options.langSet || navigator.language || "en"; + if( options.hasOwnProperty( "calendar" ) ) { + console.warn( 'the `calendar` option is deprecated since jqclock v2.3.7 and will be removed in a future release. Please use `dateFormat: false` instead of `calendar: false` to remove the calendar from the jQuery Clock.' ); + } options.calendar = options.hasOwnProperty("calendar") ? options.calendar : true; options.dateFormat = - options.dateFormat || - (options.langSet === "en" ? "l, F j, Y" : "l, j F Y"); + options.dateFormat ?? + { "dateStyle": "full" }; options.timeFormat = options.timeFormat || - (options.langSet === "en" ? "h:i:s A" : "H:i:s"); + { "timeStyle": "medium" }; options.timezone = options.timezone || "localsystimezone"; //should only really be passed in when a server timestamp is passed options.isDST = options.hasOwnProperty("isDST") ? options.isDST @@ -536,8 +562,8 @@ if (!Number.prototype.map) { }, normalizeOptions = (options) => { //ensure we have correct value types - if (typeof options.langSet !== "string") { - options.langSet = "" + options.langSet; + if (typeof options.locale !== "string") { + options.locale = "" + options.locale; } if (typeof options.calendar === "string") { options.calendar = Boolean( @@ -547,10 +573,39 @@ if (!Number.prototype.map) { options.calendar = Boolean(options.calendar); //do our best to get a boolean value } if (typeof options.dateFormat !== "string") { - options.dateFormat = "" + options.dateFormat; + if( isObject( options.dateFormat ) ) { + if ( Object.keys( options.dateFormat ).every( key => dateFormatOptions.includes( key ) ) === false ) { + const extra = Object.keys( options.dateFormat ).reduce((acc,curr) => { if(dateFormatOptions.includes(curr) === false){ acc.push(curr) }; return acc; },[]); + console.error( `unrecognized options passed to dateFormat option: ${ extra.join(', ') }. Valid options are: ${ dateFormatOptions.join(', ') }` ); + } else { + options.calendar = true; + } + } else if ( options.dateFormat === false ) { + options.calendar = false; + } else { + console.error( `dateFormat option has unsupported type, must be either string or object instead is ${ Object.prototype.toString.call( options.dateFormat ) }` ); + options.dateFormat = false; + options.calendar = false; + } + } else { + if( options.dateFormat === 'false' ) { + options.dateFormat = false; + options.calendar = false; + } else { + options.calendar = true; + } } if (typeof options.timeFormat !== "string") { - options.timeFormat = "" + options.dateFormat; + if( isObject( options.timeFormat ) ) { + if ( Object.keys( options.timeFormat ).every( key => timeFormatOptions.includes( key ) ) === false ) { + const extra = Object.keys( options.timeFormat ).reduce((acc,curr) => { if(timeFormatOptions.includes(curr) === false){ acc.push(curr) }; return acc; },[]); + console.error( `unrecognized options passed to timeFormat option: ${ extra.join(', ') }. Valid options are: ${ timeFormatOptions.join(', ') }` ); + } + } else { + console.error( `timeFormat option has unsupported type, must be either string or object instead is ${ Object.prototype.toString.call( options.dateFormat ) }` ); + //let's try to salvage the situation if at all possible... + options.timeFormat = "" + options.timeFormat; + } } if (typeof options.timezone !== "string") { options.timezone = "" + options.timezone; @@ -629,7 +684,7 @@ if (!Number.prototype.map) { $(selfRef).data("clockoptions", options); //only allow one associated settimeout at a time! basically, only one plugin instance per dom element if (_jqClock.hasOwnProperty($(selfRef).attr("id")) === false) { - _updateClock($(selfRef)); + _updateClock(selfRef); } }; @@ -644,7 +699,7 @@ if (!Number.prototype.map) { // It's no use using a client timestamp's check for DST when a server timestamp is passed! // To fix this, we will give a console warning when a server timestamp is passed but the isDST option is not... // In order to do that, we need to save a reference to the original isDST option before ensuring default options - const origDST = options.isDST || null; + const origDST = isObject(options) && options.isDST ? options.isDST : null; options = ensureDefaultOptions( options, sysDateObj ); options = normalizeOptions( options ); diff --git a/jqClock-lite.min.js b/jqClock-lite.min.js index 0e8b222..a1faae9 100644 --- a/jqClock-lite.min.js +++ b/jqClock-lite.min.js @@ -1,19 +1,23 @@ -Date.prototype.hasOwnProperty("stdTimezoneOffset")||(Date.prototype.stdTimezoneOffset=function(){const d=this.getFullYear();if(!Date.prototype.stdTimezoneOffset.cache.hasOwnProperty(d)){let f=(new Date(d,0,1)).getTimezoneOffset();const e=[6,7,5,8,4,9,3,10,2,11,1];for(let k=0;12>k;k++){const l=(new Date(d,e[k],1)).getTimezoneOffset();if(l!==f){f=Math.max(f,l);break}}Date.prototype.stdTimezoneOffset.cache[d]=f}return Date.prototype.stdTimezoneOffset.cache[d]},Date.prototype.stdTimezoneOffset.cache= -{});Date.prototype.hasOwnProperty("isDST")||(Date.prototype.isDST=function(){return this.getTimezoneOffset()k;k++){const l=(new Date(d,e[k],1)).getTimezoneOffset();if(l!==g){g=Math.max(g,l);break}}Date.prototype.stdTimezoneOffset.cache[d]=g}return Date.prototype.stdTimezoneOffset.cache[d]},Date.prototype.stdTimezoneOffset.cache= +{});Date.prototype.hasOwnProperty("isDST")||(Date.prototype.isDST=function(){return this.getTimezoneOffset(){d.clock={version:"2.3.7"};Object.freeze(d.clock);let f={};d.fn.clock=function(e){let k=this;this.initialize=()=>k;this.destroy=()=>k.each((a,b)=>{m.destroy(b)});this.stop=()=>k.each((a,b)=>{m.stop(b)});this.start=()=>k.each((a,b)=>{m.start(b)});const l={d:a=>(""+a.dt).padStart(2,"0"),D:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{weekday:"short"})).format(a.mytimestamp_sysdiff),j:a=>a.dt,l:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{weekday:"long"})).format(a.mytimestamp_sysdiff),N:a=> -0===a.dy?7:a.dy,S:a=>{a=a.dt;return 1===a||1===a%10&&11!==a?"st":2===a||2===a%10&&12!==a?"nd":3===a||3===a%10&&13!==a?"rd":"th"},w:a=>a.dy,z:a=>a.doy-1,W:a=>a.woy,F:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{month:"long"})).format(a.mytimestamp_sysdiff),m:a=>(a.mo+1+"").padStart(2,"0"),M:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{month:"short"})).format(a.mytimestamp_sysdiff),n:a=>a.mo+1,t:a=>a.dim,L:a=>a.ly?1:0,o:a=>a.iso8601Year,Y:a=>a.y,y:a=>a.y.toString().substr(2,2)},p={a:a=>a.ap.toLowerCase(), -A:a=>a.ap,B:a=>a.swt,g:a=>a.H12,G:a=>a.h,h:a=>(""+a.H12).padStart(2,"0"),H:a=>(""+a.h).padStart(2,"0"),i:a=>(""+a.m).padStart(2,"0"),s:a=>(""+a.s).padStart(2,"0"),u:a=>(""+a.ms).padStart(3,"0")+(""+a.us).padStart(3,"0"),v:a=>(""+a.ms).padStart(3,"0"),e:a=>a.myoptions.timezone,I:a=>a.myoptions.isDST?"DST":"",O:a=>(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):00>a.tzS?""+Math.abs(a.tzS):0a.y+"-"+(a.mo+1+"").padStart(2,"0")+"-"+(""+a.dt).padStart(2,"0")+"T"+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(new Intl.DateTimeFormat(a.myoptions.langSet,{weekday:"short"})).format(a.mytimestamp_sysdiff)+", "+a.dt+" "+(new Intl.DateTimeFormat(a.myoptions.langSet,{month:"short"})).format(a.mytimestamp_sysdiff)+ -" "+a.y+" "+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+" "+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0Math.floor(a.mytimestamp/1E3)},m={destroy:a=>{let b=d(a).attr("id");f.hasOwnProperty(b)&&(clearTimeout(f[b]),delete f[b]);d(a).html("");d(a).hasClass("jqclock")&&d(a).removeClass("jqclock");d(a).removeData("clockoptions")},stop:a=>{a=d(a).attr("id");f.hasOwnProperty(a)&&(clearTimeout(f[a]),delete f[a])}, -start:a=>{let b=d(a).attr("id"),c=d(a).data("clockoptions");void 0!==c&&!1===f.hasOwnProperty(b)&&(f[b]=setTimeout(()=>{n(d(a))},c.rate))}},t=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const b=16*Math.random()|0;return("x"===a?b:b&3|8).toString(16)}).toUpperCase(),n=a=>{let b={};b.myoptions=d(a).data("clockoptions");b.currentTzOffset=(new Date).getTimezoneOffset();b.correction=b.currentTzOffset===b.myoptions.tzOffset?0:6E4*(b.currentTzOffset-b.myoptions.tzOffset);b.pfnow=performance.now(); -b.mytimestamp=performance.timeOrigin+b.pfnow+b.myoptions.sysdiff+b.correction;b.mytimestamp_sysdiff=new Date(b.mytimestamp);b.h=b.mytimestamp_sysdiff.getHours();b.m=b.mytimestamp_sysdiff.getMinutes();b.s=b.mytimestamp_sysdiff.getSeconds();b.ms=b.mytimestamp_sysdiff.getMilliseconds();b.us=(""+b.pfnow%1).substring(2,5);b.dy=b.mytimestamp_sysdiff.getDay();b.dt=b.mytimestamp_sysdiff.getDate();b.mo=b.mytimestamp_sysdiff.getMonth();b.y=b.mytimestamp_sysdiff.getFullYear();b.ly=b.mytimestamp_sysdiff.isLeapYear(); -b.doy=b.mytimestamp_sysdiff.getDOY();b.woy=b.mytimestamp_sysdiff.getWOY();b.iso8601Year=b.mytimestamp_sysdiff.getWOY(!0);b.dim=b.mytimestamp_sysdiff.daysInMonth();b.swt=b.mytimestamp_sysdiff.swatchTime();b.tzH=parseInt(b.myoptions.tzOffset/60);b.tzS=parseInt(60*b.myoptions.tzOffset);b.ap="AM";b.calendElem="";b.clockElem="";11{n(d(a))},b.myoptions.rate)},u=a=>{let b="",c;const {myoptions:g}=a;for(let h=0;h<=g.dateFormat.length;h++)if(c=g.dateFormat.charAt(h),c in l)b+=l[c](a);else switch(c){case String.fromCharCode(92):b+=g.dateFormat.charAt(++h);break;case "%":[b,h]=q(g,h,!0,b,c);break;default:b+=c}return''+b+""},v=a=>{let b="",c;const {myoptions:g}=a;for(let h=0;h<=g.timeFormat.length;h++)if(c=g.timeFormat.charAt(h),c in p)b+=p[c](a);else switch(c){case String.fromCharCode(92):b+= -g.timeFormat.charAt(++h);break;case "%":[b,h]=q(g,h,!1,b,c);break;default:b+=c}return''+b+""},q=(a,b,c,g,h)=>{a=c?a.dateFormat:a.timeFormat;for(c=b+1;cb+1&&c!==a.length?(g+=a.substring(b+1,c),b+=c-b):g+=h;return[g,b]},r=(a,b)=>{a.timezone="UTC";let c=b%1;b-=c;let g="";0!==Math.abs(c)&&(g=""+Math.abs(c).map(0,1,0,60));0>b?a.timezone+="+"+Math.abs(b)+(""!==g?":"+g:""):0{if("undefined"===typeof e||"object"===typeof e){a=performance.timeOrigin+performance.now();a=new Date(a);b=e.isDST||null;var c=e;c=c||{};c.timestamp=c.timestamp||"localsystime";c.langSet=c.langSet||navigator.language||"en";c.calendar=c.hasOwnProperty("calendar")?c.calendar:!0;c.dateFormat=c.dateFormat||("en"===c.langSet?"l, F j, Y":"l, j F Y");c.timeFormat=c.timeFormat||("en"===c.langSet?"h:i:s A":"H:i:s");c.timezone=c.timezone||"localsystimezone";c.isDST=c.hasOwnProperty("isDST")?c.isDST:a.isDST(); -c.rate=c.rate||500;c=e=c;"string"!==typeof c.langSet&&(c.langSet=""+c.langSet);"string"===typeof c.calendar?c.calendar="false"===c.calendar?!1:!0:"boolean"!==typeof c.calendar&&(c.calendar=!!c.calendar);"string"!==typeof c.dateFormat&&(c.dateFormat=""+c.dateFormat);"string"!==typeof c.timeFormat&&(c.timeFormat=""+c.dateFormat);"string"!==typeof c.timezone&&(c.timezone=""+c.timezone);"string"===typeof c.isDST?c.isDST="true"===c.isDST?!0:!1:"boolean"!==typeof c.isDST&&(c.isDST=!!c.isDST);"number"!== -typeof c.rate&&(c.rate=parseInt(c.rate));e=c;e.tzOffset=a.getTimezoneOffset();const g=e.tzOffset/60;e.sysdiff=0;"localsystime"!==e.timestamp?(c=e,2<(a.getTime()+"").length-(c.timestamp+"").length?(c=e,c.timestamp*=1E3,c.sysdiff=c.timestamp-a.getTime()+6E4*c.tzOffset,e=c,null===b&&console.warn("jqClock: cannot automatically determine whether DST is in effect for a server side timestamp, please supply the `isDST` option")):(e.sysdiff=e.timestamp-a.getTime(),"localsystimezone"===e.timezone&&(e=r(e,g)))): -"localsystimezone"===e.timezone&&(e=r(e,g));a=e;d(this).hasClass("jqclock")||d(this).addClass("jqclock");d(this).is("[id]")||d(this).attr("id",t());d(this).data("clockoptions",a);!1===f.hasOwnProperty(d(this).attr("id"))&&n(d(this))}else if("string"===typeof e)if(e in m)m[e](b);else console.error("You are calling an undefined method on a jqClock instance")});return this.initialize()};return this})(jQuery); +Date.prototype.hasOwnProperty("getWOY")||(Date.prototype.getWOY=function(d=!1){const g=new Date(Date.UTC(this.getFullYear(),this.getMonth(),this.getDate()));g.setUTCHours(0,0,0,0);const e=g.getUTCDay()||7;g.setUTCDate(g.getUTCDate()+4-e);if(d)return g.getUTCFullYear();d=new Date(Date.UTC(g.getUTCFullYear(),0,1));return Math.ceil(((g-d)/864E5+1)/7)}); +Date.prototype.hasOwnProperty("swatchTime")||(Date.prototype.swatchTime=function(){return("00"+Math.floor((60*((this.getUTCHours()+1)%24*60+this.getUTCMinutes())+this.getUTCSeconds()+.001*this.getUTCMilliseconds())/86.4)).slice(-3)});Number.prototype.map||(Number.prototype.map=function(d,g,e,k){return e+(this-d)/(g-d)*(k-e)}); +(d=>{d.clock={version:"2.3.7"};Object.freeze(d.clock);let g={};d.fn.clock=function(e){let k=this;this.initialize=()=>k;this.destroy=()=>k.each((a,b)=>{m.destroy(b)});this.stop=()=>k.each((a,b)=>{m.stop(b)});this.start=()=>k.each((a,b)=>{m.start(b)});const l=a=>"[object Object]"===Object.prototype.toString.call(a),r={d:a=>(""+a.dt).padStart(2,"0"),D:a=>(new Intl.DateTimeFormat(a.myoptions.locale,{weekday:"short"})).format(a.mytimestamp_sysdiff),j:a=>a.dt,l:a=>(new Intl.DateTimeFormat(a.myoptions.locale, +{weekday:"long"})).format(a.mytimestamp_sysdiff),N:a=>0===a.dy?7:a.dy,S:a=>{a=a.dt;return 1===a||1===a%10&&11!==a?"st":2===a||2===a%10&&12!==a?"nd":3===a||3===a%10&&13!==a?"rd":"th"},w:a=>a.dy,z:a=>a.doy-1,W:a=>a.woy,F:a=>(new Intl.DateTimeFormat(a.myoptions.locale,{month:"long"})).format(a.mytimestamp_sysdiff),m:a=>(a.mo+1+"").padStart(2,"0"),M:a=>(new Intl.DateTimeFormat(a.myoptions.locale,{month:"short"})).format(a.mytimestamp_sysdiff),n:a=>a.mo+1,t:a=>a.dim,L:a=>a.ly?1:0,o:a=>a.iso8601Year,Y:a=> +a.y,y:a=>a.y.toString().substr(2,2)},t={a:a=>a.ap.toLowerCase(),A:a=>a.ap,B:a=>a.swt,g:a=>a.H12,G:a=>a.h,h:a=>(""+a.H12).padStart(2,"0"),H:a=>(""+a.h).padStart(2,"0"),i:a=>(""+a.m).padStart(2,"0"),s:a=>(""+a.s).padStart(2,"0"),u:a=>(""+a.ms).padStart(3,"0")+(""+a.us).padStart(3,"0"),v:a=>(""+a.ms).padStart(3,"0"),e:a=>a.myoptions.timezone,I:a=>a.myoptions.isDST?"DST":"",O:a=>(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2, +"0"):0(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"short"})).format(a.mytimestamp_sysdiff),Z:a=>0>a.tzS?""+Math.abs(a.tzS):0a.y+"-"+(a.mo+1+"").padStart(2,"0")+"-"+(""+a.dt).padStart(2,"0")+"T"+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(new Intl.DateTimeFormat(a.myoptions.locale,{weekday:"short"})).format(a.mytimestamp_sysdiff)+", "+a.dt+" "+(new Intl.DateTimeFormat(a.myoptions.locale,{month:"short"})).format(a.mytimestamp_sysdiff)+" "+a.y+" "+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+" "+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0Math.floor(a.mytimestamp/1E3)},n="calendar numberingSystem weekday era year month day dateStyle".split(" "), +p="numberingSystem hour12 hourCycle timeZone timeZoneName hour minute second fractionalSecondDigits dayPeriod timeStyle".split(" "),m={destroy:a=>{let b=d(a).attr("id");g.hasOwnProperty(b)&&(clearTimeout(g[b]),delete g[b]);d(a).html("");d(a).hasClass("jqclock")&&d(a).removeClass("jqclock");d(a).removeData("clockoptions")},stop:a=>{a=d(a).attr("id");g.hasOwnProperty(a)&&(clearTimeout(g[a]),delete g[a])},start:a=>{let b=d(a).attr("id"),c=d(a).data("clockoptions");void 0!==c&&!1===g.hasOwnProperty(b)&& +(g[b]=setTimeout(()=>{q(a)},c.rate))}},w=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const b=16*Math.random()|0;return("x"===a?b:b&3|8).toString(16)}).toUpperCase(),q=a=>{let b={};b.myoptions=d(a).data("clockoptions");b.currentTzOffset=(new Date).getTimezoneOffset();b.correction=b.currentTzOffset===b.myoptions.tzOffset?0:6E4*(b.currentTzOffset-b.myoptions.tzOffset);b.pfnow=performance.now();b.mytimestamp=performance.timeOrigin+b.pfnow+b.myoptions.sysdiff+b.correction;b.mytimestamp_sysdiff= +new Date(b.mytimestamp);b.h=b.mytimestamp_sysdiff.getHours();b.m=b.mytimestamp_sysdiff.getMinutes();b.s=b.mytimestamp_sysdiff.getSeconds();b.ms=b.mytimestamp_sysdiff.getMilliseconds();b.us=(""+b.pfnow%1).substring(2,5);b.dy=b.mytimestamp_sysdiff.getDay();b.dt=b.mytimestamp_sysdiff.getDate();b.mo=b.mytimestamp_sysdiff.getMonth();b.y=b.mytimestamp_sysdiff.getFullYear();b.ly=b.mytimestamp_sysdiff.isLeapYear();b.doy=b.mytimestamp_sysdiff.getDOY();b.woy=b.mytimestamp_sysdiff.getWOY();b.iso8601Year=b.mytimestamp_sysdiff.getWOY(!0); +b.dim=b.mytimestamp_sysdiff.daysInMonth();b.swt=b.mytimestamp_sysdiff.swatchTime();b.tzH=parseInt(b.myoptions.tzOffset/60);b.tzS=parseInt(60*b.myoptions.tzOffset);b.ap="AM";b.calendElem="";b.clockElem="";11{q(a)},b.myoptions.rate)},x=a=>{let b="",c;const {myoptions:f}=a;if(l(f.dateFormat))b= +(new Intl.DateTimeFormat(f.locale,f.dateFormat)).format(a.mytimestamp_sysdiff);else for(let h=0;h<=f.dateFormat.length;h++)if(c=f.dateFormat.charAt(h),c in r)b+=r[c](a);else switch(c){case String.fromCharCode(92):b+=f.dateFormat.charAt(++h);break;case "%":[b,h]=u(f,h,!0,b,c);break;default:b+=c}return''+b+""},y=a=>{let b="",c;const {myoptions:f}=a;if(l(f.timeFormat))b=(new Intl.DateTimeFormat(f.locale,f.timeFormat)).format(a.mytimestamp_sysdiff);else for(let h=0;h<=f.timeFormat.length;h++)if(c= +f.timeFormat.charAt(h),c in t)b+=t[c](a);else switch(c){case String.fromCharCode(92):b+=f.timeFormat.charAt(++h);break;case "%":[b,h]=u(f,h,!1,b,c);break;default:b+=c}return''+b+""},z=a=>{"string"!==typeof a.locale&&(a.locale=""+a.locale);"string"===typeof a.calendar?a.calendar="false"===a.calendar?!1:!0:"boolean"!==typeof a.calendar&&(a.calendar=!!a.calendar);if("string"!==typeof a.dateFormat)if(l(a.dateFormat))if(!1===Object.keys(a.dateFormat).every(c=>n.includes(c))){var b= +Object.keys(a.dateFormat).reduce((c,f)=>{!1===n.includes(f)&&c.push(f);return c},[]);console.error(`unrecognized options passed to dateFormat option: ${b.join(", ")}. Valid options are: ${n.join(", ")}`)}else a.calendar=!0;else!1!==a.dateFormat&&(console.error(`dateFormat option has unsupported type, must be either string or object instead is ${Object.prototype.toString.call(a.dateFormat)}`),a.dateFormat=!1),a.calendar=!1;else"false"===a.dateFormat?(a.dateFormat=!1,a.calendar=!1):a.calendar=!0;"string"!== +typeof a.timeFormat&&(l(a.timeFormat)?!1===Object.keys(a.timeFormat).every(c=>p.includes(c))&&(b=Object.keys(a.timeFormat).reduce((c,f)=>{!1===p.includes(f)&&c.push(f);return c},[]),console.error(`unrecognized options passed to timeFormat option: ${b.join(", ")}. Valid options are: ${p.join(", ")}`)):(console.error(`timeFormat option has unsupported type, must be either string or object instead is ${Object.prototype.toString.call(a.dateFormat)}`),a.timeFormat=""+a.timeFormat));"string"!==typeof a.timezone&& +(a.timezone=""+a.timezone);"string"===typeof a.isDST?a.isDST="true"===a.isDST?!0:!1:"boolean"!==typeof a.isDST&&(a.isDST=!!a.isDST);"number"!==typeof a.rate&&(a.rate=parseInt(a.rate));return a},u=(a,b,c,f,h)=>{a=c?a.dateFormat:a.timeFormat;for(c=b+1;cb+1&&c!==a.length?(f+=a.substring(b+1,c),b+=c-b):f+=h;return[f,b]},v=(a,b)=>{a.timezone="UTC";let c=b%1;b-=c;let f="";0!==Math.abs(c)&&(f=""+Math.abs(c).map(0,1,0,60));0>b?a.timezone+="+"+Math.abs(b)+(""!==f?":"+f: +""):0{if("undefined"===typeof e||"object"===typeof e){a=performance.timeOrigin+performance.now();a=new Date(a);b=l(e)&&e.isDST?e.isDST:null;var c=e;c=c||{};c.timestamp=c.timestamp||"localsystime";c.hasOwnProperty("langSet")&&console.warn("the `langSet` option has been changed to `locale` since v2.3.7 and will be removed in a future release. Please use `locale` in place of `langSet`.");c.locale=c.locale||c.langSet||navigator.language|| +"en";c.hasOwnProperty("calendar")&&console.warn("the `calendar` option is deprecated since jqclock v2.3.7 and will be removed in a future release. Please use `dateFormat: false` instead of `calendar: false` to remove the calendar from the jQuery Clock.");c.calendar=c.hasOwnProperty("calendar")?c.calendar:!0;c.dateFormat=c.dateFormat??{dateStyle:"full"};c.timeFormat=c.timeFormat||{timeStyle:"medium"};c.timezone=c.timezone||"localsystimezone";c.isDST=c.hasOwnProperty("isDST")?c.isDST:a.isDST();c.rate= +c.rate||500;e=c;e=z(e);e.tzOffset=a.getTimezoneOffset();const f=e.tzOffset/60;e.sysdiff=0;"localsystime"!==e.timestamp?(c=e,2<(a.getTime()+"").length-(c.timestamp+"").length?(c=e,c.timestamp*=1E3,c.sysdiff=c.timestamp-a.getTime()+6E4*c.tzOffset,e=c,null===b&&console.warn("jqClock: cannot automatically determine whether DST is in effect for a server side timestamp, please supply the `isDST` option")):(e.sysdiff=e.timestamp-a.getTime(),"localsystimezone"===e.timezone&&(e=v(e,f)))):"localsystimezone"=== +e.timezone&&(e=v(e,f));a=e;d(this).hasClass("jqclock")||d(this).addClass("jqclock");d(this).is("[id]")||d(this).attr("id",w());d(this).data("clockoptions",a);!1===g.hasOwnProperty(d(this).attr("id"))&&q(this)}else if("string"===typeof e)if(e in m)m[e](b);else console.error("You are calling an undefined method on a jqClock instance")});return this.initialize()};return this})(jQuery); diff --git a/jqClock.min.js b/jqClock.min.js index ef4a052..096dc18 100644 --- a/jqClock.min.js +++ b/jqClock.min.js @@ -1,24 +1,27 @@ -Date.prototype.hasOwnProperty("stdTimezoneOffset")||(Date.prototype.stdTimezoneOffset=function(){const d=this.getFullYear();if(!Date.prototype.stdTimezoneOffset.cache.hasOwnProperty(d)){let f=(new Date(d,0,1)).getTimezoneOffset();const e=[6,7,5,8,4,9,3,10,2,11,1];for(let k=0;12>k;k++){const l=(new Date(d,e[k],1)).getTimezoneOffset();if(l!==f){f=Math.max(f,l);break}}Date.prototype.stdTimezoneOffset.cache[d]=f}return Date.prototype.stdTimezoneOffset.cache[d]},Date.prototype.stdTimezoneOffset.cache= -{});Date.prototype.hasOwnProperty("isDST")||(Date.prototype.isDST=function(){return this.getTimezoneOffset()k;k++){const l=(new Date(d,e[k],1)).getTimezoneOffset();if(l!==g){g=Math.max(g,l);break}}Date.prototype.stdTimezoneOffset.cache[d]=g}return Date.prototype.stdTimezoneOffset.cache[d]},Date.prototype.stdTimezoneOffset.cache= +{});Date.prototype.hasOwnProperty("isDST")||(Date.prototype.isDST=function(){return this.getTimezoneOffset(){d.clock={version:"2.3.7",options:[{type:"string",value:"destroy",description:"Passing in 'destroy' to an already initialized clock will remove the setTimeout for that clock to stop it from ticking, and remove all html markup and data associated with the plugin instance on the dom elements"},{type:"string",value:"stop",description:"Passing in 'stop' to an already initialized clock will clear the setTimeout for that clock to stop it from ticking"},{type:"string",value:"start",description:"Passing in 'start' to an already initialized clock will restart the setTimeout for that clock to get it ticking again, as though it had never lost time"}, -{type:"object",description:"option set {}",values:[{name:"timestamp",description:"Either a javascript timestamp as produced by [JAVASCRIPT new Date().getTime()] or a php timestamp as produced by [PHP time()] ",type:"unix timestamp",values:["javascript timestamp","php timestamp"],default:'"localsystime" which defaults to `new Date(performance.timeOrigin + performance.now()).getTime()`'},{name:"langSet",description:"valid BCP47 locale tag to be used for the translation of Day names and Month names (currently 69 valid tags, can optionally be combined with region)", -type:"String",values:"af am ar bg bn ca cs da de el en es et fa fi fr gu he hi hr hu id in it iw ja kn ko lt lv ml mo mr ms nb nl no pl pt ro ru sh sk sl sr sv sw ta te th tl tr uk ur vi zh arb cmn cnr drw ekk fil lvs pes prs swc swh tnf zsm".split(" "),default:'navigator.language || "en"'},{name:"calendar",description:"Whether the date should be displayed together with the time",type:"Boolean",values:[!0,!1],default:!0},{name:"dateFormat",description:"PHP Style Format string for formatting a local date, see http://php.net/manual/en/function.date.php", -type:"String",values:"dDjlNSwzWFmMntLoYy".split(""),default:'langSet === "en" ? "l, F j, Y" : "l, j F Y"'},{name:"timeFormat",description:"PHP Style Format string for formatting a local date, see http://php.net/manual/en/function.date.php",type:"String",values:"aABgGhHisveIOPZcrU".split(""),default:'langSet === "en" ? "h:i:s A" : "H:i:s"'},{name:"isDST",description:"When a client side timestamp is used, whether DST is active will be automatically determined. However this cannot be determined for a server-side timestamp which must be passed in as UTC, in that case it can be set with this option", +{type:"object",description:"option set {}",values:[{name:"timestamp",description:"Either a javascript timestamp as produced by [JAVASCRIPT new Date().getTime()] or a php timestamp as produced by [PHP time()] ",type:"unix timestamp",values:["javascript timestamp","php timestamp"],default:'"localsystime" which defaults to `new Date(performance.timeOrigin + performance.now()).getTime()`'},{name:"locale (changed from `langSet` in v2.3.7)",description:"valid BCP47 locale tag to be used for the translation of Day names and Month names (currently 69 valid tags, can optionally be combined with region)", +type:"String",values:"af am ar bg bn ca cs da de el en es et fa fi fr gu he hi hr hu id in it iw ja kn ko lt lv ml mo mr ms nb nl no pl pt ro ru sh sk sl sr sv sw ta te th tl tr uk ur vi zh arb cmn cnr drw ekk fil lvs pes prs swc swh tnf zsm".split(" "),default:'navigator.language || "en"'},{name:"calendar (DEPRECATED in v2.3.7, use dateFormat option instead)",description:"Whether the date should be displayed together with the time",type:"Boolean",values:[!0,!1],default:!0},{name:"dateFormat",description:"PHP Style Format string for formatting a local date, see http://php.net/manual/en/function.date.php; OR `Intl.DateTimeFormat` options object, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat; or `false` to disable calendar output", +type:"String | Object | false",values:"dDjlNSwzWFmMntLoYy".split(""),default:{dateStyle:"full"}},{name:"timeFormat",description:"PHP Style Format string for formatting a local date, see http://php.net/manual/en/function.date.php; OR `Intl.DateTimeFormat` options object, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat",type:"String | Object",values:"aABgGhHisveIOPTZcrU".split(""),default:{timeStyle:"medium"}},{name:"isDST",description:"When a client side timestamp is used, whether DST is active will be automatically determined. However this cannot be determined for a server-side timestamp which must be passed in as UTC, in that case it can be set with this option", type:"Boolean",values:[!0,!1]},{name:"rate",description:"Defines the rate at which the clock will update, in milliseconds",type:"Integer",values:"1 - 9007199254740991 (recommended min 10 - max 60000)",default:500}]}],methods:{destroy:"Chaining clock().destroy() has the same effect as passing the 'destroy' option as in clock('destroy')",stop:"Chaining clock().stop() has the same effect as passing the 'stop' option as in clock('stop')",start:"Chaining clock().start() has the same effect as passing the 'start' option as in clock('start')"}}; -Object.freeze(d.clock);let f={};d.fn.clock=function(e){let k=this;this.initialize=()=>k;this.destroy=()=>k.each((a,b)=>{m.destroy(b)});this.stop=()=>k.each((a,b)=>{m.stop(b)});this.start=()=>k.each((a,b)=>{m.start(b)});const l={d:a=>(""+a.dt).padStart(2,"0"),D:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{weekday:"short"})).format(a.mytimestamp_sysdiff),j:a=>a.dt,l:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{weekday:"long"})).format(a.mytimestamp_sysdiff),N:a=>0===a.dy?7:a.dy,S:a=>{a=a.dt; -return 1===a||1===a%10&&11!==a?"st":2===a||2===a%10&&12!==a?"nd":3===a||3===a%10&&13!==a?"rd":"th"},w:a=>a.dy,z:a=>a.doy-1,W:a=>a.woy,F:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{month:"long"})).format(a.mytimestamp_sysdiff),m:a=>(a.mo+1+"").padStart(2,"0"),M:a=>(new Intl.DateTimeFormat(a.myoptions.langSet,{month:"short"})).format(a.mytimestamp_sysdiff),n:a=>a.mo+1,t:a=>a.dim,L:a=>a.ly?1:0,o:a=>a.iso8601Year,Y:a=>a.y,y:a=>a.y.toString().substr(2,2)},p={a:a=>a.ap.toLowerCase(),A:a=>a.ap,B:a=> -a.swt,g:a=>a.H12,G:a=>a.h,h:a=>(""+a.H12).padStart(2,"0"),H:a=>(""+a.h).padStart(2,"0"),i:a=>(""+a.m).padStart(2,"0"),s:a=>(""+a.s).padStart(2,"0"),u:a=>(""+a.ms).padStart(3,"0")+(""+a.us).padStart(3,"0"),v:a=>(""+a.ms).padStart(3,"0"),e:a=>a.myoptions.timezone,I:a=>a.myoptions.isDST?"DST":"",O:a=>(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):00>a.tzS?""+Math.abs(a.tzS):0a.y+"-"+(a.mo+1+"").padStart(2,"0")+"-"+(""+a.dt).padStart(2,"0")+"T"+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(new Intl.DateTimeFormat(a.myoptions.langSet,{weekday:"short"})).format(a.mytimestamp_sysdiff)+", "+a.dt+" "+(new Intl.DateTimeFormat(a.myoptions.langSet,{month:"short"})).format(a.mytimestamp_sysdiff)+ -" "+a.y+" "+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+" "+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0Math.floor(a.mytimestamp/1E3)},m={destroy:a=>{let b=d(a).attr("id");f.hasOwnProperty(b)&&(clearTimeout(f[b]),delete f[b]);d(a).html("");d(a).hasClass("jqclock")&&d(a).removeClass("jqclock");d(a).removeData("clockoptions")},stop:a=>{a=d(a).attr("id");f.hasOwnProperty(a)&&(clearTimeout(f[a]),delete f[a])}, -start:a=>{let b=d(a).attr("id"),c=d(a).data("clockoptions");void 0!==c&&!1===f.hasOwnProperty(b)&&(f[b]=setTimeout(()=>{n(d(a))},c.rate))}},t=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const b=16*Math.random()|0;return("x"===a?b:b&3|8).toString(16)}).toUpperCase(),n=a=>{let b={};b.myoptions=d(a).data("clockoptions");b.currentTzOffset=(new Date).getTimezoneOffset();b.correction=b.currentTzOffset===b.myoptions.tzOffset?0:6E4*(b.currentTzOffset-b.myoptions.tzOffset);b.pfnow=performance.now(); -b.mytimestamp=performance.timeOrigin+b.pfnow+b.myoptions.sysdiff+b.correction;b.mytimestamp_sysdiff=new Date(b.mytimestamp);b.h=b.mytimestamp_sysdiff.getHours();b.m=b.mytimestamp_sysdiff.getMinutes();b.s=b.mytimestamp_sysdiff.getSeconds();b.ms=b.mytimestamp_sysdiff.getMilliseconds();b.us=(""+b.pfnow%1).substring(2,5);b.dy=b.mytimestamp_sysdiff.getDay();b.dt=b.mytimestamp_sysdiff.getDate();b.mo=b.mytimestamp_sysdiff.getMonth();b.y=b.mytimestamp_sysdiff.getFullYear();b.ly=b.mytimestamp_sysdiff.isLeapYear(); -b.doy=b.mytimestamp_sysdiff.getDOY();b.woy=b.mytimestamp_sysdiff.getWOY();b.iso8601Year=b.mytimestamp_sysdiff.getWOY(!0);b.dim=b.mytimestamp_sysdiff.daysInMonth();b.swt=b.mytimestamp_sysdiff.swatchTime();b.tzH=parseInt(b.myoptions.tzOffset/60);b.tzS=parseInt(60*b.myoptions.tzOffset);b.ap="AM";b.calendElem="";b.clockElem="";11{n(d(a))},b.myoptions.rate)},u=a=>{let b="",c;const {myoptions:g}=a;for(let h=0;h<=g.dateFormat.length;h++)if(c=g.dateFormat.charAt(h),c in l)b+=l[c](a);else switch(c){case String.fromCharCode(92):b+=g.dateFormat.charAt(++h);break;case "%":[b,h]=q(g,h,!0,b,c);break;default:b+=c}return''+b+""},v=a=>{let b="",c;const {myoptions:g}=a;for(let h=0;h<=g.timeFormat.length;h++)if(c=g.timeFormat.charAt(h),c in p)b+=p[c](a);else switch(c){case String.fromCharCode(92):b+= -g.timeFormat.charAt(++h);break;case "%":[b,h]=q(g,h,!1,b,c);break;default:b+=c}return''+b+""},q=(a,b,c,g,h)=>{a=c?a.dateFormat:a.timeFormat;for(c=b+1;cb+1&&c!==a.length?(g+=a.substring(b+1,c),b+=c-b):g+=h;return[g,b]},r=(a,b)=>{a.timezone="UTC";let c=b%1;b-=c;let g="";0!==Math.abs(c)&&(g=""+Math.abs(c).map(0,1,0,60));0>b?a.timezone+="+"+Math.abs(b)+(""!==g?":"+g:""):0{if("undefined"===typeof e||"object"===typeof e){a=performance.timeOrigin+performance.now();a=new Date(a);b=e.isDST||null;var c=e;c=c||{};c.timestamp=c.timestamp||"localsystime";c.langSet=c.langSet||navigator.language||"en";c.calendar=c.hasOwnProperty("calendar")?c.calendar:!0;c.dateFormat=c.dateFormat||("en"===c.langSet?"l, F j, Y":"l, j F Y");c.timeFormat=c.timeFormat||("en"===c.langSet?"h:i:s A":"H:i:s");c.timezone=c.timezone||"localsystimezone";c.isDST=c.hasOwnProperty("isDST")?c.isDST:a.isDST(); -c.rate=c.rate||500;c=e=c;"string"!==typeof c.langSet&&(c.langSet=""+c.langSet);"string"===typeof c.calendar?c.calendar="false"===c.calendar?!1:!0:"boolean"!==typeof c.calendar&&(c.calendar=!!c.calendar);"string"!==typeof c.dateFormat&&(c.dateFormat=""+c.dateFormat);"string"!==typeof c.timeFormat&&(c.timeFormat=""+c.dateFormat);"string"!==typeof c.timezone&&(c.timezone=""+c.timezone);"string"===typeof c.isDST?c.isDST="true"===c.isDST?!0:!1:"boolean"!==typeof c.isDST&&(c.isDST=!!c.isDST);"number"!== -typeof c.rate&&(c.rate=parseInt(c.rate));e=c;e.tzOffset=a.getTimezoneOffset();const g=e.tzOffset/60;e.sysdiff=0;"localsystime"!==e.timestamp?(c=e,2<(a.getTime()+"").length-(c.timestamp+"").length?(c=e,c.timestamp*=1E3,c.sysdiff=c.timestamp-a.getTime()+6E4*c.tzOffset,e=c,null===b&&console.warn("jqClock: cannot automatically determine whether DST is in effect for a server side timestamp, please supply the `isDST` option")):(e.sysdiff=e.timestamp-a.getTime(),"localsystimezone"===e.timezone&&(e=r(e,g)))): -"localsystimezone"===e.timezone&&(e=r(e,g));a=e;d(this).hasClass("jqclock")||d(this).addClass("jqclock");d(this).is("[id]")||d(this).attr("id",t());d(this).data("clockoptions",a);!1===f.hasOwnProperty(d(this).attr("id"))&&n(d(this))}else if("string"===typeof e)if(e in m)m[e](b);else console.error("You are calling an undefined method on a jqClock instance")});return this.initialize()};return this})(jQuery); +Object.freeze(d.clock);let g={};d.fn.clock=function(e){let k=this;this.initialize=()=>k;this.destroy=()=>k.each((a,b)=>{m.destroy(b)});this.stop=()=>k.each((a,b)=>{m.stop(b)});this.start=()=>k.each((a,b)=>{m.start(b)});const l=a=>"[object Object]"===Object.prototype.toString.call(a),r={d:a=>(""+a.dt).padStart(2,"0"),D:a=>(new Intl.DateTimeFormat(a.myoptions.locale,{weekday:"short"})).format(a.mytimestamp_sysdiff),j:a=>a.dt,l:a=>(new Intl.DateTimeFormat(a.myoptions.locale,{weekday:"long"})).format(a.mytimestamp_sysdiff), +N:a=>0===a.dy?7:a.dy,S:a=>{a=a.dt;return 1===a||1===a%10&&11!==a?"st":2===a||2===a%10&&12!==a?"nd":3===a||3===a%10&&13!==a?"rd":"th"},w:a=>a.dy,z:a=>a.doy-1,W:a=>a.woy,F:a=>(new Intl.DateTimeFormat(a.myoptions.locale,{month:"long"})).format(a.mytimestamp_sysdiff),m:a=>(a.mo+1+"").padStart(2,"0"),M:a=>(new Intl.DateTimeFormat(a.myoptions.locale,{month:"short"})).format(a.mytimestamp_sysdiff),n:a=>a.mo+1,t:a=>a.dim,L:a=>a.ly?1:0,o:a=>a.iso8601Year,Y:a=>a.y,y:a=>a.y.toString().substr(2,2)},t={a:a=>a.ap.toLowerCase(), +A:a=>a.ap,B:a=>a.swt,g:a=>a.H12,G:a=>a.h,h:a=>(""+a.H12).padStart(2,"0"),H:a=>(""+a.h).padStart(2,"0"),i:a=>(""+a.m).padStart(2,"0"),s:a=>(""+a.s).padStart(2,"0"),u:a=>(""+a.ms).padStart(3,"0")+(""+a.us).padStart(3,"0"),v:a=>(""+a.ms).padStart(3,"0"),e:a=>a.myoptions.timezone,I:a=>a.myoptions.isDST?"DST":"",O:a=>(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"short"})).format(a.mytimestamp_sysdiff),Z:a=>0>a.tzS?""+Math.abs(a.tzS):0a.y+"-"+(a.mo+1+"").padStart(2,"0")+"-"+(""+a.dt).padStart(2,"0")+"T"+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0(new Intl.DateTimeFormat(a.myoptions.locale, +{weekday:"short"})).format(a.mytimestamp_sysdiff)+", "+a.dt+" "+(new Intl.DateTimeFormat(a.myoptions.locale,{month:"short"})).format(a.mytimestamp_sysdiff)+" "+a.y+" "+(""+a.h).padStart(2,"0")+":"+(""+a.m).padStart(2,"0")+":"+(""+a.s).padStart(2,"0")+" "+(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0Math.floor(a.mytimestamp/1E3)},n="calendar numberingSystem weekday era year month day dateStyle".split(" "),p="numberingSystem hour12 hourCycle timeZone timeZoneName hour minute second fractionalSecondDigits dayPeriod timeStyle".split(" "), +m={destroy:a=>{let b=d(a).attr("id");g.hasOwnProperty(b)&&(clearTimeout(g[b]),delete g[b]);d(a).html("");d(a).hasClass("jqclock")&&d(a).removeClass("jqclock");d(a).removeData("clockoptions")},stop:a=>{a=d(a).attr("id");g.hasOwnProperty(a)&&(clearTimeout(g[a]),delete g[a])},start:a=>{let b=d(a).attr("id"),c=d(a).data("clockoptions");void 0!==c&&!1===g.hasOwnProperty(b)&&(g[b]=setTimeout(()=>{q(a)},c.rate))}},w=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const b=16*Math.random()| +0;return("x"===a?b:b&3|8).toString(16)}).toUpperCase(),q=a=>{let b={};b.myoptions=d(a).data("clockoptions");b.currentTzOffset=(new Date).getTimezoneOffset();b.correction=b.currentTzOffset===b.myoptions.tzOffset?0:6E4*(b.currentTzOffset-b.myoptions.tzOffset);b.pfnow=performance.now();b.mytimestamp=performance.timeOrigin+b.pfnow+b.myoptions.sysdiff+b.correction;b.mytimestamp_sysdiff=new Date(b.mytimestamp);b.h=b.mytimestamp_sysdiff.getHours();b.m=b.mytimestamp_sysdiff.getMinutes();b.s=b.mytimestamp_sysdiff.getSeconds(); +b.ms=b.mytimestamp_sysdiff.getMilliseconds();b.us=(""+b.pfnow%1).substring(2,5);b.dy=b.mytimestamp_sysdiff.getDay();b.dt=b.mytimestamp_sysdiff.getDate();b.mo=b.mytimestamp_sysdiff.getMonth();b.y=b.mytimestamp_sysdiff.getFullYear();b.ly=b.mytimestamp_sysdiff.isLeapYear();b.doy=b.mytimestamp_sysdiff.getDOY();b.woy=b.mytimestamp_sysdiff.getWOY();b.iso8601Year=b.mytimestamp_sysdiff.getWOY(!0);b.dim=b.mytimestamp_sysdiff.daysInMonth();b.swt=b.mytimestamp_sysdiff.swatchTime();b.tzH=parseInt(b.myoptions.tzOffset/ +60);b.tzS=parseInt(60*b.myoptions.tzOffset);b.ap="AM";b.calendElem="";b.clockElem="";11{q(a)},b.myoptions.rate)},x=a=>{let b="",c;const {myoptions:f}=a;if(l(f.dateFormat))b=(new Intl.DateTimeFormat(f.locale,f.dateFormat)).format(a.mytimestamp_sysdiff);else for(let h=0;h<=f.dateFormat.length;h++)if(c= +f.dateFormat.charAt(h),c in r)b+=r[c](a);else switch(c){case String.fromCharCode(92):b+=f.dateFormat.charAt(++h);break;case "%":[b,h]=u(f,h,!0,b,c);break;default:b+=c}return''+b+""},y=a=>{let b="",c;const {myoptions:f}=a;if(l(f.timeFormat))b=(new Intl.DateTimeFormat(f.locale,f.timeFormat)).format(a.mytimestamp_sysdiff);else for(let h=0;h<=f.timeFormat.length;h++)if(c=f.timeFormat.charAt(h),c in t)b+=t[c](a);else switch(c){case String.fromCharCode(92):b+=f.timeFormat.charAt(++h); +break;case "%":[b,h]=u(f,h,!1,b,c);break;default:b+=c}return''+b+""},z=a=>{"string"!==typeof a.locale&&(a.locale=""+a.locale);"string"===typeof a.calendar?a.calendar="false"===a.calendar?!1:!0:"boolean"!==typeof a.calendar&&(a.calendar=!!a.calendar);if("string"!==typeof a.dateFormat)if(l(a.dateFormat))if(!1===Object.keys(a.dateFormat).every(c=>n.includes(c))){var b=Object.keys(a.dateFormat).reduce((c,f)=>{!1===n.includes(f)&&c.push(f);return c},[]);console.error(`unrecognized options passed to dateFormat option: ${b.join(", ")}. Valid options are: ${n.join(", ")}`)}else a.calendar= +!0;else!1!==a.dateFormat&&(console.error(`dateFormat option has unsupported type, must be either string or object instead is ${Object.prototype.toString.call(a.dateFormat)}`),a.dateFormat=!1),a.calendar=!1;else"false"===a.dateFormat?(a.dateFormat=!1,a.calendar=!1):a.calendar=!0;"string"!==typeof a.timeFormat&&(l(a.timeFormat)?!1===Object.keys(a.timeFormat).every(c=>p.includes(c))&&(b=Object.keys(a.timeFormat).reduce((c,f)=>{!1===p.includes(f)&&c.push(f);return c},[]),console.error(`unrecognized options passed to timeFormat option: ${b.join(", ")}. Valid options are: ${p.join(", ")}`)): +(console.error(`timeFormat option has unsupported type, must be either string or object instead is ${Object.prototype.toString.call(a.dateFormat)}`),a.timeFormat=""+a.timeFormat));"string"!==typeof a.timezone&&(a.timezone=""+a.timezone);"string"===typeof a.isDST?a.isDST="true"===a.isDST?!0:!1:"boolean"!==typeof a.isDST&&(a.isDST=!!a.isDST);"number"!==typeof a.rate&&(a.rate=parseInt(a.rate));return a},u=(a,b,c,f,h)=>{a=c?a.dateFormat:a.timeFormat;for(c=b+1;cb+1&& +c!==a.length?(f+=a.substring(b+1,c),b+=c-b):f+=h;return[f,b]},v=(a,b)=>{a.timezone="UTC";let c=b%1;b-=c;let f="";0!==Math.abs(c)&&(f=""+Math.abs(c).map(0,1,0,60));0>b?a.timezone+="+"+Math.abs(b)+(""!==f?":"+f:""):0{if("undefined"===typeof e||"object"===typeof e){a=performance.timeOrigin+performance.now();a=new Date(a);b=l(e)&&e.isDST?e.isDST:null;var c=e;c=c||{};c.timestamp=c.timestamp||"localsystime";c.hasOwnProperty("langSet")&& +console.warn("the `langSet` option has been changed to `locale` since v2.3.7 and will be removed in a future release. Please use `locale` in place of `langSet`.");c.locale=c.locale||c.langSet||navigator.language||"en";c.hasOwnProperty("calendar")&&console.warn("the `calendar` option is deprecated since jqclock v2.3.7 and will be removed in a future release. Please use `dateFormat: false` instead of `calendar: false` to remove the calendar from the jQuery Clock.");c.calendar=c.hasOwnProperty("calendar")? +c.calendar:!0;c.dateFormat=c.dateFormat??{dateStyle:"full"};c.timeFormat=c.timeFormat||{timeStyle:"medium"};c.timezone=c.timezone||"localsystimezone";c.isDST=c.hasOwnProperty("isDST")?c.isDST:a.isDST();c.rate=c.rate||500;e=c;e=z(e);e.tzOffset=a.getTimezoneOffset();const f=e.tzOffset/60;e.sysdiff=0;"localsystime"!==e.timestamp?(c=e,2<(a.getTime()+"").length-(c.timestamp+"").length?(c=e,c.timestamp*=1E3,c.sysdiff=c.timestamp-a.getTime()+6E4*c.tzOffset,e=c,null===b&&console.warn("jqClock: cannot automatically determine whether DST is in effect for a server side timestamp, please supply the `isDST` option")): +(e.sysdiff=e.timestamp-a.getTime(),"localsystimezone"===e.timezone&&(e=v(e,f)))):"localsystimezone"===e.timezone&&(e=v(e,f));a=e;d(this).hasClass("jqclock")||d(this).addClass("jqclock");d(this).is("[id]")||d(this).attr("id",w());d(this).data("clockoptions",a);!1===g.hasOwnProperty(d(this).attr("id"))&&q(this)}else if("string"===typeof e)if(e in m)m[e](b);else console.error("You are calling an undefined method on a jqClock instance")});return this.initialize()};return this})(jQuery);