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

120
Visualizações
How can I adjust this function to work with daylight savings?

I was using this example to create a calendar in angular. But I realized today that when DST Ends the date is repeated and then the days are off by one from then on.

Look at the stackblitz. November 7 is repeated. stackblitz link to calendar

This is the code that generates the calendar days. How do I adjust this so that DST doesn't mess everything up?

  private getCalendarDays(date = new Date) {
var startDate;

startDate = this.getCalendarStartDay(date).getTime();


 const calendarStartTime =  startDate;
    return this.range(0, 41)
      .map(num => new Date(calendarStartTime + DAY_MS * num));
  }

  private getCalendarStartDay(date = new Date) {
    const [year, month] = [date.getFullYear(), date.getMonth()];
    const firstDayOfMonth = new Date(year, month, 1).getTime();

    return this.range(1,7)
      .map(num => new Date(firstDayOfMonth - DAY_MS * num))
      .find(dt => dt.getDay() === 0)
  }

  private range(start, end, length = end - start + 1) {
    return Array.from({ length }, (_, i) => start + i)
  }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not pretty sure but I imagine you can get the dates at 12 a.m. to avoid the problem

  private getCalendarStartDay(date = new Date) {
    const [year, month] = [date.getFullYear(), date.getMonth()];

    //see that I indicate the 1 of the month at 12:00:00
    const firstDayOfMonth = new Date(year, month,1,12,0,0,0).getTime();

    //well the range from 0 to 6
    return this.range(0,6)
      .map(num => new Date(firstDayOfMonth - DAY_MS * num))
      .find(dt => dt.getDay() === 0)
  }

NOTE: I got your error in october, not in november

about 4 years ago · Juan Pablo Isaza Relatório
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