Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: customParseFormat support parsing X x timestamp #1567

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
})