iamkun / iamkun/dayjs

Wrong loading of plugins/locale breaks the app.

Open
#1,482 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Loading plugins before and then loading the locale for `en` breaks the app.

**Expected behavior**
Should work correctly without any error.

**Information**
- Day.js Version - 1.9.6
- OS: Mac
- Browser Chrome

Let's say we have code like this
```js
dayjs.extend(advancedFormat);
dayjs.locale(require('dayjs/locale/en'))

// Then when you try to do
dayjs().format('dddd, MMM Do, YYYY');
```
It breaks with an error `d.ordinal` is not a function. It is because there is no `ordinal` property in `en.js` file. More specifically this function https://github.com/iamkun/dayjs/blob/dev/src/plugin/advancedFormat/index.js#L6 should be moved to `en.js` file.

Repro - https://codesandbox.io/s/elegant-christian-hbsr7?file=/src/index.js

Happy to submit a PR.

Contributor guide

Open the contributing guide

Research direction

Start with src/plugin/advancedFormat/index.js and the en.js locale file referenced in the issue, then reproduce the failure using the linked CodeSandbox or the supplied formatting example. Verify that loading advancedFormat before the English locale no longer causes d.ordinal to be undefined when formatting the example date.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
internationalization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.