Fix checking schedules
@@ -14,23 +14,31 @@ class ReservationVerifier:
:param schedules: Schedule list that is checked to determine if reservation is allowed
:return: latest date starting from start_date allowed by given schedules
"""
- reservation_allowed = False
while True:
start_date_changed = False
for schedule in schedules:
day = start_date.weekday() + 1
if str(day) in schedule.schedule_days and schedule.hour_start <= start_date.time():
- if schedule.hour_end == time(hour=23, minute=59) or schedule.hour_end < schedule.hour_start:
+ if schedule.hour_end == time(hour=23, minute=59):
start_date = start_date.replace(hour=0, minute=0) + timedelta(days=1)
+ elif schedule.hour_start > schedule.hour_end:
+ start_date = start_date.replace(hour=schedule.hour_end.hour, minute=schedule.hour_end.minute)\
+ + timedelta(days=1)
elif start_date.time() < schedule.hour_end:
start_date = start_date.replace(hour=schedule.hour_end.hour, minute=schedule.hour_end.minute)
else:
continue
start_date_changed = True
+ # schedule starts on the previous day
+ elif str((day - 1) % 7) in schedule.schedule_days \
+ and start_date.time() < schedule.hour_end < schedule.hour_start:
+ start_date = start_date.replace(hour=schedule.hour_end.hour, minute=schedule.hour_end.minute)
+ start_date_changed = True
+ if start_date.minute == 59:
+ start_date = start_date + timedelta(minutes=1)
if start_date >= end_date:
- reservation_allowed = True
- break
- if reservation_allowed or not start_date_changed:
+ return start_date
+ if not start_date_changed:
break
return start_date
