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.18 to 1.5.19

test/utils.test.js

2

dist/dayjs.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dayjs=t()}(this,function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var t="second",n="minute",r="hour",s="day",i="week",a="month",u="year",c="Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday".split("."),o="January.February.March.April.May.June.July.August.September.October.November.December".split("."),h=/^(\d{4})-?(\d{2})-?(\d{1,2})$/,l=/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}/g,$=function(e,t,n){var r=String(e);return!r||r.length>=t?e:"".concat(Array(t+1-r.length).join(n)).concat(e)},d=function(e){return e&&String(e).toLowerCase().replace(/s$/,"")},f=function(e){var t;return null===e?new Date(NaN):e?e instanceof Date?e:(t=String(e).match(h))?new Date(t[1],t[2]-1,t[3]):new Date(e):new Date},y=function(){function h(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,h),this.$d=f(e),this.init()}var y,v,m;return y=h,(v=[{key:"init",value:function(){var e,t,n;this.$zone=this.$d.getTimezoneOffset()/60,this.$zoneStr=$((e=this.$zone,n="",n=(t=-1*e)>-10&&t<10?"$10$200":"$1$200",String(t).replace(/^(.)?(\d)/,n)),5,"+"),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()}},{key:"isValid",value:function(){return!("Invalid Date"===this.$d.toString())}},{key:"isLeapYear",value:function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}},{key:"isSame",value:function(e){return this.valueOf()===e.valueOf()}},{key:"isBefore",value:function(e){return this.valueOf()<e.valueOf()}},{key:"isAfter",value:function(e){return this.valueOf()>e.valueOf()}},{key:"year",value:function(){return this.$y}},{key:"month",value:function(){return this.$M}},{key:"day",value:function(){return this.$W}},{key:"date",value:function(){return this.$D}},{key:"hour",value:function(){return this.$H}},{key:"minute",value:function(){return this.$m}},{key:"second",value:function(){return this.$s}},{key:"millisecond",value:function(){return this.$ms}},{key:"unix",value:function(){return Math.floor(this.valueOf()/1e3)}},{key:"valueOf",value:function(){return this.$d.getTime()}},{key:"startOf",value:function(e,c){var o=this,l=void 0===c||c,$=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o.$y,r=new h(new Date(n,t,e));return l?r:r.endOf(s)},f=function(e,t){return new h(o.toDate()[e].apply(o.toDate(),l?[0,0,0,0].slice(t):[23,59,59,999].slice(t)))};switch(d(e)){case u:return l?$(1,0):$(31,11,this.$y);case a:return l?$(1,this.$M):$(0,this.$M+1,this.$y);case i:return l?$(this.$D-this.$W,this.$M):$(this.$D+(6-this.$W),this.$M,this.$y);case s:case"date":return f("setHours",0);case r:return f("setMinutes",1);case n:return f("setSeconds",2);case t:return f("setMilliseconds",3);default:return this.clone()}}},{key:"endOf",value:function(e){return this.startOf(e,!1)}},{key:"mSet",value:function(e,s){switch(d(e)){case"date":this.$d.setDate(s);break;case a:this.$d.setMonth(s);break;case u:this.$d.setFullYear(s);break;case r:this.$d.setHours(s);break;case n:this.$d.setMinutes(s);break;case t:this.$d.setSeconds(s);break;case"millisecond":this.$d.setMilliseconds(s)}return this.init(),this}},{key:"set",value:function(e,t){return n=t,Number.isNaN(parseFloat(n))||!Number.isFinite(n)?this:this.clone().mSet(e,t);var n}},{key:"add",value:function(e,t){var c,o=t&&1===t.length?t:d(t);if(["M",a].indexOf(o)>-1){var l=this.set("date",1).set(a,this.$M+e);return l=l.set("date",Math.min(this.$D,l.daysInMonth()))}if(["y",u].indexOf(o)>-1)return this.set(u,this.$y+e);switch(o){case"m":case n:c=6e4;break;case"h":case r:c=36e5;break;case"d":case s:c=864e5;break;case"w":case i:c=6048e5;break;default:c=1e3}return new h(this.valueOf()+e*c)}},{key:"subtract",value:function(e,t){return this.add(-1*e,t)}},{key:"format",value:function(e){var t=this;return(e||"YYYY-MM-DDTHH:mm:ssZ").replace(l,function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return String(t.$y);case"M":return String(t.$M+1);case"MM":return $(t.$M+1,2,"0");case"MMM":return o[t.$M].slice(0,3);case"MMMM":return o[t.$M];case"D":return String(t.$D);case"DD":return $(t.$D,2,"0");case"d":return String(t.$W);case"dddd":return c[t.$W];case"H":return String(t.$H);case"HH":return $(t.$H,2,"0");case"h":case"hh":return 0===t.$H?12:$(t.$H<13?t.$H:t.$H-12,"hh"===e?2:1,"0");case"a":return t.$H<12?"am":"pm";case"A":return t.$H<12?"AM":"PM";case"m":return String(t.$m);case"mm":return $(t.$m,2,"0");case"s":return String(t.$s);case"ss":return $(t.$s,2,"0");case"Z":return"".concat(t.$zoneStr.slice(0,-2),":00");default:return t.$zoneStr}})}},{key:"diff",value:function(e,n,r){var c,o,l,$,f,y,v=d(n),m=e instanceof h?e:new h(e),k=this-m,M=(c=this,$=12*((o=m).year()-c.year())+(o.month()-c.month()),f=c.clone().add($,"months"),l=o-f<0?(o-f)/(f-c.clone().add($-1,"months")):(o-f)/(c.clone().add($+1,"months")-f),Number(-($+l)));switch(v){case u:M/=12;break;case a:break;case"quarter":M/=3;break;case i:M=k/6048e5;break;case s:M=k/864e5;break;case t:M=k/1e3;break;default:M=k}return r?M:(y=M)<0?Math.ceil(y)||0:Math.floor(y)}},{key:"daysInMonth",value:function(){return this.endOf(a).$D}},{key:"clone",value:function(){return new h(this)}},{key:"toDate",value:function(){return new Date(this.$d)}},{key:"toArray",value:function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}},{key:"toJSON",value:function(){return this.toISOString()}},{key:"toISOString",value:function(){return this.toDate().toISOString()}},{key:"toObject",value:function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}},{key:"toString",value:function(){return this.$d.toUTCString()}}])&&e(y.prototype,v),m&&e(y,m),h}();return function(e){return new y(e)}});
!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})$/,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}/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]):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;this.$zone=this.$d.getTimezoneOffset()/60,this.$zoneStr=(t=this.$zone,n="",n=(e=-1*t)>-10&&e<10?"$10$200":"$1$200",$(String(e).replace(/^(.)?(\d)/,n),5,"+")),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 n=e,Number.isNaN(parseFloat(n))||!Number.isFinite(n)?this:this.clone().mSet(t,e);var n},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){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"Z":return e.$zoneStr.slice(0,-2)+":00";default:return e.$zoneStr}})},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)}});
{
"name": "dayjs",
"version": "1.5.18",
"version": "1.5.19",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/dayjs.min.js",

@@ -210,2 +210,12 @@ English | [简体中文](./README.zh-CN.md)

#### Day of Week
* returns a Number
Get day of the week.
```js
dayjs().day();
```
#### Hour

@@ -212,0 +222,0 @@

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

if (config === null) return new Date(NaN) // Treat null as an invalid date
if (!config) return new Date()
if (Utils.isUndefined(config)) return new Date()
if (config instanceof Date) return config

@@ -26,3 +26,3 @@ // eslint-disable-next-line no-cond-assign

this.$zone = this.$d.getTimezoneOffset() / 60
this.$zoneStr = Utils.padStart(Utils.padZoneStr(this.$zone), 5, '+')
this.$zoneStr = Utils.padZoneStr(this.$zone)
this.$y = this.$d.getFullYear()

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

startOf(units, startOf) { // startOf -> endOf
const isStartOf = startOf !== undefined ? startOf : true
const isStartOf = !Utils.isUndefined(startOf) ? startOf : true
const unit = Utils.prettyUnit(units)

@@ -103,0 +103,0 @@ const instanceFactory = (d, m, y = this.$y) => {

@@ -15,3 +15,3 @@ export const padStart = (string, length, pad) => {

}
return String(hour).replace(/^(.)?(\d)/, replacer)
return padStart(String(hour).replace(/^(.)?(\d)/, replacer), 5, '+')
}

@@ -40,1 +40,3 @@

export const prettyUnit = u => (u && String(u).toLowerCase().replace(/s$/, ''))
export const isUndefined = s => s === undefined

@@ -79,4 +79,13 @@ import moment from 'moment'

it('Format Time Zone ZZ', () => {
MockDate.set(new Date('2018-05-02T23:00:00.000'), 60 * 8)
expect(dayjs().format('Z')).toBe(moment().format('Z'))
expect(dayjs().format('ZZ')).toBe(moment().format('ZZ'))
MockDate.set(new Date('2018-05-02T23:00:00.000'), 60 * 8 * -1)
expect(dayjs().format('ZZ')).toBe(moment().format('ZZ'))
MockDate.set(new Date('2018-05-02T23:00:00.000'), 0)
expect(dayjs().format('ZZ')).toBe(moment().format('ZZ'))
MockDate.set(new Date('2018-05-02T23:00:00.000'), 60 * 10)
expect(dayjs().format('ZZ')).toBe(moment().format('ZZ'))
MockDate.set(new Date('2018-05-02T23:00:00.000'), 60 * 11 * -1)
expect(dayjs().format('ZZ')).toBe(moment().format('ZZ'))
})

@@ -83,0 +92,0 @@

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

it('Number 0', () => {
expect(dayjs(0).valueOf()).toBe(moment(0).valueOf())
})
it('Clone not affect each other', () => {

@@ -46,0 +50,0 @@ const base = dayjs(20170101)

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