Skip to content

Commit

Permalink
fix(add dayjs.unix): add dayjs.unix to parse timestamp in seconds && …
Browse files Browse the repository at this point in the history
…locale update
  • Loading branch information
iamkun committed Sep 25, 2018
1 parent 39b1e0a commit 5711c5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ dayjs.locale = parseLocale

dayjs.isDayjs = isDayjs

dayjs.unix = timestamp => (
dayjs(timestamp * 1e3)
)

dayjs.en = Ls[L]

export default dayjs
7 changes: 7 additions & 0 deletions test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ it('Unix Timestamp Number (milliseconds) 1523520536000', () => {
expect(dayjs(timestamp).valueOf()).toBe(moment(timestamp).valueOf())
})

it('Unix Timestamp Number (seconds) 1318781876', () => {
const timestamp1 = 1318781876
const timestamp2 = 1318781876.721
expect(dayjs.unix(timestamp1).valueOf()).toBe(moment.unix(timestamp1).valueOf())
expect(dayjs.unix(timestamp2).valueOf()).toBe(moment.unix(timestamp2).valueOf())
})

it('String and Number 20180101', () => {
expect(dayjs(20180101).valueOf()).toBe(moment(20180101).valueOf())
expect(dayjs('20180101').valueOf()).toBe(moment('20180101').valueOf())
Expand Down

0 comments on commit 5711c5e

Please sign in to comment.