我正在做一个预订场地的项目。目的是如果场地在此期间已经预订,则不允许预订
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;
}
}
}
}
当场地已在下午 2:00 至下午 3:00 预订时,我遇到了一个问题,我们想在下午 1:00 至下午 3:00 预订场地。这将返回该场地尚未被预订。
有没有办法解决java中方法之间的所有概率?