Skip to content

Commit

Permalink
fix: Fix bug in customParseFormat plugin while month(MM) is '01'
Browse files Browse the repository at this point in the history
fix #494
  • Loading branch information
iamkun committed Feb 14, 2019
1 parent 41eb641 commit 9884ca5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const parseFormattedInput = (input, format) => {
}
const now = new Date()
return new Date(
year || now.getFullYear(), month - 1 || now.getMonth(), day || now.getDate(),
year || now.getFullYear(), month > 0 ? month - 1 : now.getMonth(), day || now.getDate(),
hours || 0, minutes || 0, seconds || 0, milliseconds || 0
)
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ it('parse padded string', () => {
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse string January (getMonth() = 0)', () => {
const input = '01/01/2019'
const format = 'DD/MM/YYYY'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse unpadded string', () => {
const input = '2.5.18 1:2:3.4 PM -0100'
const format = 'D.M.YY H:m:s.S A ZZ'
Expand Down

0 comments on commit 9884ca5

Please sign in to comment.