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

154
Views
How do I compare Durations or Intervals in Luxon?

I have an Interval[], and I'd like to know which is the largest interval. I thought that converting them to Durations and then comparing may work, but I can't find appropriate methods in the luxon docs, and Google is getting me nowhere.

How do I compare durations or intervals? Thanks!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

One way is you can convert the date you have to an ISO string and then use diff to get the difference. https://moment.github.io/luxon/#/math?id=diffs.

var end = DateTime.fromISO('2017-03-13');
var start = DateTime.fromISO('2017-02-13');

var diffInMonths = end.diff(start, 'months');
diffInMonths.toObject(); //=> { months: 1 }

That's the example they show in that documentation.

You can also convert the date to a unix timestamp and subtract them to get a difference, after which you convert it back to a date.

If you didn't know "Luxon" is the improved package of the (now deprecated) "moment" package, that's why the documentation is still using moment.

For any more help than that I'd like more information on what exactly you're struggling with and see what you've already tried.

about 4 years ago · Juan Pablo Isaza Report

0

yourInterval.length() will give you the length of the interval in milliseconds. So you need only find the interval with the highest result.

about 4 years ago · Juan Pablo Isaza Report
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!