-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(moment.locale): avoid lookup repeatedly with the wrong names. #4007
Conversation
A benchmark using a hexo dummy website (with 900 posts): Measure 5 times and calculate the average for each benchmark. Node.js 8
Node.js 10
Node.js 12
Node.js 13
|
@@ -23,7 +23,7 @@ SchemaTypeMoment.prototype.cast = function(value, data) { | |||
const { options } = this; | |||
value = toMoment(value); | |||
|
|||
if (options.language) value = value.locale(options.language); | |||
if (options.language) value = value.locale(toMomentLocale(options.language)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.language
always is undefined
.
This is a bug, or this is unnecessary code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4478cad
to
531780f
Compare
Benchmark for A benchmark using a hexo dummy website (with 900 posts): Measure 5 times and calculate the average for each benchmark. Benchmark conditions:
Node.js 8
Node.js 10
Node.js 12
Node.js 13
|
What does it do?
Hexo language code is different with
Moment.js
.If we set language like this,
or
then
default
orzh-CN
will pass tomoment.locale(lang)
.Whenever

.locale (lang)
is called, it causesmoment
to find the locale file repeatedly.This PR adds
toMomentLocale()
to convert lang code, avoid lookup repeatedly with the wrong names.How to test
Pull request tasks