forked from iamkun/dayjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dayjs.min.js
1 lines (1 loc) · 8.85 KB
/
dayjs.min.js
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).dayjs=e()}(this,(function(){"use strict";function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var e=1e3,n=6e4,i=36e5,r="millisecond",s="second",c="minute",a="hour",u="day",o="week",h="month",d="quarter",f="year",l="date",$="Invalid Date",v=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,_={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var i=String(t);return!i||i.length>=e?t:""+Array(e+1-i.length).join(n)+t},g={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),i=Math.floor(n/60),r=n%60;return(e<=0?"+":"-")+m(i,2,"0")+":"+m(r,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var i=12*(n.year()-e.year())+(n.month()-e.month()),r=e.clone().add(i,h),s=n-r<0,c=e.clone().add(i+(s?-1:1),h);return+(-(i+(n-r)/(s?r-c:c-r))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:h,y:f,w:o,d:u,D:l,h:a,m:c,s:s,ms:r,Q:d}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},M="en",S={};S[M]=_;var D="$isDayjsObject",p=function(t){return t instanceof k||!(!t||!t[D])},O=function t(e,n,i){var r;if(!e)return M;if("string"==typeof e){var s=e.toLowerCase();S[s]&&(r=s),n&&(S[s]=n,r=s);var c=e.split("-");if(!r&&c.length>1)return t(c[0])}else{var a=e.name;S[a]=e,r=a}return!i&&r&&(M=r),r||!i&&M},w=function(t,e){if(p(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new k(n)},b=g;b.l=O,b.i=p,b.w=function(t,e){return w(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var k=function(){function _(t){this.$L=O(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[D]=!0}var m,g,M,p=_.prototype;return p.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var i=e.match(v);if(i){var r=i[2]-1||0,s=(i[7]||"0").substring(0,3);return n?new Date(Date.UTC(i[1],r,i[3]||1,i[4]||0,i[5]||0,i[6]||0,s)):new Date(i[1],r,i[3]||1,i[4]||0,i[5]||0,i[6]||0,s)}}return new Date(e)}(t),this.init()},p.init=function(){this.cached_y=void 0,this.cached_M=void 0,this.cached_D=void 0,this.cached_W=void 0,this.cached_H=void 0,this.cached_m=void 0,this.cached_s=void 0,this.cached_ms=void 0,this.cached_timezoneOffset=void 0},p.$utils=function(){return b},p.isValid=function(){return!(this.$d.toString()===$)},p.isSame=function(t,e){var n=w(t);return void 0===e?!(!this.isValid()||!n.isValid())&&this.toISOString()===n.toISOString():this.startOf(e)<=n&&n<=this.endOf(e)},p.isAfter=function(t,e){if(void 0===e){var n=w(t);return!(!this.isValid()||!n.isValid())&&this.toISOString()>n.toISOString()}return w(t)<this.startOf(e)},p.isBefore=function(t,e){if(void 0===e){var n=w(t);return!(!this.isValid()||!n.isValid())&&this.toISOString()<n.toISOString()}return this.endOf(e)<w(t)},p.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},p.unix=function(){return Math.floor(this.valueOf()/1e3)},p.valueOf=function(){return this.$d.getTime()},p.startOf=function(t,e){var n=this,i=!!b.u(e)||e,r=b.p(t),d=function(t,e){var r=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return i?r:r.endOf(u)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(i?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},v=this.$W,y=this.$M,_=this.$D,m="set"+(this.$u?"UTC":"");switch(r){case f:return i?d(1,0):d(31,11);case h:return i?d(1,y):d(0,y+1);case o:var g=this.$locale().weekStart||0,M=(v<g?v+7:v)-g;return d(i?_-M:_+(6-M),y);case u:case l:return $(m+"Hours",0);case a:return $(m+"Minutes",1);case c:return $(m+"Seconds",2);case s:return $(m+"Milliseconds",3);default:return this.clone()}},p.endOf=function(t){return this.startOf(t,!1)},p.$set=function(t,e){var n,i=b.p(t),o="set"+(this.$u?"UTC":""),d=(n={},n[u]=o+"Date",n[l]=o+"Date",n[h]=o+"Month",n[f]=o+"FullYear",n[a]=o+"Hours",n[c]=o+"Minutes",n[s]=o+"Seconds",n[r]=o+"Milliseconds",n)[i],$=i===u?this.$D+(e-this.$W):e;if(i===h||i===f){var v=this.clone().set(l,1);v.$d[d]($),v.init(),this.$d=v.set(l,Math.min(this.$D,v.daysInMonth())).$d}else d&&this.$d[d]($);return this.init(),this},p.set=function(t,e){return this.clone().$set(t,e)},p.get=function(t){return this[b.p(t)]()},p.add=function(t,r){var d,l=this;t=Number(t);var $=b.p(r),v=function(e){var n=w(l);return b.w(n.date(n.date()+Math.round(e*t)),l)};if($===h)return this.set(h,this.$M+t);if($===f)return this.set(f,this.$y+t);if($===u)return v(1);if($===o)return v(7);var y=(d={},d[c]=n,d[a]=i,d[s]=e,d)[$]||1,_=this.$d.getTime()+t*y;return b.w(_,this)},p.subtract=function(t,e){return this.add(-1*t,e)},p.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||$;var i=t||"YYYY-MM-DDTHH:mm:ssZ",r=b.z(this),s=this.$H,c=this.$m,a=this.$M,u=n.weekdays,o=n.months,h=n.meridiem,d=function(t,n,r,s){return t&&(t[n]||t(e,i))||r[n].slice(0,s)},f=function(t){return b.s(s%12||12,t,"0")},l=h||function(t,e,n){var i=t<12?"AM":"PM";return n?i.toLowerCase():i};return i.replace(y,(function(t,i){return i||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return d(n.monthsShort,a,o,3);case"MMMM":return d(o,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return d(n.weekdaysMin,e.$W,u,2);case"ddd":return d(n.weekdaysShort,e.$W,u,3);case"dddd":return u[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return l(s,c,!0);case"A":return l(s,c,!1);case"m":return String(c);case"mm":return b.s(c,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return r}return null}(t)||r.replace(":","")}))},p.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},p.diff=function(t,r,l){var $,v=this,y=b.p(r),_=w(t),m=(_.utcOffset()-this.utcOffset())*n,g=this-_,M=function(){return b.m(v,_)};switch(y){case f:$=M()/12;break;case h:$=M();break;case d:$=M()/3;break;case o:$=(g-m)/6048e5;break;case u:$=(g-m)/864e5;break;case a:$=g/i;break;case c:$=g/n;break;case s:$=g/e;break;default:$=g}return l?$:b.a($)},p.daysInMonth=function(){return this.endOf(h).$D},p.$locale=function(){return S[this.$L]},p.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),i=O(t,e,!0);return i&&(n.$L=i),n},p.clone=function(){return b.w(this.$d,this)},p.toDate=function(){return new Date(this.valueOf())},p.toJSON=function(){return this.isValid()?this.toISOString():null},p.toISOString=function(){return this.$d.toISOString()},p.toString=function(){return this.$d.toUTCString()},m=_,(g=[{key:"$y",get:function(){return void 0===this.cached_y&&(this.cached_y=this.$d.getFullYear()),this.cached_y},set:function(t){this.cached_y=t}},{key:"$M",get:function(){return void 0===this.cached_M&&(this.cached_M=this.$d.getMonth()),this.cached_M},set:function(t){this.cached_M=t}},{key:"$D",get:function(){return void 0===this.cached_D&&(this.cached_D=this.$d.getDate()),this.cached_D},set:function(t){this.cached_D=t}},{key:"$W",get:function(){return void 0===this.cached_W&&(this.cached_W=this.$d.getDay()),this.cached_W},set:function(t){this.cached_W=t}},{key:"$H",get:function(){return void 0===this.cached_H&&(this.cached_H=this.$d.getHours()),this.cached_H},set:function(t){this.cached_H=t}},{key:"$m",get:function(){return void 0===this.cached_m&&(this.cached_m=this.$d.getMinutes()),this.cached_m},set:function(t){this.cached_m=t}},{key:"$s",get:function(){return void 0===this.cached_s&&(this.cached_s=this.$d.getSeconds()),this.cached_s},set:function(t){this.cached_s=t}},{key:"$ms",get:function(){return void 0===this.cached_ms&&(this.cached_ms=this.$d.getMilliseconds()),this.cached_ms},set:function(t){this.cached_ms=t}},{key:"$timezoneOffset",get:function(){return void 0===this.cached_timezoneOffset&&(this.cached_timezoneOffset=this.$d.getTimezoneOffset()),this.cached_timezoneOffset},set:function(t){this.cached_timezoneOffset=t}}])&&t(m.prototype,g),M&&t(m,M),Object.defineProperty(m,"prototype",{writable:!1}),_}(),H=k.prototype;return w.prototype=H,[["$ms",r],["$s",s],["$m",c],["$H",a],["$W",u],["$M",h],["$y",f],["$D",l]].forEach((function(t){H[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),w.extend=function(t,e){return t.$i||(t(e,k,w),t.$i=!0),w},w.locale=O,w.isDayjs=p,w.unix=function(t){return w(1e3*t)},w.en=S[M],w.Ls=S,w.p={},w}));