2 lines
6.4 KiB
JavaScript
2 lines
6.4 KiB
JavaScript
import*as C from"./constant";import en from"./locale/en";import U from"./utils";var L="en",Ls={};Ls[L]=en;var IS_DAYJS="$isDayjsObject",isDayjs=function(t){return t instanceof Dayjs||!(!t||!t[IS_DAYJS])},parseLocale=function t(e,s,r){var n;if(!e)return L;if("string"==typeof e){var i=e.toLowerCase();Ls[i]&&(n=i),s&&(Ls[i]=s,n=i);var a=e.split("-");if(!n&&a.length>1)return t(a[0])}else{var u=e.name;Ls[u]=e,n=u}return!r&&n&&(L=n),n||!r&&L},dayjs=function(t,e){if(isDayjs(t))return t.clone();var s="object"==typeof e?e:{};return s.date=t,s.args=arguments,new Dayjs(s)},wrapper=function(t,e){return dayjs(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})},Utils=U;Utils.l=parseLocale,Utils.i=isDayjs,Utils.w=wrapper;var parseDate=function(t){var e=t.date,s=t.utc;if(null===e)return new Date(NaN);if(Utils.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(C.REGEX_PARSE);if(r){var n=r[2]-1||0,i=(r[7]||"0").substring(0,3);return s?new Date(Date.UTC(r[1],n,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)):new Date(r[1],n,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)}}return new Date(e)},Dayjs=function(){function t(t){this.$L=parseLocale(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[IS_DAYJS]=!0}var e=t.prototype;return e.parse=function(t){this.$d=parseDate(t),this.init()},e.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},e.$utils=function(){return Utils},e.isValid=function(){return!(this.$d.toString()===C.INVALID_DATE_STRING)},e.isSame=function(t,e){var s=dayjs(t);return this.startOf(e)<=s&&s<=this.endOf(e)},e.isAfter=function(t,e){return dayjs(t)<this.startOf(e)},e.isBefore=function(t,e){return this.endOf(e)<dayjs(t)},e.$g=function(t,e,s){return Utils.u(t)?this[e]:this.set(s,t)},e.unix=function(){return Math.floor(this.valueOf()/1e3)},e.valueOf=function(){return this.$d.getTime()},e.startOf=function(t,e){var s=this,r=!!Utils.u(e)||e,n=Utils.p(t),i=function(t,e){var n=Utils.w(s.$u?Date.UTC(s.$y,e,t):new Date(s.$y,e,t),s);return r?n:n.endOf(C.D)},a=function(t,e){return Utils.w(s.toDate()[t].apply(s.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),s)},u=this.$W,c=this.$M,o=this.$D,f="set"+(this.$u?"UTC":"");switch(n){case C.Y:return r?i(1,0):i(31,11);case C.M:return r?i(1,c):i(0,c+1);case C.W:var l=this.$locale().weekStart||0,h=(u<l?u+7:u)-l;return i(r?o-h:o+(6-h),c);case C.D:case C.DATE:return a(f+"Hours",0);case C.H:return a(f+"Minutes",1);case C.MIN:return a(f+"Seconds",2);case C.S:return a(f+"Milliseconds",3);default:return this.clone()}},e.endOf=function(t){return this.startOf(t,!1)},e.$set=function(t,e){var s,r=Utils.p(t),n="set"+(this.$u?"UTC":""),i=(s={},s[C.D]=n+"Date",s[C.DATE]=n+"Date",s[C.M]=n+"Month",s[C.Y]=n+"FullYear",s[C.H]=n+"Hours",s[C.MIN]=n+"Minutes",s[C.S]=n+"Seconds",s[C.MS]=n+"Milliseconds",s)[r],a=r===C.D?this.$D+(e-this.$W):e;if(r===C.M||r===C.Y){var u=this.clone().set(C.DATE,1);u.$d[i](a),u.init(),this.$d=u.set(C.DATE,Math.min(this.$D,u.daysInMonth())).$d}else i&&this.$d[i](a);return this.init(),this},e.set=function(t,e){return this.clone().$set(t,e)},e.get=function(t){return this[Utils.p(t)]()},e.add=function(t,e){var s,r=this;t=Number(t);var n=Utils.p(e),i=function(e){var s=dayjs(r);return Utils.w(s.date(s.date()+Math.round(e*t)),r)};if(n===C.M)return this.set(C.M,this.$M+t);if(n===C.Y)return this.set(C.Y,this.$y+t);if(n===C.D)return i(1);if(n===C.W)return i(7);var a=(s={},s[C.MIN]=C.MILLISECONDS_A_MINUTE,s[C.H]=C.MILLISECONDS_A_HOUR,s[C.S]=C.MILLISECONDS_A_SECOND,s)[n]||1,u=this.$d.getTime()+t*a;return Utils.w(u,this)},e.subtract=function(t,e){return this.add(-1*t,e)},e.format=function(t){var e=this,s=this.$locale();if(!this.isValid())return s.invalidDate||C.INVALID_DATE_STRING;var r=t||C.FORMAT_DEFAULT,n=Utils.z(this),i=this.$H,a=this.$m,u=this.$M,c=s.weekdays,o=s.months,f=s.meridiem,l=function(t,s,n,i){return t&&(t[s]||t(e,r))||n[s].slice(0,i)},h=function(t){return Utils.s(i%12||12,t,"0")},$=f||function(t,e,s){var r=t<12?"AM":"PM";return s?r.toLowerCase():r};return r.replace(C.REGEX_FORMAT,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return Utils.s(e.$y,4,"0");case"M":return u+1;case"MM":return Utils.s(u+1,2,"0");case"MMM":return l(s.monthsShort,u,o,3);case"MMMM":return l(o,u);case"D":return e.$D;case"DD":return Utils.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return l(s.weekdaysMin,e.$W,c,2);case"ddd":return l(s.weekdaysShort,e.$W,c,3);case"dddd":return c[e.$W];case"H":return String(i);case"HH":return Utils.s(i,2,"0");case"h":return h(1);case"hh":return h(2);case"a":return $(i,a,!0);case"A":return $(i,a,!1);case"m":return String(a);case"mm":return Utils.s(a,2,"0");case"s":return String(e.$s);case"ss":return Utils.s(e.$s,2,"0");case"SSS":return Utils.s(e.$ms,3,"0");case"Z":return n}return null}(t)||n.replace(":","")}))},e.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},e.diff=function(t,e,s){var r,n=this,i=Utils.p(e),a=dayjs(t),u=(a.utcOffset()-this.utcOffset())*C.MILLISECONDS_A_MINUTE,c=this-a,o=function(){return Utils.m(n,a)};switch(i){case C.Y:r=o()/12;break;case C.M:r=o();break;case C.Q:r=o()/3;break;case C.W:r=(c-u)/C.MILLISECONDS_A_WEEK;break;case C.D:r=(c-u)/C.MILLISECONDS_A_DAY;break;case C.H:r=c/C.MILLISECONDS_A_HOUR;break;case C.MIN:r=c/C.MILLISECONDS_A_MINUTE;break;case C.S:r=c/C.MILLISECONDS_A_SECOND;break;default:r=c}return s?r:Utils.a(r)},e.daysInMonth=function(){return this.endOf(C.M).$D},e.$locale=function(){return Ls[this.$L]},e.locale=function(t,e){if(!t)return this.$L;var s=this.clone(),r=parseLocale(t,e,!0);return r&&(s.$L=r),s},e.clone=function(){return Utils.w(this.$d,this)},e.toDate=function(){return new Date(this.valueOf())},e.toJSON=function(){return this.isValid()?this.toISOString():null},e.toISOString=function(){return this.$d.toISOString()},e.toString=function(){return this.$d.toUTCString()},t}(),proto=Dayjs.prototype;dayjs.prototype=proto,[["$ms",C.MS],["$s",C.S],["$m",C.MIN],["$H",C.H],["$W",C.D],["$M",C.M],["$y",C.Y],["$D",C.DATE]].forEach((function(t){proto[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),dayjs.extend=function(t,e){return t.$i||(t(e,Dayjs,dayjs),t.$i=!0),dayjs},dayjs.locale=parseLocale,dayjs.isDayjs=isDayjs,dayjs.unix=function(t){return dayjs(1e3*t)},dayjs.en=Ls[L],dayjs.Ls=Ls,dayjs.p={};export default dayjs;
|
|
//# sourceMappingURL=index.js.map
|