diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index a210b53ff..ab09179d4 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -159,9 +159,9 @@ const parseFormattedInput = (input, format, utc) => { ) + (zone.offset * 60 * 1000)) } const now = new Date() + const d = day || ((!year && !month) ? now.getDate() : 1) const y = year || now.getFullYear() const M = month > 0 ? month - 1 : now.getMonth() - const d = day || now.getDate() const h = hours || 0 const m = minutes || 0 const s = seconds || 0 diff --git a/test/plugin/customParseFormat.test.js b/test/plugin/customParseFormat.test.js index 43e909b58..cafb94afd 100644 --- a/test/plugin/customParseFormat.test.js +++ b/test/plugin/customParseFormat.test.js @@ -161,6 +161,10 @@ it('return Invalid Date when parse corrupt short string', () => { expect(dayjs(input, format).format()).toBe('Invalid Date') }) +it('YYYY-MM set 1st day of the month', () => { + expect(dayjs('2019-02', 'YYYY-MM').format('YYYY-MM-DD')).toBe('2019-02-01') +}) + it('Invalid Dates', () => { expect(dayjs('10/12/2014', 'YYYY-MM-DD').format('MM-DD-YYYY')).toBe('Invalid Date') expect(dayjs('10-12-2014', 'YYYY-MM-DD').format('MM-DD-YYYY')).toBe('Invalid Date')