diff --git a/jqClock-lite.js b/jqClock-lite.js index 5834a89..92287f5 100644 --- a/jqClock-lite.js +++ b/jqClock-lite.js @@ -11,8 +11,7 @@ * @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 * @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 Intl.DateTimeFormat options object { "dateStyle": "full" }; can take string with PHP style format characters; if set to false @calendar will be false + * @dateFormat defaults to Intl.DateTimeFormat options object { "dateStyle": "full" }; can take string with PHP style format characters; if set to false will remove calendar output * @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) * @@ -268,7 +267,10 @@ if (!Number.prototype.map) { //TIMEZONE //Timezone identifier - "e": ( clk ) => clk.myoptions.timezone, + "e": ( clk ) => /(UTC|GMT)\+/.test( clk.myoptions.timezone ) ? clk.myoptions.timezone : new Intl.DateTimeFormat( clk.myoptions.locale, { + timeZone: clk.myoptions.timezone, + timeZoneName: "long" + } ).formatToParts( clk.mytimestamp_sysdiff ).filter(e => e.type === 'timeZoneName')[0].value, //Whether or not the date is in daylight saving time "I": ( clk ) => clk.myoptions.isDST ? "DST" : "", //Difference to Greenwich time (GMT) in hours diff --git a/jqClock-lite.min.js b/jqClock-lite.min.js index 0a6810b..71abf3e 100644 --- a/jqClock-lite.min.js +++ b/jqClock-lite.min.js @@ -5,19 +5,19 @@ Date.prototype.hasOwnProperty("getWOY")||(Date.prototype.getWOY=function(d=!1){c 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/(UTC|GMT)\+/.test(a.myoptions.timezone)?a.myoptions.timezone:(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"short"})).formatToParts(a.mytimestamp_sysdiff).filter(b=>"timeZoneName"===b.type)[0].value,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); +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=>/(UTC|GMT)\+/.test(a.myoptions.timezone)?a.myoptions.timezone:(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"long"})).formatToParts(a.mytimestamp_sysdiff).filter(b=> +"timeZoneName"===b.type)[0].value,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/(UTC|GMT)\+/.test(a.myoptions.timezone)?a.myoptions.timezone:(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"short"})).formatToParts(a.mytimestamp_sysdiff).filter(b=>"timeZoneName"=== +b.type)[0].value,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 b0e2d6f..a36d8de 100644 --- a/jqClock.min.js +++ b/jqClock.min.js @@ -10,19 +10,19 @@ type:"String | Object | false",values:"dDjlNSwzWFmMntLoYy".split(""),default:{da 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 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/(UTC|GMT)\+/.test(a.myoptions.timezone)?a.myoptions.timezone:(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"short"})).formatToParts(a.mytimestamp_sysdiff).filter(b=>"timeZoneName"===b.type)[0].value,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); +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=>/(UTC|GMT)\+/.test(a.myoptions.timezone)?a.myoptions.timezone:(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"long"})).formatToParts(a.mytimestamp_sysdiff).filter(b=>"timeZoneName"===b.type)[0].value,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/(UTC|GMT)\+/.test(a.myoptions.timezone)?a.myoptions.timezone:(new Intl.DateTimeFormat(a.myoptions.locale,{timeZone:a.myoptions.timezone,timeZoneName:"short"})).formatToParts(a.mytimestamp_sysdiff).filter(b=>"timeZoneName"===b.type)[0].value,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);