We allow users to change their preferred locale in our web application. I set the dayjs() locale using a variable like this:
var localeAbbr = '@server_generated_abbr';
dayjs.locale(localeAbbr);
However, we also let them choose their preferred first day of week (which may conflict with their locale and the dayjs local settings file). How can I then override the single firstdayofweek local setting? How would I apply the following variable?
var firstDayOfWeek = @server_generated_var;
UPDATE
I figured out that I'm supposed to be able to do this:
dayjs.locale(localeAbbr, { weekStart: firstDayOfWeek });
This technically works if only using date manipulation functions, but it renders the format() function useless, always resulting in a JS error. It's a bug in the library that has been raised in GitHub but apparently never been addressed.
Cannot read property '7' of undefined
I can overcome the issue and "solve" my problem using the following (using ASP.Net razor)
dayjs.locale('@locale');
dayjs.Ls.@(locale).weekStart = @(firstDayOfWeek);
Which in my case renders as and works as expected.
dayjs.locale('en');
dayjs.Ls.en.weekStart = 1;
I'd like to use the preferred method, but until the bug is fixed, I can't. Hope this helps anybody else out there having the same issue as me.