def get_overlap(self, occurrence, skip_self=False): if self.reservation and occurrence.reservation and self.reservation.room_id != occurrence.reservation.room_id: raise ValueError( 'ReservationOccurrence objects of different rooms') if skip_self and self.reservation and occurrence.reservation and self.reservation == occurrence.reservation: return None, None return date_time.get_overlap((self.start_dt, self.end_dt), (occurrence.start_dt, occurrence.end_dt))
def get_room_nonbookable_periods_conflicts(candidates, occurrences): conflicts = [] for candidate in candidates: for occurrence in occurrences: overlap = get_overlap((candidate.start_dt, candidate.end_dt), (occurrence.start_dt, occurrence.end_dt)) if overlap.count(None) != len(overlap): obj = TempReservationOccurrence(overlap[0], overlap[1], None) conflicts.append(obj) return conflicts
def get_room_unbookable_hours_conflicts(candidates, occurrences): conflicts = [] for candidate in candidates: for occurrence in occurrences: hours_start_dt = candidate.start_dt.replace(hour=occurrence.start_time.hour, minute=occurrence.start_time.minute) hours_end_dt = candidate.end_dt.replace(hour=occurrence.end_time.hour, minute=occurrence.end_time.minute) overlap = get_overlap((candidate.start_dt, candidate.end_dt), (hours_start_dt, hours_end_dt)) if overlap.count(None) != len(overlap): obj = TempReservationOccurrence(overlap[0], overlap[1], None) conflicts.append(obj) return conflicts
def get_overlap(self, occurrence, skip_self=False): if self.reservation and occurrence.reservation and self.reservation.room_id != occurrence.reservation.room_id: raise ValueError('ReservationOccurrence objects of different rooms') if skip_self and self.reservation and occurrence.reservation and self.reservation == occurrence.reservation: return None, None return date_time.get_overlap((self.start_dt, self.end_dt), (occurrence.start_dt, occurrence.end_dt))