Skip to content

Commit

Permalink
fix: update customParseFormat plugin support hh:mm
Browse files Browse the repository at this point in the history
close #484
  • Loading branch information
iamkun committed Feb 7, 2019
1 parent 5c5a7a0 commit 54947cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ const parseFormattedInput = (input, format) => {
minutes || 0, seconds || 0, milliseconds || 0
) + (zone.offset * 60 * 1000))
}
const now = new Date()
return new Date(
year, month - 1, day,
year || now.getFullYear(), month - 1 || now.getMonth(), day || now.getDate(),
hours || 0, minutes || 0, seconds || 0, milliseconds || 0
)
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ it('timezone with no hour', () => {
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse just hh:mm)', () => {
const input = '12:00'
const format = 'hh:mm'
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

1 comment on commit 54947cc

@josueayala27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I occupy this in a real case, for example my input is: 12:45:54 knowing that it has a 24-hour format 🤔

Please sign in to comment.