Comparing version 1.8.8 to 1.8.9
@@ -0,1 +1,10 @@ | ||
## [1.8.9](https://github.com/iamkun/dayjs/compare/v1.8.8...v1.8.9) (2019-03-06) | ||
### Bug Fixes | ||
* Add de-AT locale ([#515](https://github.com/iamkun/dayjs/issues/515)) ([d93f7b6](https://github.com/iamkun/dayjs/commit/d93f7b6)) | ||
* Add UTC mode with UTC plugin ([#517](https://github.com/iamkun/dayjs/issues/517)) ([caf335c](https://github.com/iamkun/dayjs/commit/caf335c)) | ||
* Adding locale zh-hk ([#516](https://github.com/iamkun/dayjs/issues/516)) ([5fc05a6](https://github.com/iamkun/dayjs/commit/5fc05a6)) | ||
## [1.8.8](https://github.com/iamkun/dayjs/compare/v1.8.7...v1.8.8) (2019-02-25) | ||
@@ -2,0 +11,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.dayjs=n()}(this,function(){"use strict";var t="millisecond",n="second",e="minute",r="hour",i="day",s="week",u="month",a="year",o=/^(\d{4})-?(\d{1,2})-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})?$/,h=/\[.*?\]|Y{2,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,f=function(t,n,e){var r=String(t);return!r||r.length>=n?t:""+Array(n+1-r.length).join(e)+t},c={padStart:f,padZoneStr:function(t){var n=Math.abs(t),e=Math.floor(n/60),r=n%60;return(t<=0?"+":"-")+f(e,2,"0")+":"+f(r,2,"0")},monthDiff:function(t,n){var e=12*(n.year()-t.year())+(n.month()-t.month()),r=t.clone().add(e,"months"),i=n-r<0,s=t.clone().add(e+(i?-1:1),"months");return Number(-(e+(n-r)/(i?r-s:s-r))||0)},absFloor:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},prettyUnit:function(o){return{M:u,y:a,w:s,d:i,h:r,m:e,s:n,ms:t}[o]||String(o||"").toLowerCase().replace(/s$/,"")},isUndefined:function(t){return void 0===t}},d={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("_")},$="en",l={};l[$]=d;var m=function(t){return t instanceof D},y=function(t,n,e){var r;if(!t)return null;if("string"==typeof t)l[t]&&(r=t),n&&(l[t]=n,r=t);else{var i=t.name;l[i]=t,r=i}return e||($=r),r},M=function(t,n,e){if(m(t))return t.clone();var r=n?"string"==typeof n?{format:n,pl:e}:n:{};return r.date=t,new D(r)},p=function(t,n){return M(t,{locale:n.$L})},S=c;S.parseLocale=y,S.isDayjs=m,S.wrapper=p;var D=function(){function f(t){this.$L=this.$L||y(t.locale,null,!0)||$,this.parse(t)}var c=f.prototype;return c.parse=function(t){this.$d=function(t){if(null===t)return new Date(NaN);if(S.isUndefined(t))return new Date;if(t instanceof Date)return t;if("string"==typeof t&&!/Z$/i.test(t)){var n=t.match(o);if(n)return new Date(n[1],n[2]-1,n[3]||1,n[4]||0,n[5]||0,n[6]||0,n[7]||0)}return new Date(t)}(t.date),this.init()},c.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()},c.$utils=function(){return S},c.isValid=function(){return!("Invalid Date"===this.$d.toString())},c.isSame=function(t,n){var e=M(t);return this.startOf(n)<=e&&e<=this.endOf(n)},c.isAfter=function(t,n){return M(t)<this.startOf(n)},c.isBefore=function(t,n){return this.endOf(n)<M(t)},c.year=function(){return this.$y},c.month=function(){return this.$M},c.day=function(){return this.$W},c.date=function(){return this.$D},c.hour=function(){return this.$H},c.minute=function(){return this.$m},c.second=function(){return this.$s},c.millisecond=function(){return this.$ms},c.unix=function(){return Math.floor(this.valueOf()/1e3)},c.valueOf=function(){return this.$d.getTime()},c.startOf=function(t,o){var h=this,f=!!S.isUndefined(o)||o,c=S.prettyUnit(t),d=function(t,n){var e=p(new Date(h.$y,n,t),h);return f?e:e.endOf(i)},$=function(t,n){return p(h.toDate()[t].apply(h.toDate(),(f?[0,0,0,0]:[23,59,59,999]).slice(n)),h)},l=this.$W,m=this.$M,y=this.$D;switch(c){case a:return f?d(1,0):d(31,11);case u:return f?d(1,m):d(0,m+1);case s:var M=this.$locale().weekStart||0,D=(l<M?l+7:l)-M;return d(f?y-D:y+(6-D),m);case i:case"date":return $("setHours",0);case r:return $("setMinutes",1);case e:return $("setSeconds",2);case n:return $("setMilliseconds",3);default:return this.clone()}},c.endOf=function(t){return this.startOf(t,!1)},c.$set=function(s,o){var h,f=S.prettyUnit(s),c=(h={},h[i]="setDate",h.date="setDate",h[u]="setMonth",h[a]="setFullYear",h[r]="setHours",h[e]="setMinutes",h[n]="setSeconds",h[t]="setMilliseconds",h)[f],d=f===i?this.$D+(o-this.$W):o;return this.$d[c]&&this.$d[c](d),this.init(),this},c.set=function(t,n){return this.clone().$set(t,n)},c.add=function(t,o){var h,f=this;t=Number(t);var c=S.prettyUnit(o),d=function(n,e){var r=f.set("date",1).set(n,e+t);return r.set("date",Math.min(f.$D,r.daysInMonth()))},$=function(n){var e=new Date(f.$d);return e.setDate(e.getDate()+n*t),p(e,f)};if(c===u)return d(u,this.$M);if(c===a)return d(a,this.$y);if(c===i)return $(1);if(c===s)return $(7);var l=(h={},h[e]=6e4,h[r]=36e5,h[n]=1e3,h)[c]||1,m=this.valueOf()+t*l;return p(m,this)},c.subtract=function(t,n){return this.add(-1*t,n)},c.format=function(t){var n=this;if(!this.isValid())return"Invalid Date";var e=t||"YYYY-MM-DDTHH:mm:ssZ",r=S.padZoneStr(this.$d.getTimezoneOffset()),i=this.$locale(),s=i.weekdays,u=i.months,a=function(t,n,e,r){return t&&t[n]||e[n].substr(0,r)},o=function(t){return S.padStart(n.$H%12||12,t,"0")},f={YY:String(this.$y).slice(-2),YYYY:String(this.$y),M:String(this.$M+1),MM:S.padStart(this.$M+1,2,"0"),MMM:a(i.monthsShort,this.$M,u,3),MMMM:u[this.$M],D:String(this.$D),DD:S.padStart(this.$D,2,"0"),d:String(this.$W),dd:a(i.weekdaysMin,this.$W,s,2),ddd:a(i.weekdaysShort,this.$W,s,3),dddd:s[this.$W],H:String(this.$H),HH:S.padStart(this.$H,2,"0"),h:o(1),hh:o(2),a:this.$H<12?"am":"pm",A:this.$H<12?"AM":"PM",m:String(this.$m),mm:S.padStart(this.$m,2,"0"),s:String(this.$s),ss:S.padStart(this.$s,2,"0"),SSS:S.padStart(this.$ms,3,"0"),Z:r};return e.replace(h,function(t){return t.indexOf("[")>-1?t.replace(/\[|\]/g,""):f[t]||r.replace(":","")})},c.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},c.diff=function(t,o,h){var f,c=S.prettyUnit(o),d=M(t),$=6e4*(d.utcOffset()-this.utcOffset()),l=this-d,m=S.monthDiff(this,d);return m=(f={},f[a]=m/12,f[u]=m,f.quarter=m/3,f[s]=(l-$)/6048e5,f[i]=(l-$)/864e5,f[r]=l/36e5,f[e]=l/6e4,f[n]=l/1e3,f)[c]||l,h?m:S.absFloor(m)},c.daysInMonth=function(){return this.endOf(u).$D},c.$locale=function(){return l[this.$L]},c.locale=function(t,n){var e=this.clone();return e.$L=y(t,n,!0),e},c.clone=function(){return p(this.toDate(),this)},c.toDate=function(){return new Date(this.$d)},c.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]},c.toJSON=function(){return this.toISOString()},c.toISOString=function(){return this.$d.toISOString()},c.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}},c.toString=function(){return this.$d.toUTCString()},f}();return M.prototype=D.prototype,M.extend=function(t,n){return t(n,D,M),M},M.locale=y,M.isDayjs=m,M.unix=function(t){return M(1e3*t)},M.en=l[$],M.Ls=l,M}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.dayjs=n()}(this,function(){"use strict";var t="millisecond",n="second",e="minute",i="hour",r="day",s="week",u="month",o="year",a=/^(\d{4})-?(\d{1,2})-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})?$/,h=/\[.*?\]|Y{2,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,c=function(t,n,e){var i=String(t);return!i||i.length>=n?t:""+Array(n+1-i.length).join(e)+t},f={s:c,z:function(t){var n=-t.utcOffset(),e=Math.abs(n),i=Math.floor(e/60),r=e%60;return(n<=0?"+":"-")+c(i,2,"0")+":"+c(r,2,"0")},m:function(t,n){var e=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(e,u),r=n-i<0,s=t.clone().add(e+(r?-1:1),u);return Number(-(e+(n-i)/(r?i-s:s-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(a){return{M:u,y:o,w:s,d:r,h:i,m:e,s:n,ms:t}[a]||String(a||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},d={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("_")},$="en",l={};l[$]=d;var m=function(t){return t instanceof S},y=function(t,n,e){var i;if(!t)return null;if("string"==typeof t)l[t]&&(i=t),n&&(l[t]=n,i=t);else{var r=t.name;l[r]=t,i=r}return e||($=i),i},M=function(t,n,e){if(m(t))return t.clone();var i=n?"string"==typeof n?{format:n,pl:e}:n:{};return i.date=t,new S(i)},D=f;D.l=y,D.i=m,D.w=function(t,n){return M(t,{locale:n.$L,utc:n.$u})};var S=function(){function c(t){this.$L=this.$L||y(t.locale,null,!0)||$,this.parse(t)}var f=c.prototype;return f.parse=function(t){this.$d=function(t){var n=t.date,e=t.utc;if(null===n)return new Date(NaN);if(D.u(n))return new Date;if(n instanceof Date)return new Date(n);if("string"==typeof n&&!/Z$/i.test(n)){var i=n.match(a);if(i)return e?new Date(Date.UTC(i[1],i[2]-1,i[3]||1,i[4]||0,i[5]||0,i[6]||0,i[7]||0)):new Date(i[1],i[2]-1,i[3]||1,i[4]||0,i[5]||0,i[6]||0,i[7]||0)}return new Date(n)}(t),this.init()},f.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()},f.$utils=function(){return D},f.isValid=function(){return!("Invalid Date"===this.$d.toString())},f.isSame=function(t,n){var e=M(t);return this.startOf(n)<=e&&e<=this.endOf(n)},f.isAfter=function(t,n){return M(t)<this.startOf(n)},f.isBefore=function(t,n){return this.endOf(n)<M(t)},f.year=function(){return this.$y},f.month=function(){return this.$M},f.day=function(){return this.$W},f.date=function(){return this.$D},f.hour=function(){return this.$H},f.minute=function(){return this.$m},f.second=function(){return this.$s},f.millisecond=function(){return this.$ms},f.unix=function(){return Math.floor(this.valueOf()/1e3)},f.valueOf=function(){return this.$d.getTime()},f.startOf=function(t,a){var h=this,c=!!D.u(a)||a,f=D.p(t),d=function(t,n){var e=D.w(h.$u?Date.UTC(h.$y,n,t):new Date(h.$y,n,t),h);return c?e:e.endOf(r)},$=function(t,n){return D.w(h.toDate()[t].apply(h.toDate(),(c?[0,0,0,0]:[23,59,59,999]).slice(n)),h)},l=this.$W,m=this.$M,y=this.$D,M="set"+(this.$u?"UTC":"");switch(f){case o:return c?d(1,0):d(31,11);case u:return c?d(1,m):d(0,m+1);case s:var S=this.$locale().weekStart||0,g=(l<S?l+7:l)-S;return d(c?y-g:y+(6-g),m);case r:case"date":return $(M+"Hours",0);case i:return $(M+"Minutes",1);case e:return $(M+"Seconds",2);case n:return $(M+"Milliseconds",3);default:return this.clone()}},f.endOf=function(t){return this.startOf(t,!1)},f.$set=function(s,a){var h,c=D.p(s),f="set"+(this.$u?"UTC":""),d=(h={},h[r]=f+"Date",h.date=f+"Date",h[u]=f+"Month",h[o]=f+"FullYear",h[i]=f+"Hours",h[e]=f+"Minutes",h[n]=f+"Seconds",h[t]=f+"Milliseconds",h)[c],$=c===r?this.$D+(a-this.$W):a;return this.$d[d]&&this.$d[d]($),this.init(),this},f.set=function(t,n){return this.clone().$set(t,n)},f.add=function(t,a){var h,c=this;t=Number(t);var f=D.p(a),d=function(n,e){var i=c.set("date",1).set(n,e+t);return i.set("date",Math.min(c.$D,i.daysInMonth()))},$=function(n){var e=new Date(c.$d);return e.setDate(e.getDate()+n*t),D.w(e,c)};if(f===u)return d(u,this.$M);if(f===o)return d(o,this.$y);if(f===r)return $(1);if(f===s)return $(7);var l=(h={},h[e]=6e4,h[i]=36e5,h[n]=1e3,h)[f]||1,m=this.valueOf()+t*l;return D.w(m,this)},f.subtract=function(t,n){return this.add(-1*t,n)},f.format=function(t){var n=this;if(!this.isValid())return"Invalid Date";var e=t||"YYYY-MM-DDTHH:mm:ssZ",i=D.z(this),r=this.$locale(),s=r.weekdays,u=r.months,o=function(t,n,e,i){return t&&t[n]||e[n].substr(0,i)},a=function(t){return D.s(n.$H%12||12,t,"0")},c={YY:String(this.$y).slice(-2),YYYY:String(this.$y),M:String(this.$M+1),MM:D.s(this.$M+1,2,"0"),MMM:o(r.monthsShort,this.$M,u,3),MMMM:u[this.$M],D:String(this.$D),DD:D.s(this.$D,2,"0"),d:String(this.$W),dd:o(r.weekdaysMin,this.$W,s,2),ddd:o(r.weekdaysShort,this.$W,s,3),dddd:s[this.$W],H:String(this.$H),HH:D.s(this.$H,2,"0"),h:a(1),hh:a(2),a:this.$H<12?"am":"pm",A:this.$H<12?"AM":"PM",m:String(this.$m),mm:D.s(this.$m,2,"0"),s:String(this.$s),ss:D.s(this.$s,2,"0"),SSS:D.s(this.$ms,3,"0"),Z:i};return e.replace(h,function(t){return t.indexOf("[")>-1?t.replace(/\[|\]/g,""):c[t]||i.replace(":","")})},f.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},f.diff=function(t,a,h){var c,f=D.p(a),d=M(t),$=6e4*(d.utcOffset()-this.utcOffset()),l=this-d,m=D.m(this,d);return m=(c={},c[o]=m/12,c[u]=m,c.quarter=m/3,c[s]=(l-$)/6048e5,c[r]=(l-$)/864e5,c[i]=l/36e5,c[e]=l/6e4,c[n]=l/1e3,c)[f]||l,h?m:D.a(m)},f.daysInMonth=function(){return this.endOf(u).$D},f.$locale=function(){return l[this.$L]},f.locale=function(t,n){var e=this.clone();return e.$L=y(t,n,!0),e},f.clone=function(){return D.w(this.toDate(),this)},f.toDate=function(){return new Date(this.$d)},f.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]},f.toJSON=function(){return this.toISOString()},f.toISOString=function(){return this.$d.toISOString()},f.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}},f.toString=function(){return this.$d.toUTCString()},c}();return M.prototype=S.prototype,M.extend=function(t,n){return t(n,S,M),M},M.locale=y,M.isDayjs=m,M.unix=function(t){return M(1e3*t)},M.en=l[$],M.Ls=l,M}); |
@@ -54,3 +54,4 @@ import * as C from './constant'; | ||
return dayjs(date, { | ||
locale: instance.$L | ||
locale: instance.$L, | ||
utc: instance.$u | ||
}); | ||
@@ -61,12 +62,14 @@ }; | ||
Utils.parseLocale = parseLocale; | ||
Utils.isDayjs = isDayjs; | ||
Utils.wrapper = wrapper; | ||
Utils.l = parseLocale; | ||
Utils.i = isDayjs; | ||
Utils.w = wrapper; | ||
var parseDate = function parseDate(date) { | ||
var parseDate = function parseDate(cfg) { | ||
var date = cfg.date, | ||
utc = cfg.utc; | ||
if (date === null) return new Date(NaN); // null is invalid | ||
if (Utils.isUndefined(date)) return new Date(); // today | ||
if (Utils.u(date)) return new Date(); // today | ||
if (date instanceof Date) return date; | ||
if (date instanceof Date) return new Date(date); | ||
@@ -77,2 +80,6 @@ if (typeof date === 'string' && !/Z$/i.test(date)) { | ||
if (d) { | ||
if (utc) { | ||
return new Date(Date.UTC(d[1], d[2] - 1, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, d[7] || 0)); | ||
} | ||
return new Date(d[1], d[2] - 1, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, d[7] || 0); | ||
@@ -96,3 +103,3 @@ } | ||
_proto.parse = function parse(cfg) { | ||
this.$d = parseDate(cfg.date); | ||
this.$d = parseDate(cfg); | ||
this.init(); | ||
@@ -180,7 +187,7 @@ }; | ||
// startOf -> endOf | ||
var isStartOf = !Utils.isUndefined(_startOf) ? _startOf : true; | ||
var unit = Utils.prettyUnit(units); | ||
var isStartOf = !Utils.u(_startOf) ? _startOf : true; | ||
var unit = Utils.p(units); | ||
var instanceFactory = function instanceFactory(d, m) { | ||
var ins = wrapper(new Date(_this.$y, m, d), _this); | ||
var ins = Utils.w(_this.$u ? Date.UTC(_this.$y, m, d) : new Date(_this.$y, m, d), _this); | ||
return isStartOf ? ins : ins.endOf(C.D); | ||
@@ -192,3 +199,3 @@ }; | ||
var argumentEnd = [23, 59, 59, 999]; | ||
return wrapper(_this.toDate()[method].apply( // eslint-disable-line prefer-spread | ||
return Utils.w(_this.toDate()[method].apply( // eslint-disable-line prefer-spread | ||
_this.toDate(), (isStartOf ? argumentStart : argumentEnd).slice(slice)), _this); | ||
@@ -200,2 +207,3 @@ }; | ||
$D = this.$D; | ||
var utcPad = "set" + (this.$u ? 'UTC' : ''); | ||
@@ -218,12 +226,12 @@ switch (unit) { | ||
case C.DATE: | ||
return instanceFactorySet('setHours', 0); | ||
return instanceFactorySet(utcPad + "Hours", 0); | ||
case C.H: | ||
return instanceFactorySet('setMinutes', 1); | ||
return instanceFactorySet(utcPad + "Minutes", 1); | ||
case C.MIN: | ||
return instanceFactorySet('setSeconds', 2); | ||
return instanceFactorySet(utcPad + "Seconds", 2); | ||
case C.S: | ||
return instanceFactorySet('setMilliseconds', 3); | ||
return instanceFactorySet(utcPad + "Milliseconds", 3); | ||
@@ -243,4 +251,5 @@ default: | ||
// private set | ||
var unit = Utils.prettyUnit(units); | ||
var name = (_C$D$C$DATE$C$M$C$Y$C = {}, _C$D$C$DATE$C$M$C$Y$C[C.D] = 'setDate', _C$D$C$DATE$C$M$C$Y$C[C.DATE] = 'setDate', _C$D$C$DATE$C$M$C$Y$C[C.M] = 'setMonth', _C$D$C$DATE$C$M$C$Y$C[C.Y] = 'setFullYear', _C$D$C$DATE$C$M$C$Y$C[C.H] = 'setHours', _C$D$C$DATE$C$M$C$Y$C[C.MIN] = 'setMinutes', _C$D$C$DATE$C$M$C$Y$C[C.S] = 'setSeconds', _C$D$C$DATE$C$M$C$Y$C[C.MS] = 'setMilliseconds', _C$D$C$DATE$C$M$C$Y$C)[unit]; | ||
var unit = Utils.p(units); | ||
var utcPad = "set" + (this.$u ? 'UTC' : ''); | ||
var name = (_C$D$C$DATE$C$M$C$Y$C = {}, _C$D$C$DATE$C$M$C$Y$C[C.D] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[C.DATE] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[C.M] = utcPad + "Month", _C$D$C$DATE$C$M$C$Y$C[C.Y] = utcPad + "FullYear", _C$D$C$DATE$C$M$C$Y$C[C.H] = utcPad + "Hours", _C$D$C$DATE$C$M$C$Y$C[C.MIN] = utcPad + "Minutes", _C$D$C$DATE$C$M$C$Y$C[C.S] = utcPad + "Seconds", _C$D$C$DATE$C$M$C$Y$C[C.MS] = utcPad + "Milliseconds", _C$D$C$DATE$C$M$C$Y$C)[unit]; | ||
var arg = unit === C.D ? this.$D + (int - this.$W) : int; | ||
@@ -262,3 +271,3 @@ if (this.$d[name]) this.$d[name](arg); | ||
var unit = Utils.prettyUnit(units); | ||
var unit = Utils.p(units); | ||
@@ -274,3 +283,3 @@ var instanceFactory = function instanceFactory(u, n) { | ||
date.setDate(date.getDate() + n * number); | ||
return wrapper(date, _this2); | ||
return Utils.w(date, _this2); | ||
}; | ||
@@ -297,3 +306,3 @@ | ||
var nextTimeStamp = this.valueOf() + number * step; | ||
return wrapper(nextTimeStamp, this); | ||
return Utils.w(nextTimeStamp, this); | ||
}; | ||
@@ -310,3 +319,3 @@ | ||
var str = formatStr || C.FORMAT_DEFAULT; | ||
var zoneStr = Utils.padZoneStr(this.$d.getTimezoneOffset()); | ||
var zoneStr = Utils.z(this); | ||
var locale = this.$locale(); | ||
@@ -321,3 +330,3 @@ var weekdays = locale.weekdays, | ||
var get$H = function get$H(num) { | ||
return Utils.padStart(_this3.$H % 12 || 12, num, '0'); | ||
return Utils.s(_this3.$H % 12 || 12, num, '0'); | ||
}; | ||
@@ -329,7 +338,7 @@ | ||
M: String(this.$M + 1), | ||
MM: Utils.padStart(this.$M + 1, 2, '0'), | ||
MM: Utils.s(this.$M + 1, 2, '0'), | ||
MMM: getShort(locale.monthsShort, this.$M, months, 3), | ||
MMMM: months[this.$M], | ||
D: String(this.$D), | ||
DD: Utils.padStart(this.$D, 2, '0'), | ||
DD: Utils.s(this.$D, 2, '0'), | ||
d: String(this.$W), | ||
@@ -340,3 +349,3 @@ dd: getShort(locale.weekdaysMin, this.$W, weekdays, 2), | ||
H: String(this.$H), | ||
HH: Utils.padStart(this.$H, 2, '0'), | ||
HH: Utils.s(this.$H, 2, '0'), | ||
h: get$H(1), | ||
@@ -347,7 +356,8 @@ hh: get$H(2), | ||
m: String(this.$m), | ||
mm: Utils.padStart(this.$m, 2, '0'), | ||
mm: Utils.s(this.$m, 2, '0'), | ||
s: String(this.$s), | ||
ss: Utils.padStart(this.$s, 2, '0'), | ||
SSS: Utils.padStart(this.$ms, 3, '0'), | ||
Z: zoneStr | ||
ss: Utils.s(this.$s, 2, '0'), | ||
SSS: Utils.s(this.$ms, 3, '0'), | ||
Z: zoneStr // 'ZZ' logic below | ||
}; | ||
@@ -369,10 +379,10 @@ return str.replace(C.REGEX_FORMAT, function (match) { | ||
var unit = Utils.prettyUnit(units); | ||
var unit = Utils.p(units); | ||
var that = dayjs(input); | ||
var zoneDelta = (that.utcOffset() - this.utcOffset()) * C.MILLISECONDS_A_MINUTE; | ||
var diff = this - that; | ||
var result = Utils.monthDiff(this, that); | ||
var result = Utils.m(this, that); | ||
result = (_C$Y$C$M$C$Q$C$W$C$D$ = {}, _C$Y$C$M$C$Q$C$W$C$D$[C.Y] = result / 12, _C$Y$C$M$C$Q$C$W$C$D$[C.M] = result, _C$Y$C$M$C$Q$C$W$C$D$[C.Q] = result / 3, _C$Y$C$M$C$Q$C$W$C$D$[C.W] = (diff - zoneDelta) / C.MILLISECONDS_A_WEEK, _C$Y$C$M$C$Q$C$W$C$D$[C.D] = (diff - zoneDelta) / C.MILLISECONDS_A_DAY, _C$Y$C$M$C$Q$C$W$C$D$[C.H] = diff / C.MILLISECONDS_A_HOUR, _C$Y$C$M$C$Q$C$W$C$D$[C.MIN] = diff / C.MILLISECONDS_A_MINUTE, _C$Y$C$M$C$Q$C$W$C$D$[C.S] = diff / C.MILLISECONDS_A_SECOND, _C$Y$C$M$C$Q$C$W$C$D$)[unit] || diff; // milliseconds | ||
return float ? result : Utils.absFloor(result); | ||
return float ? result : Utils.a(result); | ||
}; | ||
@@ -396,3 +406,3 @@ | ||
_proto.clone = function clone() { | ||
return wrapper(this.toDate(), this); | ||
return Utils.w(this.toDate(), this); | ||
}; | ||
@@ -399,0 +409,0 @@ |
@@ -32,3 +32,3 @@ import { FORMAT_DEFAULT } from '../../constant'; | ||
case 'kk': | ||
return utils.padStart(String(_this.$H === 0 ? 24 : _this.$H), match === 'k' ? 1 : 2, '0'); | ||
return utils.s(String(_this.$H === 0 ? 24 : _this.$H), match === 'k' ? 1 : 2, '0'); | ||
@@ -35,0 +35,0 @@ case 'X': |
@@ -11,11 +11,9 @@ import { FORMAT_DEFAULT } from '../../constant'; | ||
var yearBias = 543; | ||
var _this$$utils = this.$utils(), | ||
padStart = _this$$utils.padStart; | ||
var str = formatStr || FORMAT_DEFAULT; | ||
var result = str.replace(/BBBB|BB/g, function (match) { | ||
var _this$$utils; | ||
var year = String(_this.$y + yearBias); | ||
var args = match === 'BB' ? [year.slice(-2), 2] : [year, 4]; | ||
return padStart.apply(void 0, args.concat(['0'])); | ||
return (_this$$utils = _this.$utils()).s.apply(_this$$utils, args.concat(['0'])); | ||
}); | ||
@@ -22,0 +20,0 @@ return oldFormat.bind(this)(result); |
@@ -169,3 +169,3 @@ var formattingTokens = /(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g; | ||
var parseFormattedInput = function parseFormattedInput(input, format) { | ||
var parseFormattedInput = function parseFormattedInput(input, format, utc) { | ||
try { | ||
@@ -189,3 +189,15 @@ var parser = makeParser(format); | ||
var now = new Date(); | ||
return new Date(year || now.getFullYear(), month > 0 ? month - 1 : now.getMonth(), day || now.getDate(), hours || 0, minutes || 0, seconds || 0, milliseconds || 0); | ||
var y = year || now.getFullYear(); | ||
var M = month > 0 ? month - 1 : now.getMonth(); | ||
var d = day || now.getDate(); | ||
var h = hours || 0; | ||
var m = minutes || 0; | ||
var s = seconds || 0; | ||
var ms = milliseconds || 0; | ||
if (utc) { | ||
return new Date(Date.UTC(y, M, d, h, m, s, ms)); | ||
} | ||
return new Date(y, M, d, h, m, s, ms); | ||
} catch (e) { | ||
@@ -201,9 +213,11 @@ return new Date(''); // Invalid Date | ||
proto.parse = function (cfg) { | ||
var input = cfg.date, | ||
var date = cfg.date, | ||
format = cfg.format, | ||
pl = cfg.pl; | ||
pl = cfg.pl, | ||
utc = cfg.utc; | ||
this.$u = utc; | ||
if (format) { | ||
locale = pl ? d.Ls[pl] : this.$locale(); | ||
this.$d = parseFormattedInput(input, format); | ||
this.$d = parseFormattedInput(date, format, utc); | ||
this.init(cfg); | ||
@@ -210,0 +224,0 @@ } else { |
@@ -9,3 +9,4 @@ import * as C from './constant'; | ||
var padZoneStr = function padZoneStr(negMinuts) { | ||
var padZoneStr = function padZoneStr(instance) { | ||
var negMinuts = -instance.utcOffset(); | ||
var minutes = Math.abs(negMinuts); | ||
@@ -20,5 +21,5 @@ var hourOffset = Math.floor(minutes / 60); | ||
var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()); | ||
var anchor = a.clone().add(wholeMonthDiff, 'months'); | ||
var anchor = a.clone().add(wholeMonthDiff, C.M); | ||
var c = b - anchor < 0; | ||
var anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), 'months'); | ||
var anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), C.M); | ||
return Number(-(wholeMonthDiff + (b - anchor) / (c ? anchor - anchor2 : anchor2 - anchor)) || 0); | ||
@@ -50,8 +51,8 @@ }; | ||
export default { | ||
padStart: padStart, | ||
padZoneStr: padZoneStr, | ||
monthDiff: monthDiff, | ||
absFloor: absFloor, | ||
prettyUnit: prettyUnit, | ||
isUndefined: isUndefined | ||
s: padStart, | ||
z: padZoneStr, | ||
m: monthDiff, | ||
a: absFloor, | ||
p: prettyUnit, | ||
u: isUndefined | ||
}; |
@@ -7,3 +7,3 @@ export = dayjs; | ||
export type OptionType = { locale?: string, format?: string } | string | ||
export type OptionType = { locale?: string, format?: string, utc?: boolean } | string | ||
@@ -81,2 +81,4 @@ type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms' | ||
utcOffset(): number | ||
isBefore(date: ConfigType, unit?: OpUnitType): boolean | ||
@@ -83,0 +85,0 @@ |
{ | ||
"name": "dayjs", | ||
"version": "1.8.8", | ||
"version": "1.8.9", | ||
"description": "2KB immutable date time library alternative to Moment.js with the same modern API ", | ||
@@ -5,0 +5,0 @@ "main": "dayjs.min.js", |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dayjs_plugin_advancedFormat=e()}(this,function(){"use strict";return function(t,e,n){var r=e.prototype,i=r.format;n.en.ordinal=function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"},r.format=function(t){var e=this,n=this.$locale(),r=this.$utils(),o=(t||"YYYY-MM-DDTHH:mm:ssZ").replace(/Q|Do|X|x|k{1,2}|S/g,function(t){switch(t){case"Q":return Math.ceil((e.$M+1)/3);case"Do":return n.ordinal(e.$D);case"k":case"kk":return r.padStart(String(0===e.$H?24:e.$H),"k"===t?1:2,"0");case"X":return Math.floor(e.$d.getTime()/1e3);default:return e.$d.getTime()}});return i.bind(this)(o)}}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dayjs_plugin_advancedFormat=t()}(this,function(){"use strict";return function(e,t,n){var r=t.prototype,i=r.format;n.en.ordinal=function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"},r.format=function(e){var t=this,n=this.$locale(),r=this.$utils(),o=(e||"YYYY-MM-DDTHH:mm:ssZ").replace(/Q|Do|X|x|k{1,2}|S/g,function(e){switch(e){case"Q":return Math.ceil((t.$M+1)/3);case"Do":return n.ordinal(t.$D);case"k":case"kk":return r.s(String(0===t.$H?24:t.$H),"k"===e?1:2,"0");case"X":return Math.floor(t.$d.getTime()/1e3);default:return t.$d.getTime()}});return i.bind(this)(o)}}}); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dayjs_plugin_buddhistEra=e()}(this,function(){"use strict";return function(t,e){var n=e.prototype,i=n.format;n.format=function(t){var e=this,n=this.$utils().padStart,o=(t||"YYYY-MM-DDTHH:mm:ssZ").replace(/BBBB|BB/g,function(t){var i=String(e.$y+543),o="BB"===t?[i.slice(-2),2]:[i,4];return n.apply(void 0,o.concat(["0"]))});return i.bind(this)(o)}}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dayjs_plugin_buddhistEra=e()}(this,function(){"use strict";return function(t,e){var n=e.prototype,i=n.format;n.format=function(t){var e=this,n=(t||"YYYY-MM-DDTHH:mm:ssZ").replace(/BBBB|BB/g,function(t){var n,i=String(e.$y+543),o="BB"===t?[i.slice(-2),2]:[i,4];return(n=e.$utils()).s.apply(n,o.concat(["0"]))});return i.bind(this)(n)}}}); |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.dayjs_plugin_customParseFormat=t()}(this,function(){"use strict";var n,t=/(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,e=/\d\d/,r=/\d\d?/,o=/\d*[^\s\d]+/;var s=function(n){return function(t){this[n]=+t}},i=[/[+-]\d\d:?\d\d/,function(n){var t,e;(this.zone||(this.zone={})).offset=(t=n.match(/([+-]|\d\d)/g),0===(e=60*t[1]+ +t[2])?0:"+"===t[0]?-e:e)}],a={A:[/[AP]M/,function(n){this.afternoon="PM"===n}],a:[/[ap]m/,function(n){this.afternoon="pm"===n}],S:[/\d/,function(n){this.milliseconds=100*+n}],SS:[e,function(n){this.milliseconds=10*+n}],SSS:[/\d{3}/,function(n){this.milliseconds=+n}],s:[r,s("seconds")],ss:[e,s("seconds")],m:[r,s("minutes")],mm:[e,s("minutes")],H:[r,s("hours")],h:[r,s("hours")],HH:[e,s("hours")],hh:[e,s("hours")],D:[r,s("day")],DD:[e,s("day")],M:[r,s("month")],MM:[e,s("month")],MMM:[o,function(t){var e=n,r=e.months,o=e.monthsShort,s=o?o.findIndex(function(n){return n===t}):r.findIndex(function(n){return n.substr(0,3)===t});if(s<0)throw new Error;this.month=s+1}],MMMM:[o,function(t){var e=n.months.indexOf(t);if(e<0)throw new Error;this.month=e+1}],Y:[/[+-]?\d+/,s("year")],YY:[e,function(n){n=+n,this.year=n+(n>68?1900:2e3)}],YYYY:[/\d{4}/,s("year")],Z:i,ZZ:i};var u=function(n,e){try{var r=function(n){for(var e=n.match(t),r=e.length,o=0;o<r;o+=1){var s=e[o],i=a[s],u=i&&i[0],f=i&&i[1];e[o]=f?{regex:u,parser:f}:s.replace(/^\[|\]$/g,"")}return function(n){for(var t={},o=0,s=0;o<r;o+=1){var i=e[o];if("string"==typeof i)s+=i.length;else{var a=i.regex,u=i.parser,f=n.substr(s),h=a.exec(f)[0];u.call(t,h),s+=h.length}}return function(n){var t=n.afternoon;if(void 0!==t){var e=n.hours;t?e<12&&(n.hours+=12):12===e&&(n.hours=0),delete n.afternoon}}(t),t}}(e)(n),o=r.year,s=r.month,i=r.day,u=r.hours,f=r.minutes,h=r.seconds,d=r.milliseconds,c=r.zone;if(c)return new Date(Date.UTC(o,s-1,i,u||0,f||0,h||0,d||0)+60*c.offset*1e3);var m=new Date;return new Date(o||m.getFullYear(),s>0?s-1:m.getMonth(),i||m.getDate(),u||0,f||0,h||0,d||0)}catch(n){return new Date("")}};return function(t,e,r){var o=e.prototype,s=o.parse;o.parse=function(t){var e=t.date,o=t.format,i=t.pl;o?(n=i?r.Ls[i]:this.$locale(),this.$d=u(e,o),this.init(t)):s.call(this,t)}}}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.dayjs_plugin_customParseFormat=n()}(this,function(){"use strict";var t,n=/(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,e=/\d\d/,r=/\d\d?/,o=/\d*[^\s\d]+/;var s=function(t){return function(n){this[t]=+n}},i=[/[+-]\d\d:?\d\d/,function(t){var n,e;(this.zone||(this.zone={})).offset=(n=t.match(/([+-]|\d\d)/g),0===(e=60*n[1]+ +n[2])?0:"+"===n[0]?-e:e)}],a={A:[/[AP]M/,function(t){this.afternoon="PM"===t}],a:[/[ap]m/,function(t){this.afternoon="pm"===t}],S:[/\d/,function(t){this.milliseconds=100*+t}],SS:[e,function(t){this.milliseconds=10*+t}],SSS:[/\d{3}/,function(t){this.milliseconds=+t}],s:[r,s("seconds")],ss:[e,s("seconds")],m:[r,s("minutes")],mm:[e,s("minutes")],H:[r,s("hours")],h:[r,s("hours")],HH:[e,s("hours")],hh:[e,s("hours")],D:[r,s("day")],DD:[e,s("day")],M:[r,s("month")],MM:[e,s("month")],MMM:[o,function(n){var e=t,r=e.months,o=e.monthsShort,s=o?o.findIndex(function(t){return t===n}):r.findIndex(function(t){return t.substr(0,3)===n});if(s<0)throw new Error;this.month=s+1}],MMMM:[o,function(n){var e=t.months.indexOf(n);if(e<0)throw new Error;this.month=e+1}],Y:[/[+-]?\d+/,s("year")],YY:[e,function(t){t=+t,this.year=t+(t>68?1900:2e3)}],YYYY:[/\d{4}/,s("year")],Z:i,ZZ:i};var u=function(t,e,r){try{var o=function(t){for(var e=t.match(n),r=e.length,o=0;o<r;o+=1){var s=e[o],i=a[s],u=i&&i[0],f=i&&i[1];e[o]=f?{regex:u,parser:f}:s.replace(/^\[|\]$/g,"")}return function(t){for(var n={},o=0,s=0;o<r;o+=1){var i=e[o];if("string"==typeof i)s+=i.length;else{var a=i.regex,u=i.parser,f=t.substr(s),h=a.exec(f)[0];u.call(n,h),s+=h.length}}return function(t){var n=t.afternoon;if(void 0!==n){var e=t.hours;n?e<12&&(t.hours+=12):12===e&&(t.hours=0),delete t.afternoon}}(n),n}}(e)(t),s=o.year,i=o.month,u=o.day,f=o.hours,h=o.minutes,d=o.seconds,c=o.milliseconds,m=o.zone;if(m)return new Date(Date.UTC(s,i-1,u,f||0,h||0,d||0,c||0)+60*m.offset*1e3);var l=new Date,v=s||l.getFullYear(),p=i>0?i-1:l.getMonth(),M=u||l.getDate(),y=f||0,Y=h||0,g=d||0,D=c||0;return r?new Date(Date.UTC(v,p,M,y,Y,g,D)):new Date(v,p,M,y,Y,g,D)}catch(t){return new Date("")}};return function(n,e,r){var o=e.prototype,s=o.parse;o.parse=function(n){var e=n.date,o=n.format,i=n.pl,a=n.utc;this.$u=a,o?(t=i?r.Ls[i]:this.$locale(),this.$d=u(e,o,a),this.init(n)):s.call(this,n)}}}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157414
142
2820
47