iamkun / iamkun/dayjs

core bug with locale plugin

Open
#2,281 9 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

```js
> 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/dayjs@1.11.7/node_modules/dayjs/plugin/localizedFormat.js:1:676
at String.replace ()
at /Users/user/Projects/web/node_modules/.pnpm/dayjs@1.11.7/node_modules/dayjs/plugin/localizedFormat.js:1:563
at r.format (/Users/user/Projects/web/node_modules/.pnpm/dayjs@1.11.7/node_modules/dayjs/plugin/localizedFormat.js:1:761)
at e.format (/Users/user/Projects/web/node_modules/.pnpm/dayjs@1.11.7/node_modules/dayjs/plugin/preParsePostFormat.js:1:592)
at u.format (/Users/user/Projects/web/node_modules/.pnpm/dayjs@1.11.7/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`.

Contributor guide

Open the contributing guide

Research direction

Reproduce the lowercase l, ll, lll, and llll formats with the en locale, then inspect the localizedFormat.js plugin path shown in the stack trace and compare it with the locale definitions used by zh and de. Done means these formats no longer throw for affected locales and retain the expected localized output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.