Skip to content

Commit

Permalink
fix: CustomParseFormat correct parse HH:mm:ss with only one digit lik…
Browse files Browse the repository at this point in the history
…e 0:12:10
  • Loading branch information
iamkun committed Mar 6, 2019
1 parent e487922 commit 600d547
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ const expressions = {
this.milliseconds = +input
}],
s: [match1to2, addInput('seconds')],
ss: [match2, addInput('seconds')],
ss: [match1to2, addInput('seconds')],
m: [match1to2, addInput('minutes')],
mm: [match2, addInput('minutes')],
mm: [match1to2, addInput('minutes')],
H: [match1to2, addInput('hours')],
h: [match1to2, addInput('hours')],
HH: [match2, addInput('hours')],
hh: [match2, addInput('hours')],
HH: [match1to2, addInput('hours')],
hh: [match1to2, addInput('hours')],
D: [match1to2, addInput('day')],
DD: [match2, addInput('day')],
M: [match1to2, addInput('month')],
Expand Down
20 changes: 19 additions & 1 deletion test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,30 @@ it('timezone with no hour', () => {
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse just hh:mm)', () => {
it('parse hh:mm', () => {
const input = '12:00'
const format = 'hh:mm'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse HH:mm:ss', () => {
const input = '00:27:21'
const format = 'HH:mm:ss'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse HH:mm:ss but only one digit', () => {
const input = '0:0:1'
const format = 'HH:mm:ss'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse hh:mm:ss but only one digit', () => {
const input = '0:0:1'
const format = 'hh:mm:ss'
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'
Expand Down

0 comments on commit 600d547

Please sign in to comment.