-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
jqClock-lite.min.js
23 lines (23 loc) · 11 KB
/
jqClock-lite.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Date.prototype.hasOwnProperty("stdTimezoneOffset")||(Date.prototype.stdTimezoneOffset=function(){const d=this.getFullYear();if(!Date.prototype.stdTimezoneOffset.cache.hasOwnProperty(d)){let g=(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!==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()<this.stdTimezoneOffset()});Date.prototype.hasOwnProperty("isLeapYear")||(Date.prototype.isLeapYear=function(){const d=this.getFullYear();return 0!==(d&3)?!1:0!==d%100||0===d%400});Date.prototype.hasOwnProperty("getDOY")||(Date.prototype.getDOY=function(){const d=this.getMonth();var g=this.getDate();g=[0,31,59,90,120,151,181,212,243,273,304,334][d]+g;1<d&&this.isLeapYear()&&g++;return g});
Date.prototype.hasOwnProperty("daysInMonth")||(Date.prototype.daysInMonth=function(){return[31,this.isLeapYear()?29:28,31,30,31,30,31,31,30,31,30,31][this.getMonth()]});
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=>/(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<a.tzH?(""+-1*a.tzH).padStart(2,"0"):"+00")+"00",P:a=>(0>a.tzH?"+"+(""+Math.abs(a.tzH)).padStart(2,"0"):0<a.tzH?(""+-1*a.tzH).padStart(2,"0"):"+00")+":00",T:a=>/(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):0<a.tzS?""+-1*a.tzS:"0",c:a=>a.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<a.tzH?(""+-1*a.tzH).padStart(2,"0"):"+00")+":00",r:a=>(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"):0<a.tzh?(""+-1*a.tzh).padStart(2,"0"):"+00")+"00",U:a=>Math.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<b.h&&(b.ap="PM");b.H12=b.h;12<b.H12?b.H12-=12:0===b.H12&&(b.H12=12);!0===b.myoptions.calendar&&(b.calendElem=x(b));b.clockElem=y(b);d(a).html(b.calendElem+b.clockElem);let c=d(a).attr("id");g[c]=setTimeout(()=>{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'<span class="clockdate">'+b+"</span>"},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'<span class="clocktime">'+b+"</span>"},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;c<a.length&&"%"!==a.charAt(c);)c++;c>b+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<b&&(a.timezone+=-1*b+(""!==f?":"+f:""));return a};this.each((a,b)=>{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);