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

customParseFormat: parse a string with underscore delimiter #1349

Merged
merged 1 commit into from
Jan 22, 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
2 changes: 1 addition & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const match4 = /\d{4}/ // 0000 - 9999
const match1to2 = /\d\d?/ // 0 - 99
const matchSigned = /[+-]?\d+/ // -inf - inf
const matchOffset = /[+-]\d\d:?(\d\d)?/ // +00:00 -00:00 +0000 or -0000 +00
const matchWord = /\d*[^\s\d-:/()]+/ // Word
const matchWord = /\d*[^\s\d-_:/()]+/ // Word

let locale = {}

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 @@ -338,3 +338,12 @@ describe('meridiem locale', () => {
expect(dayjs(date, format, 'zh-cn').format(format2)).toBe(input)
})
})

it('parse a string for MMM month format with underscore delimiter', () => {
const input = 'Jan_2021'
const format = 'MMM_YYYY'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
const input2 = '21_Jan_2021_123523'
const format2 = 'DD_MMM_YYYY_hhmmss'
expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf())
})