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

168
Visualizações
Luxon diff DST issue

I am trying to calculate time difference given a start datetime and end datetime. I have 2 date objects to calculate the time difference. The issue is when the dates span across a DST day (eg:- Nov 7th).

start datetime = Nov 6th, 16:30

end datetime = Nov 7th, 01:00

Expected difference = 8.5 hours, but received 9.5 hours

Using Luxon JS Library

<script src="https://cdn.jsdelivr.net/npm/luxon@1.25.0/build/global/luxon.min.js"></script>
<script>
startDate = luxon.DateTime.fromObject({year: 2021, month: 11, day: 06, hour: 16, minute: 30 }, { zone: 'America/New_York' });
endDate = luxon.DateTime.fromObject({year: 2021, month: 11, day: 07, hour: 01, minute: 0 }, { zone: 'America/New_York' });

diff = Math.abs(startDate.diff(endDate).as('hours'));
console.log(startDate.toMillis() + ' ' + endDate.toMillis() + ' ' + diff)
</script>

The above code gives me 570 which is 9.5 hours. I am expecting 510 which is 8.5 hours using the diff function.

I can use the offset on each of these dates to plus the offset difference

offset=(endDate.offset - startDate.offset)/60
console.log(endDate.diff(startDate, 'hours').plus({hours: offset}).toObject())

I wanted to know if there is another way to solve this using the diff method.

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