Skip to content

Commit c5cc893

Browse files
committed
fix: update devHelper to add dev warning setting locale before loading
1 parent 1858df8 commit c5cc893

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/plugin/devHelper/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export default (o, c, d) => {
1616
}
1717
return oldParse.bind(this)(cfg)
1818
}
19+
const oldLocale = d.locale
20+
d.locale = function (preset, object, isLocal) {
21+
if (typeof object === 'undefined' && typeof preset === 'string') {
22+
if (!d.Ls[preset]) {
23+
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`)
24+
}
25+
}
26+
return oldLocale(preset, object, isLocal)
27+
}
1928
}
2029
}
2130

test/plugin/devHelper.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ it('Warning Enable customParseFormat plugin while passing the second format para
3232
dayjs('2020', 'YYYY')
3333
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')
3434
})
35+
36+
it('Warning: Setting locale before loading locale', () => {
37+
const consoleSpy = jest.spyOn(console, 'warn')
38+
dayjs.locale('zh-cn')
39+
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')
40+
})

0 commit comments

Comments
 (0)