Example #1
0
 public function testSetDates()
 {
     $booking = new Booking(123, new Tenant(1, 'test'), new Room(1, 2, 'test'), new DateTime(), (new DateTime())->add(new DateInterval('P1M')));
     $newStartDate = (new DateTime())->add(new DateInterval('P1D'));
     $booking->setStartDate($newStartDate);
     $this->assertEquals($newStartDate, $booking->getStartDate());
     $newEndDate = (new DateTime())->add(new DateInterval('P2M'));
     $booking->setEndDate($newEndDate);
     $this->assertEquals($newEndDate, $booking->getEndDate());
 }
Example #2
0
 /**
  * Check if there's an overlap between the new reservation and the existing ones.
  *
  * @param Booking   $newBooking         The new Booking instance.
  * @param Booking[] $existingBookings   An array that contains the related reservations.
  *
  * @return bool   Return TRUE if there's an overlap, otherwise return FALSE.
  */
 private function isBookingTimeRangesOverlapped(Booking $newBooking, array $existingBookings)
 {
     foreach ($existingBookings as $existingBooking) {
         /** @var Booking $existingBooking */
         if ($newBooking->getId() == $existingBooking->getId()) {
             continue;
         }
         if ($newBooking->getStartDate() < $existingBooking->getEndDate() && $existingBooking->getStartDate() < $newBooking->getEndDate()) {
             return true;
         }
     }
     return false;
 }