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

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

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