iamkun / iamkun/dayjs

Handle unsupported locale also change global locale

Open
#1,875 2 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**
```
import dayjs from 'dayjs';
import 'dayjs/locale/fr';
import 'dayjs/locale/es';

dayjs.locale('fr');

setTimeout(() => {
const globalLanguage = dayjs.locale();
console.log('1 language', globalLanguage);
}, 1000);

setTimeout(() => {
const localTranslate = dayjs().locale('es-es').locale();
console.log('2 language', localTranslate);
}, 3000);

setTimeout(() => {
const globalLanguage = dayjs.locale();
console.log('3 language', globalLanguage);
}, 5000);
```
result:
1 language fr
2 language es
3 language es

if we change from `es-es` to `en-us` it would behave similar... both `es-es` and `en-us` are not supported by dayjs and they force global locale to be changed

**Expected behavior**
It should not change the global locale when handle unsupported local locale

**Information**
- Day.js Version [e.g. v1.11.0, v1.11.1]
- OS: Window and Mac OS
- Browser: Chrome version 100.0.4896.127
- Time zone: GMT+7 Indochina Time

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied Day.js reproduction and trace how the locale('es-es') call is handled. Add a regression test showing that an unsupported local locale does not change the global locale, then verify the expected language values from the example.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.