Skip to content

Commit

Permalink
fix: Fix CustomParseFormat Plugin 'YYYY-MM' use first day of the month
Browse files Browse the repository at this point in the history
fix #761
  • Loading branch information
iamkun committed Dec 30, 2019
1 parent 79b86db commit ba709ec
Show file tree
Hide file tree
Showing 2 changed files with 5 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 @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ba709ec

Please sign in to comment.