Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Overriding a single Locale property in dayjs()

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!