Skip to content

Commit

Permalink
Merge pull request #22 from xx45/dev
Browse files Browse the repository at this point in the history
fix(add): add missing toDate
  • Loading branch information
iamkun authored Apr 19, 2018
2 parents 16661f8 + d41ecd0 commit cfb0c03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ class Dayjs {
clone() {
return new Dayjs(this)
}

toDate() {
return new Date(this.$date)
}

toISOString() {
return this.toDate().toISOString()
}
}

export default config => (new Dayjs(config))
15 changes: 15 additions & 0 deletions test/display.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,18 @@ 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())
})

it('As ISO 8601 String e.g. 2013-02-04T22:44:30.652Z', () => {
expect(dayjs().toISOString()).toBe(moment().toISOString())
})

0 comments on commit cfb0c03

Please sign in to comment.