dayjs
dayjs copied to clipboard
Broken format "MMMM" while using local with option "weekStart"
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
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
.
Any updates?