Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

boolean match =  (dayx.isAfter(day0) && dayx.isBefore(day0.plus(length));
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda