Пример #1
0
 /**
  * @param from
  * @param to
  * @param offsetMinutes
  * @return
  */
 private Pair<Set<LocalTime>, Set<LocalTime>> getTimeOptions(
     DateTime from, DateTime to, int offsetMinutes) {
   Set<LocalTime> first = new TreeSet<LocalTime>();
   Set<LocalTime> second = new TreeSet<LocalTime>();
   if (from == null || to == null) {
     return new Pair<Set<LocalTime>, Set<LocalTime>>(first, second);
   }
   LocalTime startTime = from.toLocalTime();
   from = from.plusMinutes(offsetMinutes);
   int minuteInterval = from.getMinuteOfHour() % 15;
   from = from.plusMinutes(minuteInterval == 0 ? 0 : 15 - minuteInterval);
   while (!from.isAfter(to)) {
     LocalTime nextTime = from.toLocalTime();
     if (!nextTime.isAfter(startTime)) {
       second.add(nextTime);
     } else {
       first.add(nextTime);
     }
     from = from.plusMinutes(15);
   }
   return new Pair<Set<LocalTime>, Set<LocalTime>>(first, second);
 }
Пример #2
0
  public void checkForBookedCourts(
      TimeSlot timeSlot, List<Booking> confirmedBookings, Boolean preventOverlapping) {
    LocalTime startTime = timeSlot.getStartTime();
    LocalTime endTime = timeSlot.getEndTime();

    for (Booking booking : confirmedBookings) {

      if (timeSlot.getDate().equals(booking.getBookingDate())) {
        LocalTime bookingStartTime = booking.getBookingTime();
        LocalTime bookingEndTime = bookingStartTime.plusMinutes(booking.getDuration().intValue());
        Boolean addBooking = false;
        if (preventOverlapping) {
          if (startTime.isBefore(bookingEndTime)) {
            if (endTime.isAfter(bookingStartTime)) {
              addBooking = true;
            }
          }
        } else {
          // for displaying allocations
          if (startTime.compareTo(bookingStartTime) >= 0) {
            if (endTime.compareTo(bookingEndTime) <= 0) {
              addBooking = true;
            }
          }
        }
        if (addBooking) {
          Offer offer = booking.getOffer();
          for (Offer timeSlotOffer : timeSlot.getConfig().getOffers()) {
            if (offer.equals(timeSlotOffer)) {
              timeSlot.addBooking(booking);
              break;
            }
          }
        }
      }
    }
  }