Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda