I am working on a project for booking venues. The aim is to not allow the booking if the venue is already booking during this period
if (!alreadyBookedSet.isEmpty()) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
logger.debug("Check if the venue is already booked on this date" + booking.getBookingDate());
for (Booking alreadyBooked : alreadyBookedSet) {
String bookingDate = alreadyBooked.getBookingDate();
if (bookingDate.equals(booking.getBookingDate())) {
String alreadyBookedTimeStart = alreadyBooked.getTimeStart();
Date alreadyBookedTimeStartDate = simpleDateFormat.parse(alreadyBookedTimeStart);
String alreaydBookedTimeEnd = alreadyBooked.getTimeEnd();
Date alreaydBookedTimeEndDate = simpleDateFormat.parse(alreaydBookedTimeEnd);
String bookingTimeStart = booking.getTimeStart();
Date bookingTimeStartDate = simpleDateFormat.parse(bookingTimeStart);
String bookingTimeEnd = booking.getTimeEnd();
Date bookingTimeEndDate = simpleDateFormat.parse(bookingTimeEnd);
if (!bookingTimeStartDate.before(alreadyBookedTimeStartDate) && !bookingTimeEndDate.after(alreaydBookedTimeEndDate)) {
return true;
}
}
}
}
I have an issue when the venue is already booked from 2:00 PM to 3:00 PM and we want to book it from 1:00 PM to 3:00 PM. This returns that the venue is not already booked which it is.
Is there a way to solve all the probabilities a between method in java?