Skip to content

Commit 5711c5e

Browse files
committed
fix(add dayjs.unix): add dayjs.unix to parse timestamp in seconds && locale update
1 parent 39b1e0a commit 5711c5e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ dayjs.locale = parseLocale
446446

447447
dayjs.isDayjs = isDayjs
448448

449+
dayjs.unix = timestamp => (
450+
dayjs(timestamp * 1e3)
451+
)
452+
449453
dayjs.en = Ls[L]
450454

451455
export default dayjs

test/parse.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ it('Unix Timestamp Number (milliseconds) 1523520536000', () => {
5656
expect(dayjs(timestamp).valueOf()).toBe(moment(timestamp).valueOf())
5757
})
5858

59+
it('Unix Timestamp Number (seconds) 1318781876', () => {
60+
const timestamp1 = 1318781876
61+
const timestamp2 = 1318781876.721
62+
expect(dayjs.unix(timestamp1).valueOf()).toBe(moment.unix(timestamp1).valueOf())
63+
expect(dayjs.unix(timestamp2).valueOf()).toBe(moment.unix(timestamp2).valueOf())
64+
})
65+
5966
it('String and Number 20180101', () => {
6067
expect(dayjs(20180101).valueOf()).toBe(moment(20180101).valueOf())
6168
expect(dayjs('20180101').valueOf()).toBe(moment('20180101').valueOf())

0 commit comments

Comments
 (0)