Skip to content

Commit

Permalink
fix: update devHelper to add dev warning setting locale before loading
Browse files Browse the repository at this point in the history
  • Loading branch information
allmoviestvshowslistsfilmography28 authored and iamkun committed Jan 9, 2021
1 parent c1b2f39 commit 508233c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/plugin/devHelper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export default (o, c, d) => {
}
return oldParse.bind(this)(cfg)
}
const oldLocale = d.locale
d.locale = function (preset, object, isLocal) {
if (typeof object === 'undefined' && typeof preset === 'string') {
if (!d.Ls[preset]) {
console.warn(`Guessing you may want to use locale ${preset}, you have to load it before using it. https://day.js.org/docs/en/i18n/loading-into-nodejs`)
}
}
return oldLocale(preset, object, isLocal)
}
}
}

6 changes: 6 additions & 0 deletions test/plugin/devHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ it('Warning Enable customParseFormat plugin while passing the second format para
dayjs('2020', 'YYYY')
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: Setting locale before loading locale', () => {
const consoleSpy = jest.spyOn(console, 'warn')
dayjs.locale('zh-cn')
expect(consoleSpy).toHaveBeenCalledWith('Guessing you may want to use locale zh-cn, you have to load it before using it. https://day.js.org/docs/en/i18n/loading-into-nodejs')
})

0 comments on commit 508233c

Please sign in to comment.