Skip to content

Commit 54947cc

Browse files
committed
fix: update customParseFormat plugin support hh:mm
close #484
1 parent 5c5a7a0 commit 54947cc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/plugin/customParseFormat/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ const parseFormattedInput = (input, format) => {
127127
minutes || 0, seconds || 0, milliseconds || 0
128128
) + (zone.offset * 60 * 1000))
129129
}
130+
const now = new Date()
130131
return new Date(
131-
year, month - 1, day,
132+
year || now.getFullYear(), month - 1 || now.getMonth(), day || now.getDate(),
132133
hours || 0, minutes || 0, seconds || 0, milliseconds || 0
133134
)
134135
} catch (e) {

test/plugin/customParseFormat.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ it('timezone with no hour', () => {
6666
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
6767
})
6868

69+
it('parse just hh:mm)', () => {
70+
const input = '12:00'
71+
const format = 'hh:mm'
72+
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
73+
})
74+
6975
it('fails with an invalid format', () => {
7076
const input = '2018-05-02 12:00 PM'
7177
const format = 'C'

0 commit comments

Comments
 (0)