Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!