Skip to content

Commit 600d547

Browse files
committed
fix: CustomParseFormat correct parse HH:mm:ss with only one digit like 0:12:10
1 parent e487922 commit 600d547

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/plugin/customParseFormat/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ const expressions = {
4747
this.milliseconds = +input
4848
}],
4949
s: [match1to2, addInput('seconds')],
50-
ss: [match2, addInput('seconds')],
50+
ss: [match1to2, addInput('seconds')],
5151
m: [match1to2, addInput('minutes')],
52-
mm: [match2, addInput('minutes')],
52+
mm: [match1to2, addInput('minutes')],
5353
H: [match1to2, addInput('hours')],
5454
h: [match1to2, addInput('hours')],
55-
HH: [match2, addInput('hours')],
56-
hh: [match2, addInput('hours')],
55+
HH: [match1to2, addInput('hours')],
56+
hh: [match1to2, addInput('hours')],
5757
D: [match1to2, addInput('day')],
5858
DD: [match2, addInput('day')],
5959
M: [match1to2, addInput('month')],

test/plugin/customParseFormat.test.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,30 @@ it('timezone with no hour', () => {
7373
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
7474
})
7575

76-
it('parse just hh:mm)', () => {
76+
it('parse hh:mm', () => {
7777
const input = '12:00'
7878
const format = 'hh:mm'
7979
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
8080
})
8181

82+
it('parse HH:mm:ss', () => {
83+
const input = '00:27:21'
84+
const format = 'HH:mm:ss'
85+
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
86+
})
87+
88+
it('parse HH:mm:ss but only one digit', () => {
89+
const input = '0:0:1'
90+
const format = 'HH:mm:ss'
91+
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
92+
})
93+
94+
it('parse hh:mm:ss but only one digit', () => {
95+
const input = '0:0:1'
96+
const format = 'hh:mm:ss'
97+
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
98+
})
99+
82100
it('fails with an invalid format', () => {
83101
const input = '2018-05-02 12:00 PM'
84102
const format = 'C'

0 commit comments

Comments
 (0)