Comparing version 1.4.2 to 1.4.3
@@ -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";const t=60,e=60*t,s=24*e,r=7*s,n=(t,e,s)=>!t||t.length>=e?t:`${Array(e+1-t.length).join(s)}${t}`;class i{constructor(t){this.utc=!1;const e=this.parseConfig(t);this.date=new Date(e),this.timeZone=this.date.getTimezoneOffset()/60,this.timeZoneString=n(String(-1*this.timeZone).replace(/^(.)?(\d)/,"$10$200"),5,"+"),this.mYear=this.date.getFullYear(),this.mMonth=this.date.getMonth(),this.mDay=this.date.getDate(),this.mWeek=this.date.getDay(),this.mHour=this.date.getHours(),this.mMinute=this.date.getMinutes(),this.mSecond=this.date.getSeconds()}parseConfig(t){if(!t)return new Date;if(t instanceof Date)return t;if(/^(\d){8}$/.test(t)){return this.utc=!0,`${t.substr(0,4)}-${t.substr(4,2)}-${t.substr(6,2)}`}return t}year(){return this.mYear}month(){return this.mMonth}unix(){const t=this.utc?60*this.timeZone*60*1e3:0;return Math.floor((this.date.getTime()+t)/1e3)}toString(){return this.date.toUTCString()}startOf(t){switch(t){case"year":return new i(new Date(this.year(),0,1));case"month":return new i(new Date(this.year(),this.month(),1));default:return this}}add(n,a){let h;switch(a){case"m":case"minutes":h=t;break;case"h":case"hours":h=e;break;case"d":case"days":h=s;break;case"w":case"weeks":h=r;break;default:h=1}const u=this.unix()+n*h;return new i(1e3*u)}subtract(t,e){return this.add(-1*t,e)}format(t="YYYY-MM-DDTHH:mm:ssZ"){const e=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];return t.replace(/Y{2,4}|M{1,2}|D{1,2}|d{1,4}|H{1,2}|m{1,2}|s{1,2}|Z{1,2}/g,t=>{switch(t){case"YY":return String(this.mYear).slice(-2);case"YYYY":return String(this.mYear);case"M":return String(this.mMonth+1);case"MM":return n(String(this.mMonth+1),2,"0");case"D":return String(this.mDay);case"DD":return n(String(this.mDay),2,"0");case"d":return String(this.mWeek);case"dddd":return e[this.mWeek];case"H":return String(this.mHour);case"HH":return n(String(this.mHour),2,"0");case"m":return String(this.mMinute);case"mm":return n(String(this.mMinute),2,"0");case"s":return String(this.mSecond);case"ss":return n(String(this.mSecond),2,"0");case"Z":return`${this.timeZoneString.slice(0,-2)}:00`;case"ZZ":return this.timeZoneString;default:return t}})}}return t=>new i(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";const t=60,e=60*t,s=24*e,r=7*s,n=(t,e,s)=>!t||t.length>=e?t:`${Array(e+1-t.length).join(s)}${t}`;class i{constructor(t){this.utc=!1;const e=this.parseConfig(t);this.$date=new Date(e),this.timeZone=this.$date.getTimezoneOffset()/60,this.timeZoneString=n(String(-1*this.timeZone).replace(/^(.)?(\d)/,"$10$200"),5,"+"),this.$year=this.$date.getFullYear(),this.$month=this.$date.getMonth(),this.$day=this.$date.getDate(),this.$week=this.$date.getDay(),this.$hour=this.$date.getHours(),this.$minute=this.$date.getMinutes(),this.$second=this.$date.getSeconds()}parseConfig(t){if(!t)return new Date;if(t instanceof Date)return t;if(/^(\d){8}$/.test(t)){return this.utc=!0,`${t.substr(0,4)}-${t.substr(4,2)}-${t.substr(6,2)}`}return t}year(){return this.$year}month(){return this.$month}date(){return this.$day}unix(){const t=this.utc?60*this.timeZone*60*1e3:0;return Math.floor((this.$date.getTime()+t)/1e3)}toString(){return this.$date.toUTCString()}startOf(t){switch(t){case"year":return new i(new Date(this.year(),0,1));case"month":return new i(new Date(this.year(),this.month(),1));default:return this}}add(n,a){let h;switch(a){case"m":case"minutes":h=t;break;case"h":case"hours":h=e;break;case"d":case"days":h=s;break;case"w":case"weeks":h=r;break;default:h=1}const u=this.unix()+n*h;return new i(1e3*u)}subtract(t,e){return this.add(-1*t,e)}format(t="YYYY-MM-DDTHH:mm:ssZ"){const e=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];return t.replace(/Y{2,4}|M{1,2}|D{1,2}|d{1,4}|H{1,2}|m{1,2}|s{1,2}|Z{1,2}/g,t=>{switch(t){case"YY":return String(this.$year).slice(-2);case"YYYY":return String(this.$year);case"M":return String(this.$month+1);case"MM":return n(String(this.$month+1),2,"0");case"D":return String(this.$day);case"DD":return n(String(this.$day),2,"0");case"d":return String(this.$week);case"dddd":return e[this.$week];case"H":return String(this.$hour);case"HH":return n(String(this.$hour),2,"0");case"m":return String(this.$minute);case"mm":return n(String(this.$minute),2,"0");case"s":return String(this.$second);case"ss":return n(String(this.$second),2,"0");case"Z":return`${this.timeZoneString.slice(0,-2)}:00`;case"ZZ":return this.timeZoneString;default:return t}})}}return t=>new i(t)}); |
{ | ||
"name": "dayjs", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -12,12 +12,12 @@ import * as Constant from './constant' | ||
const args = this.parseConfig(config) | ||
this.date = new Date(args) | ||
this.timeZone = this.date.getTimezoneOffset() / 60 | ||
this.$date = new Date(args) | ||
this.timeZone = this.$date.getTimezoneOffset() / 60 | ||
this.timeZoneString = padStart(String(this.timeZone * -1).replace(/^(.)?(\d)/, '$10$200'), 5, '+') | ||
this.mYear = this.date.getFullYear() | ||
this.mMonth = this.date.getMonth() | ||
this.mDay = this.date.getDate() | ||
this.mWeek = this.date.getDay() | ||
this.mHour = this.date.getHours() | ||
this.mMinute = this.date.getMinutes() | ||
this.mSecond = this.date.getSeconds() | ||
this.$year = this.$date.getFullYear() | ||
this.$month = this.$date.getMonth() | ||
this.$day = this.$date.getDate() | ||
this.$week = this.$date.getDay() | ||
this.$hour = this.$date.getHours() | ||
this.$minute = this.$date.getMinutes() | ||
this.$second = this.$date.getSeconds() | ||
} | ||
@@ -39,17 +39,21 @@ | ||
year() { | ||
return this.mYear | ||
return this.$year | ||
} | ||
month() { | ||
return this.mMonth | ||
return this.$month | ||
} | ||
date() { | ||
return this.$day | ||
} | ||
unix() { | ||
// timezone(hour) * 60 * 60 * 1000 => ms | ||
const zonePad = !this.utc ? 0 : this.timeZone * 60 * 60 * 1000 | ||
return Math.floor((this.date.getTime() + zonePad) / 1000) | ||
return Math.floor((this.$date.getTime() + zonePad) / 1000) | ||
} | ||
toString() { | ||
return this.date.toUTCString() | ||
return this.$date.toUTCString() | ||
} | ||
@@ -104,29 +108,29 @@ | ||
case 'YY': | ||
return String(this.mYear).slice(-2) | ||
return String(this.$year).slice(-2) | ||
case 'YYYY': | ||
return String(this.mYear) | ||
return String(this.$year) | ||
case 'M': | ||
return String(this.mMonth + 1) | ||
return String(this.$month + 1) | ||
case 'MM': | ||
return padStart(String(this.mMonth + 1), 2, '0') | ||
return padStart(String(this.$month + 1), 2, '0') | ||
case 'D': | ||
return String(this.mDay) | ||
return String(this.$day) | ||
case 'DD': | ||
return padStart(String(this.mDay), 2, '0') | ||
return padStart(String(this.$day), 2, '0') | ||
case 'd': | ||
return String(this.mWeek) | ||
return String(this.$week) | ||
case 'dddd': | ||
return weeks[this.mWeek] | ||
return weeks[this.$week] | ||
case 'H': | ||
return String(this.mHour) | ||
return String(this.$hour) | ||
case 'HH': | ||
return padStart(String(this.mHour), 2, '0') | ||
return padStart(String(this.$hour), 2, '0') | ||
case 'm': | ||
return String(this.mMinute) | ||
return String(this.$minute) | ||
case 'mm': | ||
return padStart(String(this.mMinute), 2, '0') | ||
return padStart(String(this.$minute), 2, '0') | ||
case 's': | ||
return String(this.mSecond) | ||
return String(this.$second) | ||
case 'ss': | ||
return padStart(String(this.mSecond), 2, '0') | ||
return padStart(String(this.$second), 2, '0') | ||
case 'Z': | ||
@@ -133,0 +137,0 @@ return `${this.timeZoneString.slice(0, -2)}:00` |
@@ -12,1 +12,5 @@ import moment from 'moment' | ||
test('Date', () => { | ||
expect(dayjs().date()).toBe(moment().date()) | ||
}) | ||
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
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
14020
255