Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugin/devHelper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default (o, c, d) => {
if (typeof date === 'number' && String(date).length === 4) {
console.warn(`Guessing you may want to parse the Year ${date}, you should pass it as a String ${date}, not a Number. Otherwise, ${date} will be treated as a Unix timestamp`)
}
if (cfg.args.length >= 2 && !d.p.customParseFormat) {
if (cfg.args.length >= 2 && typeof cfg.args[1] === 'string' && !d.p.customParseFormat) {
console.warn(`To parse a date-time string like ${date} using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format`)
}
return oldParse.bind(this)(cfg)
Expand Down
6 changes: 6 additions & 0 deletions test/plugin/devHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ it('Warning Enable customParseFormat plugin while passing the second format para
expect(consoleSpy).toHaveBeenCalledWith('To parse a date-time string like 2020 using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format')
})

it('Warning Enable customParseFormat plugin for date with format string (MM/DD/YYYY)', () => {
const consoleSpy = jest.spyOn(console, 'warn')
dayjs('11/1/2004', 'MM/DD/YYYY')
expect(consoleSpy).toHaveBeenCalledWith('To parse a date-time string like 11/1/2004 using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format')
})

it('Warning: Setting locale before loading locale', () => {
const consoleSpy = jest.spyOn(console, 'warn')
dayjs.locale('zh-cn')
Expand Down