diff --git a/src/index.js b/src/index.js index e34a920ff..7b37258be 100644 --- a/src/index.js +++ b/src/index.js @@ -446,6 +446,10 @@ dayjs.locale = parseLocale dayjs.isDayjs = isDayjs +dayjs.unix = timestamp => ( + dayjs(timestamp * 1e3) +) + dayjs.en = Ls[L] export default dayjs diff --git a/test/parse.test.js b/test/parse.test.js index 395d36882..5dab174b9 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -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())