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

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

Open
jordwest opened this issue Dec 7, 2020 · 1 comment

Comments

@jordwest
Copy link

jordwest commented Dec 7, 2020

Describe the bug
Changing the weekStart value breaks the format function, when changing locale locally or globally.

Minimal reproduction steps:

// 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 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)

@iamkun
Copy link
Owner

iamkun commented Dec 7, 2020

If you want to change the locale locally, you have to pass in the whole locale object.

import en from 'dayjs/locale/en'

const newEn = copy(en)
newEn.weekStart =  1

dayjs().locale(newEn)

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