Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unsupported locale also change global locale #1875

Open
hxltinh opened this issue Apr 27, 2022 · 2 comments
Open

Handle unsupported locale also change global locale #1875

hxltinh opened this issue Apr 27, 2022 · 2 comments

Comments

@hxltinh
Copy link

hxltinh commented Apr 27, 2022

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
@barisbikmaz
Copy link

barisbikmaz commented Apr 28, 2022

Seems to be a regression. This was working on version 1.10.8

@barisbikmaz
Copy link

barisbikmaz commented Apr 29, 2022

Seems like this bug happened with this PR: #1524 .
On line 25 there is a recursive return statement where you do not pass the other arguments. Then the language is set globally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants