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

Possible bug regarding dayjs.locale() usage #765

Closed
denchen opened this issue Jan 4, 2020 · 1 comment
Closed

Possible bug regarding dayjs.locale() usage #765

denchen opened this issue Jan 4, 2020 · 1 comment

Comments

@denchen
Copy link

denchen commented Jan 4, 2020

I want to have weekStart be 1 (start on Monday instead of Sunday), so my understanding is that we're supposed to use dayjs.locale() to override. So something like:

import dayjs from 'dayjs';
import en from 'dayjs/locale/en';

dayjs.locale({
  ...en,
  weekStart: 1
});

However, if I do this, then some functions break, such as dayjs().format('ll'), which gives me TypeError: Cannot read property 'replace' of undefined. Although dayjs().format('LL') does work.

I got around the problem by including formats in the locale info:

import dayjs from 'dayjs';
import en from 'dayjs/locale/en';

dayjs.locale({
  ...en,
  weekStart: 1,
  formats: {
    LT: 'h:mm A',
    LTS: 'h:mm:ss A',
    L: 'MM/DD/YYYY',
    LL: 'MMMM D, YYYY',
    LLL: 'MMMM D, YYYY h:mm A',
    LLLL: 'dddd, MMMM D, YYYY h:mm A'
  }
});

So my question is, am I supposed to include formats when overriding locale? Should I have to include other keys as well? Or is this a bug?

Information

  • Day.js Version: 1.8.18
  • OS: macOS Catalina 0.15.2
  • Browser: Chrome 79.0.3945.88
  • Time zone: GMT-07:00 PST (Pacific Daylight Time)
@iamkun
Copy link
Owner

iamkun commented Jan 6, 2020

You can try #766 UpdateLocale plugin in our latest release.

dayjs.updateLocale('en', {
  weekStart: 6
})

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