Commit a0d63266 by Antonio Rueda

Arreglado un error que producía un bloqueo si la fecha final de una búsqueda

de disponibilidad de un hotel era muy lejana en el futuro.
parent eaa269dc
......@@ -110,7 +110,14 @@ public class Hotel {
* @return true si hay disponibilidad, false en caso contrario
*/
public boolean disponible(LocalDate fechaInicio, LocalDate fechaFin, int numHabSimple, int numHabDoble) {
for (var fecha = fechaInicio.plusDays(0); fecha.isBefore(fechaFin); fecha = fecha.plusDays(1))
// Obtener la fecha máxima donde hay registrada una reserva
final var fechaMax = reservas.stream()
.map(r -> r.fechaFin)
.max(LocalDate::compareTo)
.map(f -> f.isBefore(fechaFin) ? f : fechaFin)
.orElse(LocalDate.now());
for (var fecha = fechaInicio.plusDays(0); fecha.isBefore(fechaMax); fecha = fecha.plusDays(1))
if (!disponible(fecha, numHabSimple, numHabDoble))
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment