Skip to content

Commit

Permalink
fix: fix parse time string vs time stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed May 8, 2018
1 parent 6e299cc commit 7dbdd1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -7,7 +7,7 @@ const parseConfig = (config) => {
if (Utils.isUndefined(config)) return new Date()
if (config instanceof Date) return config
// eslint-disable-next-line no-cond-assign
if (reg = String(config).match(C.REGEX_PARSE)) {
if ((typeof config === 'string') && (reg = config.match(C.REGEX_PARSE))) {
// 2018-08-08 or 20180808
return new Date(
reg[1], reg[2] - 1, reg[3],
Expand Down
5 changes: 5 additions & 0 deletions test/parse.test.js
Expand Up @@ -49,6 +49,11 @@ it('Unix Timestamp Number (milliseconds) 1523520536000', () => {
expect(dayjs(timestamp).valueOf()).toBe(moment(timestamp).valueOf())
})

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

it('Number 0', () => {
expect(dayjs(0).valueOf()).toBe(moment(0).valueOf())
})
Expand Down

0 comments on commit 7dbdd1d

Please sign in to comment.