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

162
Visualizações
DayJs how to calculate first day and last day in a month that starts and ends on the same day

I have built a calendar using dayjs. To create a square calendar I have included the days starting from Sunday from the previous month and included the days finishing on Sunday from the following month.

For example, here is the code I am running to get the remaining days up until Sunday.

{range(6 - weekDayOfLast).map((dayIdx) => ())}

weekDayOfLast meaning the day from 0-6 the last day of the month falls on.

I need to apply some conditional CSS to all corners of the calendar, but in order to do this I have to calculate the first day of the calendar, the last day of the first week, the first day of the last week and the last day of the month.

I am struggling with how to figure this out.

The only one I have managed so far is the last day of the month:

dayIdx + 1 === 6 - weekDayOfLast ? "rounded-br-lg" : ""

I calculator the middle of the calendar by mapping over the days in the month, like this:

 {range(daysInMonth).map((dayIdx) => ()))}

And the first days of the calendar by calculating the day the first day of the month falls on, for example:

 {range(daysInMonth).map((dayIdx) => ()}
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