dayjs
dayjs copied to clipboard
core bug with locale plugin
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('LT')
'12:00 AM'
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('LTS')
'12:00:00 AM'
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('L')
'04/23/2022'
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('LL')
'April 23, 2022'
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('LLL')
'April 23, 2022 12:00 AM'
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('LLLL')
'Saturday, April 23, 2022 12:00 AM'
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('l')
Uncaught TypeError: Cannot read properties of undefined (reading 'replace')
at /Users/user/Projects/web/node_modules/.pnpm/[email protected]/node_modules/dayjs/plugin/localizedFormat.js:1:676
at String.replace (<anonymous>)
at /Users/user/Projects/web/node_modules/.pnpm/[email protected]/node_modules/dayjs/plugin/localizedFormat.js:1:563
at r.format (/Users/user/Projects/web/node_modules/.pnpm/[email protected]/node_modules/dayjs/plugin/localizedFormat.js:1:761)
at e.format (/Users/user/Projects/web/node_modules/.pnpm/[email protected]/node_modules/dayjs/plugin/preParsePostFormat.js:1:592)
at u.format (/Users/user/Projects/web/node_modules/.pnpm/[email protected]/node_modules/dayjs/plugin/utc.js:1:1655)
> dayjs('4/23/22', 'M/DD/YY').locale('zh').format('l')
'2022/4/23'
> dayjs('4/23/22', 'M/DD/YY').locale('de').format('l')
'23.4.2022'
As you can see, there is an uncaught typeerror above for "l", "ll", "lll", and "llll" usage for certain locales, e.g. en.
The reason is because the englishFormats object does not contain it.
https://github.com/iamkun/dayjs/blob/00c223b7e92970d07557133994fcb225a6d4c960/src/plugin/localizedFormat/utils.js#L5-L12
Needs to have l, ll, lll, and llll added. Will submit a PR now.
This has been tested. Confirmed my PR works per #2282.
Please merge and release to npm with patch version bump.
Ping me back once done please! Thank you @iamkun.
> dayjs('4/23/22', 'M/DD/YY').locale('en').format('l') // this is with the PR
'4/23/2022'
I don't agree with your conclusion, because I looked up the source code and found this
const B = b && b.toUpperCase()
return a || formats[b] || englishFormats[b] || t(formats[B])
@tendguo you are incorrect as that output is undefined, and you get an uncaught exception TypeError. From my tests on the latest version of dayjs it is an error when you require all the locales and then run the above commands.
there should be no problem with localizedFormat plugin
https://runkit.com/embed/yzvddg5czfg6
This still looks to be an issue in 1.11.13:
Still seeing this issue as well. I am using the localizedFormat plugin.
there should be no problem with localizedFormat plugin
https://runkit.com/embed/yzvddg5czfg6
This is indeed still a real bug.
Weirdly enough it only happen for us when used as a Nuxt plugin, not when used as a singleton (but that's problematic due to cross-request sharing).
Yeah still 100% a bug that we clearly showed how to reproduce but is not resolved and ignored.