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

185
Views
Joda-Time: Test if a LocalDate falls in a duration

What is an efficient and easy-to-read expression of testing if LocalDate dayX falls in a duration that is described with a starting day LocalDate day0 and a length Period length?

Currently I am doing like this:

boolean match = !day0.isAfter(dayX) && day0.plus(length).isAfter(dayX);

I just feel this looks a bit dumb and every time I read this it takes several seconds for my brain to tell if the boundaries are correct. So I am looking for a smarter way that maybe involves the Duration or Interval classes.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

What you are doing is correct (except that you need to use before method for the first condition). Maybe you can wrap it into a method and call it to make it reusable and look more elegant, e.g.:

public boolean isInRange(Localdate start, Period period, Localdate target){
   return !target.before(start) && !target.after(start.plus(period));
}
over 4 years ago · Santiago Trujillo Report

0

Somewhat similar approach: day0 < dayx < (day0 + period)

boolean match =  (dayx.isAfter(day0) && dayx.isBefore(day0.plus(length));
over 4 years ago · Santiago Trujillo 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!