Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.20 to 1.5.21

index.d.ts

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{2})-?(\d{1,2})(.*(\d{2}):(\d{2}):(\d{2}))?.?(\d{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,$=function(t,e,n){var s=String(t);return!s||s.length>=e?t:""+Array(e+1-s.length).join(n)+t},d=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:(e=String(t).match(h))?new Date(e[1],e[2]-1,e[3],e[5],e[6],e[7],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(){var t,e,n,s,r;this.$zone=this.$d.getTimezoneOffset(),this.$zoneStr=(t=this.$zone,e=Math.abs(t),n=t<=0?"+":"-",s=Math.floor(e/60),r=e%60,""+n+$(s,2,"0")+":"+$(r,2,"0")),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,$=!!f(c)||c,l=function(t,e,n){void 0===n&&(n=o.$y);var r=new h(new Date(n,e,t));return $?r:r.endOf(s)},m=function(t,e){return new h(o.toDate()[t].apply(o.toDate(),$?[0,0,0,0].slice(e):[23,59,59,999].slice(e)))};switch(d(u)){case a:return $?l(1,0):l(31,11,this.$y);case i:return $?l(1,this.$M):l(0,this.$M+1,this.$y);case r:return $?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.mSet=function(s,r){switch(d(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().mSet(t,e)},m.add=function(t,u){var c,o=u&&1===u.length?u:d(u);if(["M",i].indexOf(o)>-1){var $=this.set("date",1).set(i,this.$M+t);return $=$.set("date",Math.min(this.$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=this;return(t||"YYYY-MM-DDTHH:mm:ssZ").replace(o,function(t){if(t.indexOf("[")>-1)return t.replace(/\[|\]/g,"");switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return String(e.$y);case"M":return String(e.$M+1);case"MM":return $(e.$M+1,2,"0");case"MMM":return c[e.$M].slice(0,3);case"MMMM":return c[e.$M];case"D":return String(e.$D);case"DD":return $(e.$D,2,"0");case"d":return String(e.$W);case"dddd":return u[e.$W];case"H":return String(e.$H);case"HH":return $(e.$H,2,"0");case"h":case"hh":return 0===e.$H?12:$(e.$H<13?e.$H:e.$H-12,"hh"===t?2:1,"0");case"a":return e.$H<12?"am":"pm";case"A":return e.$H<12?"AM":"PM";case"m":return String(e.$m);case"mm":return $(e.$m,2,"0");case"s":return String(e.$s);case"ss":return $(e.$s,2,"0");case"SSS":return $(e.$ms,3,"0");case"Z":return e.$zoneStr;default:return e.$zoneStr.replace(":","")}})},m.diff=function(e,n,u){var c,o,$,f,l,m,M=d(n),y=e instanceof h?e:new h(e),S=this-y,g=(c=this,f=12*((o=y).year()-c.year())+(o.month()-c.month()),l=c.clone().add(f,"months"),$=o-l<0?(o-l)/(l-c.clone().add(f-1,"months")):(o-l)/(c.clone().add(f+1,"months")-l),Number(-(f+$)));switch(M){case a:g/=12;break;case i:break;case"quarter":g/=3;break;case r:g=S/6048e5;break;case s:g=S/864e5;break;case t:g=S/1e3;break;default:g=S}return u?g:(m=g)<0?Math.ceil(m)||0:Math.floor(m)},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{2})-?(\d{1,2})(.*(\d{2}):(\d{2}):(\d{2}))?.?(\d{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:(e=String(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,S=$(c),g=u instanceof h?u:new h(u),D=this-g,b=(d=this,m=12*((f=g).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(S){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)}});

@@ -62,6 +62,2 @@ module.exports = function (config) {

},
sl_ios_safari: {
base: 'SauceLabs',
browserName: 'iphone'
},
sl_android_4_4: {

@@ -71,2 +67,8 @@ base: 'SauceLabs',

version: '4.4'
}
},
{
sl_ios_safari: {
base: 'SauceLabs',
browserName: 'iphone'
},

@@ -95,3 +97,3 @@ sl_android: {

},
captureTimeout: 120000,
captureTimeout: 200000, // try fix ios timeout
customLaunchers: batch,

@@ -98,0 +100,0 @@ browsers: Object.keys(batch),

{
"name": "dayjs",
"version": "1.5.20",
"version": "1.5.21",
"description": "",
"main": "dist/dayjs.min.js",
"types": "index.d.ts",
"scripts": {

@@ -11,3 +12,3 @@ "test": "jest",

"sauce": "npx karma start karma.sauce.conf.js",
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2",
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2 && npm run sauce -- 3",
"gzip-size": "gzip-size ./dist/*.min.js"

@@ -14,0 +15,0 @@ },

@@ -12,3 +12,6 @@ import * as C from './constant'

// 2018-08-08 or 20180808
return new Date(reg[1], reg[2] - 1, reg[3], reg[5], reg[6], reg[7], reg[8] || 0)
return new Date(
reg[1], reg[2] - 1, reg[3],
reg[5] || 0, reg[6] || 0, reg[7] || 0, reg[8] || 0
)
}

@@ -25,4 +28,2 @@ return new Date(config) // timestamp

init() {
this.$zone = this.$d.getTimezoneOffset()
this.$zoneStr = Utils.padZoneStr(this.$zone)
this.$y = this.$d.getFullYear()

@@ -142,3 +143,3 @@ this.$M = this.$d.getMonth()

mSet(units, int) {
$set(units, int) { // private set
const unit = Utils.prettyUnit(units)

@@ -175,6 +176,7 @@ switch (unit) {

set(string, int) {
return this.clone().mSet(string, int)
return this.clone().$set(string, int)
}
add(number, units) {
number = Number(number) // eslint-disable-line no-param-reassign
const unit = (units && units.length === 1) ? units : Utils.prettyUnit(units)

@@ -220,2 +222,3 @@ if (['M', C.M].indexOf(unit) > -1) {

const str = formatStr || C.FORMAT_DEFAULT
const zoneStr = Utils.padZoneStr(this.$d.getTimezoneOffset())
return str.replace(C.REGEX_FORMAT, (match) => {

@@ -267,5 +270,5 @@ if (match.indexOf('[') > -1) return match.replace(/\[|\]/g, '')

case 'Z':
return this.$zoneStr
return zoneStr
default: // 'ZZ'
return this.$zoneStr.replace(':', '')
return zoneStr.replace(':', '')
}

@@ -295,2 +298,8 @@ })

break
case C.H:
result = diff / C.MILLISECONDS_A_HOUR
break
case C.MIN:
result = diff / C.MILLISECONDS_A_MINUTE
break
case C.S:

@@ -297,0 +306,0 @@ result = diff / C.MILLISECONDS_A_SECOND

@@ -9,7 +9,5 @@ export const padStart = (string, length, pad) => {

const minutes = Math.abs(negMinuts)
const sign = negMinuts <= 0 ? '+' : '-'
const hourOffset = Math.floor(minutes / 60)
const minuteOffset = minutes % 60
return `${sign}${padStart(hourOffset, 2, '0')}:${padStart(minuteOffset, 2, '0')}`
return `${negMinuts <= 0 ? '+' : '-'}${padStart(hourOffset, 2, '0')}:${padStart(minuteOffset, 2, '0')}`
}

@@ -16,0 +14,0 @@

@@ -22,2 +22,9 @@ /* eslint-disable prefer-arrow-callback,func-names */

})
it('Date parse - nonstandard date string with only one digit', function () {
expect(dayjs('2018-4-1 1:1:1:22').isValid())
.toBe(true)
expect(dayjs('2018-4-1').isValid())
.toBe(true)
})
})

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

expect(dayjs().format('ZZ')).toBe(moment().format('ZZ'))
MockDate.set(new Date('2018-05-02T23:00:00.000'), 60 * 5.5 * -1)
expect(dayjs().format('ZZ')).toBe(moment().format('ZZ'))
})

@@ -125,3 +127,3 @@

it('diff -> in seconds, days, weeks, months, quarters, years ', () => {
it('diff -> in seconds, minutes, hours, days, weeks, months, quarters, years ', () => {
const dayjsA = dayjs()

@@ -133,3 +135,3 @@ const dayjsB = dayjs().add(1000, 'days')

const momentC = moment().subtract(1000, 'days')
const units = ['seconds', 'days', 'weeks', 'months', 'quarters', 'years']
const units = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'quarters', 'years']
units.forEach((unit) => {

@@ -136,0 +138,0 @@ expect(dayjsA.diff(dayjsB, unit)).toBe(momentA.diff(momentB, unit))

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

expect(dayjs('20111031').add(1, 'months').valueOf()).toBe(moment('20111031').add(1, 'months').valueOf())
expect(dayjs().add('2', 'years').valueOf()).toBe(moment().add('2', 'years').valueOf())
})

@@ -46,0 +48,0 @@

@@ -19,3 +19,11 @@ import moment from 'moment'

it('String 20130208', () => {
const timeArr = ['20130108', '2018-04-24', '2018-05-02 11:12:13', '2018-05-02 11:12:13.998']
global.console.warn = jest.genMockFunction()// moment.js '2018-4-1 1:1:1:22' will throw warn
const timeArr = [
'20130108',
'2018-04-24',
'2018-05-02 11:12:13',
'2018-05-02 11:12:13.998',
'2018-4-1', // not recommend
'2018-4-1 1:1:1:22' // not recommend
]
timeArr.forEach((t) => {

@@ -22,0 +30,0 @@ expect(dayjs(t).valueOf()).toBe(moment(t).valueOf())

Sorry, the diff of this file is not supported yet

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