diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index 0bc8ef342..ad639beb1 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -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) { diff --git a/test/plugin/customParseFormat.test.js b/test/plugin/customParseFormat.test.js index 835df9674..e26cbea30 100644 --- a/test/plugin/customParseFormat.test.js +++ b/test/plugin/customParseFormat.test.js @@ -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'