From 90abbc62d77cfe5f3e82ffa3592c23f6322a3c03 Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 10 May 2018 13:35:27 +0800 Subject: [PATCH 1/2] fix: fix add millisecond --- src/index.js | 9 +++++++-- test/manipulate.test.js | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 6e89b52db..853fd90d5 100644 --- a/src/index.js +++ b/src/index.js @@ -175,7 +175,8 @@ class Dayjs { add(number, units) { 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) { let date = this.set(C.DATE, 1).set(C.M, this.$M + number) date = date.set(C.DATE, Math.min(this.$D, date.daysInMonth())) @@ -202,8 +203,12 @@ class Dayjs { case C.W: step = C.MILLISECONDS_A_WEEK break - default: // s seconds + case 's': + case C.S: step = C.MILLISECONDS_A_SECOND + break + default: // ms + step = 1 } const nextTimeStamp = this.valueOf() + (number * step) return new Dayjs(nextTimeStamp) diff --git a/test/manipulate.test.js b/test/manipulate.test.js index 9c7aac810..76e87d278 100644 --- a/test/manipulate.test.js +++ b/test/manipulate.test.js @@ -28,6 +28,8 @@ describe('StartOf EndOf', () => { 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()) expect(dayjs().add(1, 'seconds').valueOf()).toBe(moment().add(1, 'seconds').valueOf()) expect(dayjs().add(1, 'm').valueOf()).toBe(moment().add(1, 'm').valueOf()) From 12c35df3eb66ec727c051f7c7de25127ad621d5b Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 10 May 2018 13:38:54 +0800 Subject: [PATCH 2/2] chore: update package.json --- package.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9243c8fda..d72ec3403 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dayjs", "version": "0.0.0-development", - "description": "", + "description": "2KB immutable date library alternative to Moment.js with the same modern API ", "main": "dist/dayjs.min.js", "types": "index.d.ts", "scripts": { @@ -23,6 +23,13 @@ "src/*" ] }, + "keywords": [ + "dayjs", + "date", + "time", + "immutable", + "moment" + ], "author": "iamkun", "license": "MIT", "repository": {