Skip to content

Commit

Permalink
fix: customParseFormat support parsing X x timestamp (#1567)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun authored Jul 6, 2021
1 parent b5e40e6 commit eb087f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function makeParser(format) {

const parseFormattedInput = (input, format, utc) => {
try {
if (['x', 'X'].indexOf(format) > -1) return new Date((format === 'X' ? 1000 : 1) * input)
const parser = makeParser(format)
const {
year, month, day, hours, minutes, seconds, milliseconds, zone
Expand Down
9 changes: 9 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,12 @@ it('custom two-digit year parse function', () => {
const input3 = '99-05-02'
expect(dayjs(input3, format).year()).toBe(1899)
})

it('parse X x', () => {
const input = '1410715640.579'
const format = 'X'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
const input2 = '1410715640579'
const format2 = 'x'
expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf())
})

0 comments on commit eb087f5

Please sign in to comment.