Socket
Socket
Sign inDemoInstall

dayjs

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dayjs - npm Package Compare versions

Comparing version 1.5.23 to 1.5.24

2

dist/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=e()}(this,function(){"use strict";var t="second",e="minute",n="hour",s="day",r="week",i="month",a="year",u="Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday".split("."),c="January.February.March.April.May.June.July.August.September.October.November.December".split("."),h=/^(\d{4})-?(\d{1,2})-?(\d{1,2})(.*?(\d{1,2}):(\d{1,2}):(\d{1,2}))?.?(\d{1,3})?$/,o=/\[.*?\]|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,d=function(t,e,n){var s=String(t);return!s||s.length>=e?t:""+Array(e+1-s.length).join(n)+t},$=function(t){return t&&String(t).toLowerCase().replace(/s$/,"")},f=function(t){return void 0===t},l=function(t){var e;return null===t?new Date(NaN):f(t)?new Date:t instanceof Date?t:"string"==typeof t&&(e=t.match(h))?new Date(e[1],e[2]-1,e[3],e[5]||0,e[6]||0,e[7]||0,e[8]||0):new Date(t)},m=function(){function h(t){this.$d=l(t),this.init()}var m=h.prototype;return m.init=function(){this.$y=this.$d.getFullYear(),this.$M=this.$d.getMonth(),this.$D=this.$d.getDate(),this.$W=this.$d.getDay(),this.$H=this.$d.getHours(),this.$m=this.$d.getMinutes(),this.$s=this.$d.getSeconds(),this.$ms=this.$d.getMilliseconds()},m.isValid=function(){return!("Invalid Date"===this.$d.toString())},m.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0},m.isSame=function(t){return this.valueOf()===t.valueOf()},m.isBefore=function(t){return this.valueOf()<t.valueOf()},m.isAfter=function(t){return this.valueOf()>t.valueOf()},m.year=function(){return this.$y},m.month=function(){return this.$M},m.day=function(){return this.$W},m.date=function(){return this.$D},m.hour=function(){return this.$H},m.minute=function(){return this.$m},m.second=function(){return this.$s},m.millisecond=function(){return this.$ms},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(u,c){var o=this,d=!!f(c)||c,l=function(t,e,n){void 0===n&&(n=o.$y);var r=new h(new Date(n,e,t));return d?r:r.endOf(s)},m=function(t,e){return new h(o.toDate()[t].apply(o.toDate(),d?[0,0,0,0].slice(e):[23,59,59,999].slice(e)))};switch($(u)){case a:return d?l(1,0):l(31,11,this.$y);case i:return d?l(1,this.$M):l(0,this.$M+1,this.$y);case r:return d?l(this.$D-this.$W,this.$M):l(this.$D+(6-this.$W),this.$M,this.$y);case s:case"date":return m("setHours",0);case n:return m("setMinutes",1);case e:return m("setSeconds",2);case t:return m("setMilliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(s,r){switch($(s)){case"date":this.$d.setDate(r);break;case i:this.$d.setMonth(r);break;case a:this.$d.setFullYear(r);break;case n:this.$d.setHours(r);break;case e:this.$d.setMinutes(r);break;case t:this.$d.setSeconds(r);break;case"millisecond":this.$d.setMilliseconds(r)}return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.add=function(t,u){t=Number(t);var c,o=u&&1===u.length?u:$(u);if(["M",i].indexOf(o)>-1){var d=this.set("date",1).set(i,this.$M+t);return d=d.set("date",Math.min(this.$D,d.daysInMonth()))}if(["y",a].indexOf(o)>-1)return this.set(a,this.$y+t);switch(o){case"m":case e:c=6e4;break;case"h":case n:c=36e5;break;case"d":case s:c=864e5;break;case"w":case r:c=6048e5;break;default:c=1e3}return new h(this.valueOf()+t*c)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e,n,s,r,i=this,a=t||"YYYY-MM-DDTHH:mm:ssZ",h=(e=this.$d.getTimezoneOffset(),n=Math.abs(e),s=Math.floor(n/60),r=n%60,(e<=0?"+":"-")+d(s,2,"0")+":"+d(r,2,"0"));return a.replace(o,function(t){if(t.indexOf("[")>-1)return t.replace(/\[|\]/g,"");switch(t){case"YY":return String(i.$y).slice(-2);case"YYYY":return String(i.$y);case"M":return String(i.$M+1);case"MM":return d(i.$M+1,2,"0");case"MMM":return c[i.$M].slice(0,3);case"MMMM":return c[i.$M];case"D":return String(i.$D);case"DD":return d(i.$D,2,"0");case"d":return String(i.$W);case"dddd":return u[i.$W];case"H":return String(i.$H);case"HH":return d(i.$H,2,"0");case"h":case"hh":return 0===i.$H?12:d(i.$H<13?i.$H:i.$H-12,"hh"===t?2:1,"0");case"a":return i.$H<12?"am":"pm";case"A":return i.$H<12?"AM":"PM";case"m":return String(i.$m);case"mm":return d(i.$m,2,"0");case"s":return String(i.$s);case"ss":return d(i.$s,2,"0");case"SSS":return d(i.$ms,3,"0");case"Z":return h;default:return h.replace(":","")}})},m.diff=function(u,c,o){var d,f,l,m,M,y,g=$(c),S=u instanceof h?u:new h(u),D=this-S,b=(d=this,m=12*((f=S).year()-d.year())+(f.month()-d.month()),M=d.clone().add(m,"months"),l=f-M<0?(f-M)/(M-d.clone().add(m-1,"months")):(f-M)/(d.clone().add(m+1,"months")-M),Number(-(m+l)));switch(g){case a:b/=12;break;case i:break;case"quarter":b/=3;break;case r:b=D/6048e5;break;case s:b=D/864e5;break;case n:b=D/36e5;break;case e:b=D/6e4;break;case t:b=D/1e3;break;default:b=D}return o?b:(y=b)<0?Math.ceil(y)||0:Math.floor(y)},m.daysInMonth=function(){return this.endOf(i).$D},m.clone=function(){return new h(this)},m.toDate=function(){return new Date(this.$d)},m.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]},m.toJSON=function(){return this.toISOString()},m.toISOString=function(){return this.toDate().toISOString()},m.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}},m.toString=function(){return this.$d.toUTCString()},h}();return function(t){return new m(t)}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dayjs=e()}(this,function(){"use strict";var t="second",e="minute",n="hour",s="day",r="week",i="month",a="year",u="Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday".split("."),c="January.February.March.April.May.June.July.August.September.October.November.December".split("."),h=/^(\d{4})-?(\d{1,2})-?(\d{1,2})(.*?(\d{1,2}):(\d{1,2}):(\d{1,2}))?.?(\d{1,3})?$/,o=/\[.*?\]|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,d=function(t,e,n){var s=String(t);return!s||s.length>=e?t:""+Array(e+1-s.length).join(n)+t},$=function(t){return t&&String(t).toLowerCase().replace(/s$/,"")},f=function(t){return void 0===t},l=function(t){var e;return null===t?new Date(NaN):f(t)?new Date:t instanceof Date?t:"string"==typeof t&&(e=t.match(h))?new Date(e[1],e[2]-1,e[3],e[5]||0,e[6]||0,e[7]||0,e[8]||0):new Date(t)},m=function(){function h(t){this.$d=l(t),this.init()}var m=h.prototype;return m.init=function(){this.$y=this.$d.getFullYear(),this.$M=this.$d.getMonth(),this.$D=this.$d.getDate(),this.$W=this.$d.getDay(),this.$H=this.$d.getHours(),this.$m=this.$d.getMinutes(),this.$s=this.$d.getSeconds(),this.$ms=this.$d.getMilliseconds()},m.isValid=function(){return!("Invalid Date"===this.$d.toString())},m.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0},m.isSame=function(t){return this.valueOf()===t.valueOf()},m.isBefore=function(t){return this.valueOf()<t.valueOf()},m.isAfter=function(t){return this.valueOf()>t.valueOf()},m.year=function(){return this.$y},m.month=function(){return this.$M},m.day=function(){return this.$W},m.date=function(){return this.$D},m.hour=function(){return this.$H},m.minute=function(){return this.$m},m.second=function(){return this.$s},m.millisecond=function(){return this.$ms},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(u,c){var o=this,d=!!f(c)||c,l=function(t,e,n){void 0===n&&(n=o.$y);var r=new h(new Date(n,e,t));return d?r:r.endOf(s)},m=function(t,e){return new h(o.toDate()[t].apply(o.toDate(),d?[0,0,0,0].slice(e):[23,59,59,999].slice(e)))};switch($(u)){case a:return d?l(1,0):l(31,11,this.$y);case i:return d?l(1,this.$M):l(0,this.$M+1,this.$y);case r:return d?l(this.$D-this.$W,this.$M):l(this.$D+(6-this.$W),this.$M,this.$y);case s:case"date":return m("setHours",0);case n:return m("setMinutes",1);case e:return m("setSeconds",2);case t:return m("setMilliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(s,r){switch($(s)){case"date":this.$d.setDate(r);break;case i:this.$d.setMonth(r);break;case a:this.$d.setFullYear(r);break;case n:this.$d.setHours(r);break;case e:this.$d.setMinutes(r);break;case t:this.$d.setSeconds(r);break;case"millisecond":this.$d.setMilliseconds(r)}return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.add=function(u,c){u=Number(u);var o,d=!c||1!==c.length&&"ms"!==c?$(c):c;if(["M",i].indexOf(d)>-1){var f=this.set("date",1).set(i,this.$M+u);return f=f.set("date",Math.min(this.$D,f.daysInMonth()))}if(["y",a].indexOf(d)>-1)return this.set(a,this.$y+u);switch(d){case"m":case e:o=6e4;break;case"h":case n:o=36e5;break;case"d":case s:o=864e5;break;case"w":case r:o=6048e5;break;case"s":case t:o=1e3;break;default:o=1}return new h(this.valueOf()+u*o)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e,n,s,r,i=this,a=t||"YYYY-MM-DDTHH:mm:ssZ",h=(e=this.$d.getTimezoneOffset(),n=Math.abs(e),s=Math.floor(n/60),r=n%60,(e<=0?"+":"-")+d(s,2,"0")+":"+d(r,2,"0"));return a.replace(o,function(t){if(t.indexOf("[")>-1)return t.replace(/\[|\]/g,"");switch(t){case"YY":return String(i.$y).slice(-2);case"YYYY":return String(i.$y);case"M":return String(i.$M+1);case"MM":return d(i.$M+1,2,"0");case"MMM":return c[i.$M].slice(0,3);case"MMMM":return c[i.$M];case"D":return String(i.$D);case"DD":return d(i.$D,2,"0");case"d":return String(i.$W);case"dddd":return u[i.$W];case"H":return String(i.$H);case"HH":return d(i.$H,2,"0");case"h":case"hh":return 0===i.$H?12:d(i.$H<13?i.$H:i.$H-12,"hh"===t?2:1,"0");case"a":return i.$H<12?"am":"pm";case"A":return i.$H<12?"AM":"PM";case"m":return String(i.$m);case"mm":return d(i.$m,2,"0");case"s":return String(i.$s);case"ss":return d(i.$s,2,"0");case"SSS":return d(i.$ms,3,"0");case"Z":return h;default:return h.replace(":","")}})},m.diff=function(u,c,o){var d,f,l,m,M,y,g=$(c),S=u instanceof h?u:new h(u),D=this-S,b=(d=this,m=12*((f=S).year()-d.year())+(f.month()-d.month()),M=d.clone().add(m,"months"),l=f-M<0?(f-M)/(M-d.clone().add(m-1,"months")):(f-M)/(d.clone().add(m+1,"months")-M),Number(-(m+l)));switch(g){case a:b/=12;break;case i:break;case"quarter":b/=3;break;case r:b=D/6048e5;break;case s:b=D/864e5;break;case n:b=D/36e5;break;case e:b=D/6e4;break;case t:b=D/1e3;break;default:b=D}return o?b:(y=b)<0?Math.ceil(y)||0:Math.floor(y)},m.daysInMonth=function(){return this.endOf(i).$D},m.clone=function(){return new h(this)},m.toDate=function(){return new Date(this.$d)},m.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]},m.toJSON=function(){return this.toISOString()},m.toISOString=function(){return this.toDate().toISOString()},m.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}},m.toString=function(){return this.$d.toUTCString()},h}();return function(t){return new m(t)}});
{
"name": "dayjs",
"version": "1.5.23",
"description": "",
"version": "1.5.24",
"description": "2KB immutable date library alternative to Moment.js with the same modern API ",
"main": "dist/dayjs.min.js",

@@ -26,2 +26,9 @@ "types": "index.d.ts",

},
"keywords": [
"dayjs",
"date",
"time",
"immutable",
"moment"
],
"author": "iamkun",

@@ -28,0 +35,0 @@ "license": "MIT",

@@ -178,3 +178,4 @@ import * as C from './constant'

number = Number(number) // eslint-disable-line no-param-reassign
const unit = (units && units.length === 1) ? units : Utils.prettyUnit(units)
// units === 'ms' hard code here, will update in next release
const unit = (units && (units.length === 1 || units === 'ms')) ? units : Utils.prettyUnit(units)
if (['M', C.M].indexOf(unit) > -1) {

@@ -206,4 +207,8 @@ let date = this.set(C.DATE, 1).set(C.M, this.$M + number)

break
default: // s seconds
case 's':
case C.S:
step = C.MILLISECONDS_A_SECOND
break
default: // ms
step = 1
}

@@ -210,0 +215,0 @@ const nextTimeStamp = this.valueOf() + (number * step)

@@ -31,2 +31,4 @@ import moment from 'moment'

it('Add Time days', () => {
expect(dayjs().add(1, 'ms').valueOf()).toBe(moment().add(1, 'ms').valueOf())
expect(dayjs().add(1, 'milliseconds').valueOf()).toBe(moment().add(1, 'milliseconds').valueOf())
expect(dayjs().add(1, 's').valueOf()).toBe(moment().add(1, 's').valueOf())

@@ -33,0 +35,0 @@ expect(dayjs().add(1, 'seconds').valueOf()).toBe(moment().add(1, 'seconds').valueOf())

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc