From 47a41ea3686baeabcc1362097665bcc874348bdd Mon Sep 17 00:00:00 2001 From: iamkun Date: Mon, 16 Apr 2018 00:03:59 +0800 Subject: [PATCH 1/3] fix(add): add missing toDate --- src/index.js | 4 ++++ test/display.test.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/index.js b/src/index.js index 2ccdf20e5..8a26ea8ee 100644 --- a/src/index.js +++ b/src/index.js @@ -177,6 +177,10 @@ class Dayjs { clone() { return new Dayjs(this) } + + toDate() { + return new Date(this.$date) + } } export default config => (new Dayjs(config)) diff --git a/test/display.test.js b/test/display.test.js index b50aaa8c7..95dcfa59a 100644 --- a/test/display.test.js +++ b/test/display.test.js @@ -82,3 +82,14 @@ it('Days in Month', () => { expect(dayjs().daysInMonth()).toBe(moment().daysInMonth()) }) +it('As Javascript Date', () => { + const base = dayjs() + const momentBase = moment() + const jsDate = base.toDate() + expect(jsDate).toEqual(momentBase.toDate()) + expect(jsDate).toEqual(new Date()) + + jsDate.setFullYear(1970) + expect(jsDate.toUTCString()).not.toBe(base.toString()) +}) + From 2efe082f20c4fdcd38eb2a6c84307712004f8e1e Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 19 Apr 2018 10:12:20 +0800 Subject: [PATCH 2/3] fix(add toisostring): add toISOString --- src/index.js | 4 ++++ test/display.test.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/index.js b/src/index.js index 8a26ea8ee..b9cf0b73b 100644 --- a/src/index.js +++ b/src/index.js @@ -181,6 +181,10 @@ class Dayjs { toDate() { return new Date(this.$date) } + + toISOString() { + return this.toDate().toISOString(); + } } export default config => (new Dayjs(config)) diff --git a/test/display.test.js b/test/display.test.js index 95dcfa59a..52b53ff19 100644 --- a/test/display.test.js +++ b/test/display.test.js @@ -93,3 +93,7 @@ it('As Javascript Date', () => { expect(jsDate.toUTCString()).not.toBe(base.toString()) }) +it('As ISO 8601 String e.g. 2013-02-04T22:44:30.652Z', () => { + expect(dayjs().toISOString()).toBe(moment().toISOString()) +}) + From d41ecd00c51fccdebaa42100dde059ccc325774d Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 19 Apr 2018 10:13:02 +0800 Subject: [PATCH 3/3] style(lint): lint --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index b9cf0b73b..64aeb1cd5 100644 --- a/src/index.js +++ b/src/index.js @@ -183,7 +183,7 @@ class Dayjs { } toISOString() { - return this.toDate().toISOString(); + return this.toDate().toISOString() } }