-
Notifications
You must be signed in to change notification settings - Fork 42
/
date-and-time.min.js
4 lines (4 loc) · 7.22 KB
/
date-and-time.min.js
1
2
3
4
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).date=t()}(this,(function(){"use strict";
/**
* @preserve date-and-time (c) KNOWLEDGECODE | MIT
*/var e,t={},n={},r="en",u={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"]},i={YYYY:function(e){return("000"+e.getFullYear()).slice(-4)},YY:function(e){return("0"+e.getFullYear()).slice(-2)},Y:function(e){return""+e.getFullYear()},MMMM:function(e){return this.res.MMMM[e.getMonth()]},MMM:function(e){return this.res.MMM[e.getMonth()]},MM:function(e){return("0"+(e.getMonth()+1)).slice(-2)},M:function(e){return""+(e.getMonth()+1)},DD:function(e){return("0"+e.getDate()).slice(-2)},D:function(e){return""+e.getDate()},HH:function(e){return("0"+e.getHours()).slice(-2)},H:function(e){return""+e.getHours()},A:function(e){return this.res.A[e.getHours()>11|0]},hh:function(e){return("0"+(e.getHours()%12||12)).slice(-2)},h:function(e){return""+(e.getHours()%12||12)},mm:function(e){return("0"+e.getMinutes()).slice(-2)},m:function(e){return""+e.getMinutes()},ss:function(e){return("0"+e.getSeconds()).slice(-2)},s:function(e){return""+e.getSeconds()},SSS:function(e){return("00"+e.getMilliseconds()).slice(-3)},SS:function(e){return("0"+(e.getMilliseconds()/10|0)).slice(-2)},S:function(e){return""+(e.getMilliseconds()/100|0)},dddd:function(e){return this.res.dddd[e.getDay()]},ddd:function(e){return this.res.ddd[e.getDay()]},dd:function(e){return this.res.dd[e.getDay()]},Z:function(e){var t=e.getTimezoneOffset()/.6|0;return(t>0?"-":"+")+("000"+Math.abs(t-(t%100*.4|0))).slice(-4)},ZZ:function(e){var t=e.getTimezoneOffset(),n=Math.abs(t);return(t>0?"-":"+")+("0"+(n/60|0)).slice(-2)+":"+("0"+n%60).slice(-2)},post:function(e){return e},res:u},o={YYYY:function(e){return this.exec(/^\d{4}/,e)},Y:function(e){return this.exec(/^\d{1,4}/,e)},MMMM:function(e){var t=this.find(this.res.MMMM,e);return t.value++,t},MMM:function(e){var t=this.find(this.res.MMM,e);return t.value++,t},MM:function(e){return this.exec(/^\d\d/,e)},M:function(e){return this.exec(/^\d\d?/,e)},DD:function(e){return this.exec(/^\d\d/,e)},D:function(e){return this.exec(/^\d\d?/,e)},HH:function(e){return this.exec(/^\d\d/,e)},H:function(e){return this.exec(/^\d\d?/,e)},A:function(e){return this.find(this.res.A,e)},hh:function(e){return this.exec(/^\d\d/,e)},h:function(e){return this.exec(/^\d\d?/,e)},mm:function(e){return this.exec(/^\d\d/,e)},m:function(e){return this.exec(/^\d\d?/,e)},ss:function(e){return this.exec(/^\d\d/,e)},s:function(e){return this.exec(/^\d\d?/,e)},SSS:function(e){return this.exec(/^\d{1,3}/,e)},SS:function(e){var t=this.exec(/^\d\d?/,e);return t.value*=10,t},S:function(e){var t=this.exec(/^\d/,e);return t.value*=100,t},Z:function(e){var t=this.exec(/^[+-]\d{2}[0-5]\d/,e);return t.value=-60*(t.value/100|0)-t.value%100,t},ZZ:function(e){var t=/^([+-])(\d{2}):([0-5]\d)/.exec(e)||["","","",""];return{value:0-(60*(t[1]+t[2]|0)+(t[1]+t[3]|0)),length:t[0].length}},h12:function(e,t){return(12===e?0:e)+12*t},exec:function(e,t){var n=(e.exec(t)||[""])[0];return{value:0|n,length:n.length}},find:function(e,t){for(var n,r=-1,u=0,i=0,o=e.length;i<o;i++)n=e[i],!t.indexOf(n)&&n.length>u&&(r=i,u=n.length);return{value:r,length:u}},pre:function(e){return e},res:u},s=function(e,t,n,r){var u,i={};for(u in e)i[u]=e[u];for(u in t||{})!!n^!!i[u]||(i[u]=t[u]);return r&&(i.res=r),i},a={_formatter:i,_parser:o};return a.compile=function(e){return[e].concat(e.match(/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g)||[])},a.format=function(t,n,r){for(var u,i=this||e,o="string"==typeof n?i.compile(n):n,s=i._formatter,a=function(){if(r){var e=new Date(t.getTime());return e.getFullYear=e.getUTCFullYear,e.getMonth=e.getUTCMonth,e.getDate=e.getUTCDate,e.getHours=e.getUTCHours,e.getMinutes=e.getUTCMinutes,e.getSeconds=e.getUTCSeconds,e.getMilliseconds=e.getUTCMilliseconds,e.getDay=e.getUTCDay,e.getTimezoneOffset=function(){return 0},e.getTimezoneName=function(){return"UTC"},e}return t}(),c=/^\[(.*)\]$/,f="",d=1,l=o.length;d<l;d++)f+=s[u=o[d]]?s.post(s[u](a,o[0])):c.test(u)?u.replace(c,"$1"):u;return f},a.preparse=function(t,n){var r=this||e,u="string"==typeof n?r.compile(n):n,i=r._parser,o={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},s=/^\[(.*)\]$/;t=i.pre(t);for(var a,c,f,d=1,l=u.length;d<l;d++)if(a=u[d],c=t.substring(o._index),i[a]){if(!(f=i[a](c,u[0])).length)break;o[f.token||a.charAt(0)]=f.value,o._index+=f.length,o._match++}else if(a===c.charAt(0)||" "===a)o._index++;else{if(!s.test(a)||c.indexOf(a.replace(s,"$1"))){if("..."===a){o._index=t.length;break}break}o._index+=a.length-2}return o.H=o.H||i.h12(o.h,o.A),o._length=t.length,o},a.parse=function(t,n,r){var u=this||e,i="string"==typeof n?u.compile(n):n,o=u.preparse(t,i);return u.isValid(o)?(o.M-=o.Y<100?22801:1,r||~u._parser.find(i,"ZZ").value?new Date(Date.UTC(o.Y,o.M,o.D,o.H,o.m+o.Z,o.s,o.S)):new Date(o.Y,o.M,o.D,o.H,o.m,o.s,o.S)):new Date(NaN)},a.isValid=function(t,n){var r="string"==typeof t?(this||e).preparse(t,n):t;return!(r._index<1||r._length<1||r._index-r._length||r._match<1||r.Y<1||r.Y>9999||r.M<1||r.M>12||r.D<1||r.D>new Date(r.Y,r.M,0).getDate()||r.H<0||r.H>23||r.m<0||r.m>59||r.s<0||r.s>59||r.S<0||r.S>999||r.Z<-840||r.Z>720)},a.transform=function(t,n,r,u){const i=this||e;return i.format(i.parse(t,n),r,u)},a.addYears=function(t,n,r){return(this||e).addMonths(t,12*n,r)},a.addMonths=function(e,t,n){var r=new Date(e.getTime());if(n){if(r.setUTCMonth(r.getUTCMonth()+t),r.getUTCDate()<e.getUTCDate())return r.setUTCDate(0),r}else if(r.setMonth(r.getMonth()+t),r.getDate()<e.getDate())return r.setDate(0),r;return r},a.addDays=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCDate(r.getUTCDate()+t):r.setDate(r.getDate()+t),r},a.addHours=function(e,t){return new Date(e.getTime()+60*t*60*1e3)},a.addMinutes=function(e,t){return new Date(e.getTime()+60*t*1e3)},a.addSeconds=function(e,t){return new Date(e.getTime()+1e3*t)},a.addMilliseconds=function(e,t){return new Date(e.getTime()+t)},a.subtract=function(e,t){var n=e.getTime()-t.getTime();return{toMilliseconds:function(){return n},toSeconds:function(){return n/1e3},toMinutes:function(){return n/6e4},toHours:function(){return n/36e5},toDays:function(){return n/864e5}}},a.isLeapYear=function(e){return!((e%4||!(e%100))&&e%400)},a.isSameDay=function(e,t){return e.toDateString()===t.toDateString()},a.locale=function(e,n){t[e]||(t[e]=n)},a.plugin=function(e,t){n[e]||(n[e]=t)},(e=s(a)).locale=function(c){var f="function"==typeof c?c:e.locale[c];if(!f)return r;r=f(a);var d=t[r]||{},l=s(u,d.res,!0),g=s(i,d.formatter,!0,l),h=s(o,d.parser,!0,l);for(var M in e._formatter=g,e._parser=h,n)e.extend(n[M]);return r},e.extend=function(t){var n=s(e._parser.res,t.res),r=t.extender||{};for(var u in e._formatter=s(e._formatter,t.formatter,!1,n),e._parser=s(e._parser,t.parser,!1,n),r)e[u]||(e[u]=r[u])},e.plugin=function(t){var r="function"==typeof t?t:e.plugin[t];r&&e.extend(n[r(a,e)]||{})},e}));