You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the local functions getShort, get$H, meridiemFunc, matches are created on every call, even if not needed
the same format string D MMMM YYYY is processed via str.replace(C.REGEX_FORMAT, ...) again and again on every call
Expected behavior
I'd like to have a way to preprocess/precompile format string in such a way that the following calls to format() will be very fast. E.g.
constnow=dayjs();constlist=[];constprecompiledFormat=dayjs.precompileFormat(`D MMMM YYYY`);for(constitemofgoods){list.push({
item,expires: now.add(item.daysLeft).format(precompiledFormat),// or maybe:expires: precompiledFormat(now.add(item.daysLeft))});}// render the list
Information
Day.js Version: 1.9.0
OS: Mac OS 12
Browser: Chrome 115
The text was updated successfully, but these errors were encountered:
Describe the bug
This takes too long, because every call to
.format()
does much of work under the hood:dayjs/src/index.js
Lines 262 to 342 in a9d7d03
The worst things performance-wise:
getShort
,get$H
,meridiemFunc
,matches
are created on every call, even if not neededD MMMM YYYY
is processed viastr.replace(C.REGEX_FORMAT, ...)
again and again on every callExpected behavior
I'd like to have a way to preprocess/precompile format string in such a way that the following calls to
format()
will be very fast. E.g.Information
The text was updated successfully, but these errors were encountered: