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.15 to 1.5.16

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=function(e,t,n){return!e||e.length>=t?e:"".concat(Array(t+1-e.length).join(n)).concat(e)},o=function(e){return e&&String(e).toLowerCase().replace(/s$/,"")},h=function(e){var t;return e?e instanceof Date?e:(t=String(e).match(/^(\d{4})-?(\d{2})-?(\d{1,2})$/))?new Date(t[1],t[2]-1,t[3]):new Date(e):new Date},l=function(){function l(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l),this.$d=h(e),this.init()}var d,$,f;return d=l,($=[{key:"init",value:function(){this.$zone=this.$d.getTimezoneOffset()/60,this.$zoneStr=c(String(-1*this.$zone).replace(/^(.)?(\d)/,"$10$200"),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:"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){var c=this,h=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],d=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c.$y,r=new l(new Date(n,t,e));return h?r:r.endOf(s)},$=function(e,t){return new l(c.toDate()[e].apply(c.toDate(),h?[0,0,0,0].slice(t):[23,59,59,999].slice(t)))};switch(o(e)){case u:return h?d(1,0):d(31,11,this.$y);case a:return h?d(1,this.$M):d(0,this.$M+1,this.$y);case i:return h?d(this.$D-this.$W,this.$M):d(this.$D+(6-this.$W),this.$M,this.$y);case s:case"date":return $("setHours",0);case r:return $("setMinutes",1);case n:return $("setSeconds",2);case t:return $("setMilliseconds",3);default:return this.clone()}}},{key:"endOf",value:function(e){return this.startOf(e,!1)}},{key:"mSet",value:function(e,s){switch(o(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,h=t&&1===t.length?t:o(t);if(["M",a].indexOf(h)>-1){var d=this.set("date",1).set(a,this.$M+e);return d=d.set("date",Math.min(this.$D,d.daysInMonth()))}if(["y",u].indexOf(h)>-1)return this.set(u,this.$y+e);switch(h){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 l(this.valueOf()+e*c)}},{key:"subtract",value:function(e,t){return this.add(-1*e,t)}},{key:"format",value:function(){var e=this,t=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],n=["January","February","March","April","May","June","July","August","September","October","November","December"];return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DDTHH:mm:ssZ").replace(/Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|m{1,2}|s{1,2}|Z{1,2}/g,function(r){switch(r){case"YY":return String(e.$y).slice(-2);case"YYYY":return String(e.$y);case"M":return String(e.$M+1);case"MM":return c(String(e.$M+1),2,"0");case"MMM":return n[e.$M].slice(0,3);case"MMMM":return n[e.$M];case"D":return String(e.$D);case"DD":return c(String(e.$D),2,"0");case"d":return String(e.$W);case"dddd":return t[e.$W];case"H":return String(e.$H);case"HH":return c(String(e.$H),2,"0");case"m":return String(e.$m);case"mm":return c(String(e.$m),2,"0");case"s":return String(e.$s);case"ss":return c(String(e.$s),2,"0");case"Z":return"".concat(e.$zoneStr.slice(0,-2),":00");default:return e.$zoneStr}})}},{key:"diff",value:function(e,n){var r,c,h,d,$,f,y=arguments.length>2&&void 0!==arguments[2]&&arguments[2],v=o(n),m=e instanceof l?e:new l(e),k=this-m,M=(r=this,d=12*((c=m).year()-r.year())+(c.month()-r.month()),$=r.clone().add(d,"months"),h=c-$<0?(c-$)/($-r.clone().add(d-1,"months")):(c-$)/(r.clone().add(d+1,"months")-$),Number(-(d+h))||0);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 y?M:(f=M)<0?Math.ceil(f)||0:Math.floor(f)}},{key:"daysInMonth",value:function(){return this.endOf(a).$D}},{key:"clone",value:function(){return new l(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(d.prototype,$),f&&e(d,f),l}();return function(e){return new l(e)}});
!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=function(e,t,n){return!e||e.length>=t?e:"".concat(Array(t+1-e.length).join(n)).concat(e)},o=function(e){return e&&String(e).toLowerCase().replace(/s$/,"")},h=function(e){var t;return null===e?new Date(NaN):e?e instanceof Date?e:(t=String(e).match(/^(\d{4})-?(\d{2})-?(\d{1,2})$/))?new Date(t[1],t[2]-1,t[3]):new Date(e):new Date},l=function(){function l(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l),this.$d=h(e),this.init()}var d,$,f;return d=l,($=[{key:"init",value:function(){this.$zone=this.$d.getTimezoneOffset()/60,this.$zoneStr=c(String(-1*this.$zone).replace(/^(.)?(\d)/,"$10$200"),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:"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){var c=this,h=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],d=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c.$y,r=new l(new Date(n,t,e));return h?r:r.endOf(s)},$=function(e,t){return new l(c.toDate()[e].apply(c.toDate(),h?[0,0,0,0].slice(t):[23,59,59,999].slice(t)))};switch(o(e)){case u:return h?d(1,0):d(31,11,this.$y);case a:return h?d(1,this.$M):d(0,this.$M+1,this.$y);case i:return h?d(this.$D-this.$W,this.$M):d(this.$D+(6-this.$W),this.$M,this.$y);case s:case"date":return $("setHours",0);case r:return $("setMinutes",1);case n:return $("setSeconds",2);case t:return $("setMilliseconds",3);default:return this.clone()}}},{key:"endOf",value:function(e){return this.startOf(e,!1)}},{key:"mSet",value:function(e,s){switch(o(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,h=t&&1===t.length?t:o(t);if(["M",a].indexOf(h)>-1){var d=this.set("date",1).set(a,this.$M+e);return d=d.set("date",Math.min(this.$D,d.daysInMonth()))}if(["y",u].indexOf(h)>-1)return this.set(u,this.$y+e);switch(h){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 l(this.valueOf()+e*c)}},{key:"subtract",value:function(e,t){return this.add(-1*e,t)}},{key:"format",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DDTHH:mm:ssZ",n="Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday".split("."),r="January.February.March.April.May.June.July.August.September.October.November.December".split(".");return t.replace(/Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|m{1,2}|s{1,2}|Z{1,2}/g,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 c(String(e.$M+1),2,"0");case"MMM":return r[e.$M].slice(0,3);case"MMMM":return r[e.$M];case"D":return String(e.$D);case"DD":return c(String(e.$D),2,"0");case"d":return String(e.$W);case"dddd":return n[e.$W];case"H":return String(e.$H);case"HH":return c(String(e.$H),2,"0");case"m":return String(e.$m);case"mm":return c(String(e.$m),2,"0");case"s":return String(e.$s);case"ss":return c(String(e.$s),2,"0");case"Z":return"".concat(e.$zoneStr.slice(0,-2),":00");default:return e.$zoneStr}})}},{key:"diff",value:function(e,n){var r,c,h,d,$,f,y=arguments.length>2&&void 0!==arguments[2]&&arguments[2],v=o(n),m=e instanceof l?e:new l(e),k=this-m,M=(r=this,d=12*((c=m).year()-r.year())+(c.month()-r.month()),$=r.clone().add(d,"months"),h=c-$<0?(c-$)/($-r.clone().add(d-1,"months")):(c-$)/(r.clone().add(d+1,"months")-$),Number(-(d+h))||0);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 y?M:(f=M)<0?Math.ceil(f)||0:Math.floor(f)}},{key:"daysInMonth",value:function(){return this.endOf(a).$D}},{key:"clone",value:function(){return new l(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(d.prototype,$),f&&e(d,f),l}();return function(e){return new l(e)}});
{
"name": "dayjs",
"version": "1.5.15",
"version": "1.5.16",
"description": "",

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

@@ -248,2 +248,25 @@ English | [简体中文](./ReadMe.zh-CN.md)

```
List of all available formats:
| Format | Output | Description |
| ------ | ------ | ----------- |
| `YY` | 18 | Two digit year |
| `YYYY` | 2018 | Four digit year |
| `M` | 1-12 | The month, beginning at 1 |
| `MM` | 01-12 | The month, with preceeding 0
| `MMM` | Jan-Dec | The abbreviated month name |
| `MMMM` | January-December | The full month name |
| `D` | 1-31 | The day of the month |
| `DD` | 01-31 | The day of the month, preceeding 0 |
| `d` | 0-6 | The day of the week, with Sunday as 0 |
| `dddd` | Sunday-Saturday | The name of the day of the week |
| `H` | 0-23 | The hour |
| `HH` | 00-23 | The hour, with preceeding 0 |
| `m` | 0-59 | The minute |
| `mm` | 00-59 | The minute, with preceeding 0 |
| `s` | 0-59 | The second |
| `ss` | 00-59 | The second, with preceeding 0 |
| `Z` | +5:00 | The offset from UTC |
| `ZZ` | +0500 | The offset from UTC with preceeding 0 |
#### Difference

@@ -250,0 +273,0 @@ - return Number

@@ -244,2 +244,3 @@ [English](./ReadMe.md) | 简体中文

接收一系列的时间日期字符串并替换成相应的值。
```js

@@ -250,2 +251,26 @@ dayjs().format(String);

```
详情如下:
| Format | Output | Description |
| ------ | ------ | ----------- |
| `YY` | 18 | 两位数的年份 |
| `YYYY` | 2018 | 四位数的年份 |
| `M` | 1-12 | 月份,从1开始 |
| `MM` | 01-12 | 月份,数字前面加上0
| `MMM` | Jan-Dec | 简写的月份名称 |
| `MMMM` | January-December | 完整的月份名称 |
| `D` | 1-31 | 月份里的一天 |
| `DD` | 01-31 | 月份里的一天,数字前面加上0 |
| `d` | 0-6 | 一周中的一天,星期天是0 |
| `dddd` | Sunday-Saturday | 一周中一天的名称 |
| `H` | 0-23 | 小时 |
| `HH` | 00-23 | 小时,数字前面加上0 |
| `m` | 0-59 | 分钟 |
| `mm` | 00-59 | 分钟,数字前面加上0 |
| `s` | 0-59 | 秒 |
| `ss` | 00-59 | 秒,数字前面加上0 |
| `Z` | +5:00 | UTC的偏移量 |
| `ZZ` | +0500 | UTC的偏移量,数字前面加上0 |
#### 时间差

@@ -252,0 +277,0 @@ - return Number

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

let reg
if (config === null) return new Date(NaN) // Treat null as an invalid date
if (!config) return new Date()

@@ -211,4 +212,4 @@ if (config instanceof Date) return config

format(formatStr = 'YYYY-MM-DDTHH:mm:ssZ') {
const weeks = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
const weeks = 'Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday'.split('.')
const months = 'January.February.March.April.May.June.July.August.September.October.November.December'.split('.')

@@ -215,0 +216,0 @@ return formatStr.replace(/Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|m{1,2}|s{1,2}|Z{1,2}/g, (match) => {

@@ -30,3 +30,3 @@ import moment from 'moment'

it('String Other and isValid', () => {
it('String Other, Null and isValid', () => {
global.console.warn = jest.genMockFunction()// moment.js otherString will throw warn

@@ -36,2 +36,3 @@ expect(dayjs('otherString').toString().toLowerCase()).toBe(moment('otherString').toString().toLowerCase())

expect(dayjs('otherString').isValid()).toBe(false)
expect(dayjs(null).toString().toLowerCase()).toBe(moment(null).toString().toLowerCase())
})

@@ -38,0 +39,0 @@ })

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