Skip to content

Commit 9884ca5

Browse files
committed
fix: Fix bug in customParseFormat plugin while month(MM) is '01'
fix #494
1 parent 41eb641 commit 9884ca5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/plugin/customParseFormat/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const parseFormattedInput = (input, format) => {
129129
}
130130
const now = new Date()
131131
return new Date(
132-
year || now.getFullYear(), month - 1 || now.getMonth(), day || now.getDate(),
132+
year || now.getFullYear(), month > 0 ? month - 1 : now.getMonth(), day || now.getDate(),
133133
hours || 0, minutes || 0, seconds || 0, milliseconds || 0
134134
)
135135
} catch (e) {

test/plugin/customParseFormat.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ it('parse padded string', () => {
2424
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
2525
})
2626

27+
it('parse string January (getMonth() = 0)', () => {
28+
const input = '01/01/2019'
29+
const format = 'DD/MM/YYYY'
30+
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
31+
})
32+
2733
it('parse unpadded string', () => {
2834
const input = '2.5.18 1:2:3.4 PM -0100'
2935
const format = 'D.M.YY H:m:s.S A ZZ'

0 commit comments

Comments
 (0)