dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

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

Open av-k opened this issue 1 year ago • 2 comments

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 avatar Nov 09 '23 08:11 av-k

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. https://github.com/iamkun/dayjs/pull/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 avatar Jan 26 '24 16:01 av-k

Any updates?

av-k avatar May 13 '24 08:05 av-k