iamkun / iamkun/dayjs

Changing the `weekStart` value (even locally) breaks the `format` function globally

Open
#1,258 1 comment 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**
Changing the `weekStart` value breaks the `format` function, when changing locale locally or globally.

Minimal reproduction steps:
```js
// This works:
dayjs().format('DD MM YYYY')
// > "07 12 2020"

// Update locale *locally* or globally
dayjs().locale('en', { weekStart: 1 }).valueOf();
// > 1607303261223

// Now this breaks:
dayjs().format('DD MM YYYY')
// > Uncaught TypeError: i is undefined
```

**Expected behavior**

I would expect that [changing the locale locally](https://day.js.org/docs/en/i18n/instance-locale) to have no effect on other dayjs instances. This suggests there's some global state leaking out of the instance locale function.

**Information**
- Day.js Version: v1.9.7
- OS: Mac OS Catalina 10.15.4
- Browser: Confirmed in Firefox 83 and Chrome 86
- Time zone: GMT+11:00 AEDT (Australia/Sydney)

Likely related to #765 (however `updateLocale` doesn't work for me as I'm changing locale locally, not globally)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with the dayjs().locale(), valueOf(), and format() calls shown in the issue, then compare local locale changes with the related updateLocale behavior in #765. Done means changing weekStart locally no longer makes format fail and does not affect other Day.js instances.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.