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

Broken format "MMMM" while using local with option "weekStart" #2499

Open
av-k opened this issue Nov 9, 2023 · 2 comments
Open

Broken format "MMMM" while using local with option "weekStart" #2499

av-k opened this issue Nov 9, 2023 · 2 comments

Comments

@av-k
Copy link

av-k commented Nov 9, 2023

Describe the bug
Make a minimal setup like:

import dayjs from "dayjs";

dayjs.locale("en", {weekStart: 1}); // cause {weekStart: number}

conole.log(dayjs().format("MMMM"))

Here is the playground with the sample code.

Expected behavior
There are no syntax errors.
The current month is displayed as November.

Information

  • Day.js Version: v1.11.10
  • OS: macOS Big Sur v11.7.8
  • Browser: Chrome Version 119.0.6045.105 (Official Build) (x86_64)
  • Time zone: GMT+1 Europe/Berlin
@av-k
Copy link
Author

av-k commented Jan 26, 2024

Some time ago, I left work on the functionality affected by this error. I have returned with some updates.
First, I found a possible workaround for this error.
Use Customization feature to setup your custom locale setting instead passing setting at the time of initialization.
It means instead this:

import dayjs from "dayjs";

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

do this:

import dayjs from "dayjs";
import pluginUpdateLocale from "dayjs/plugin/updateLocale";

dayjs.extend(pluginUpdateLocale);
dayjs.updateLocale("en", {weekStart: 1});

Second, I created a pull request to fix this error.
#2566

The cause of that issue here:

case 'MMMM':
  return getShort(months, $M)

the variable months is coming from:

    const {
      weekdays, months, meridiem
    } = locale

where locale can be assign in wrong way by this function parseLocale.

@av-k
Copy link
Author

av-k commented May 13, 2024

Any updates?

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

1 participant