Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda