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

169
Vistas
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 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