Skip to content

Commit 1f5a9db

Browse files
waseemahmad31iamkun
authored andcommitted
fix: Fix CustomParseFormat plugin bug (#568)
fix #555
1 parent 9007cc5 commit 1f5a9db

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/plugin/customParseFormat/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function makeParser(format) {
137137
const match = regex.exec(part)
138138
const value = match[0]
139139
parser.call(time, value)
140-
start += value.length
140+
input = input.replace(value, '')
141141
}
142142
}
143143
correctHours(time)

test/plugin/customParseFormat.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ it('return Invalid Date when parse corrupt short string', () => {
161161
expect(dayjs(input, format).format()).toBe('Invalid Date')
162162
})
163163

164+
it('Invalid Dates', () => {
165+
expect(dayjs('10/12/2014', 'YYYY-MM-DD').format('MM-DD-YYYY')).toBe('Invalid Date')
166+
expect(dayjs('10-12-2014', 'YYYY-MM-DD').format('MM-DD-YYYY')).toBe('Invalid Date')
167+
})
168+
169+
it('Valid Date', () => {
170+
expect(dayjs('2014/10/12', 'YYYY-MM-DD').format('MM-DD-YYYY')).toBe('10-12-2014')
171+
})
172+
164173
it('correctly parse month from string after changing locale globally', () => {
165174
const input = '2018 лютий 03'
166175
const format = 'YYYY MMMM DD'

0 commit comments

Comments
 (0)