diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index 0fbd9825..0bc8ef34 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -127,8 +127,9 @@ const parseFormattedInput = (input, format) => { minutes || 0, seconds || 0, milliseconds || 0 ) + (zone.offset * 60 * 1000)) } + const now = new Date() return new Date( - year, month - 1, day, + year || now.getFullYear(), 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 155560be..835df967 100644 --- a/test/plugin/customParseFormat.test.js +++ b/test/plugin/customParseFormat.test.js @@ -66,6 +66,12 @@ it('timezone with no hour', () => { expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf()) }) +it('parse just hh:mm)', () => { + const input = '12:00' + const format = 'hh:mm' + expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf()) +}) + it('fails with an invalid format', () => { const input = '2018-05-02 12:00 PM' const format = 'C'