diff --git a/backend/db/crud.py b/backend/db/crud.py index be18e5a4ea90ec0456c4a79d0ec3891d40fde904..1209dcc586a9f151d029416f4bac55b209d6bfbb 100644 --- a/backend/db/crud.py +++ b/backend/db/crud.py @@ -19,8 +19,12 @@ def get_waiting_time(place: str, db: Session): """ Get the last estimated waiting time for the given place """ current_date = datetime.now(tz=pytz.timezone("Europe/Paris")) weekday, current_time = current_date.weekday(), current_date.time() - opening_hours = db.query(models.OpeningHours.open_time, models.OpeningHours.close_time).filter( - models.OpeningHours.place == place, models.OpeningHours.day == weekday).all() + opening_hours = db.query( + models.OpeningHours.open_time, + models.OpeningHours.close_time).filter( + models.OpeningHours.place == place, + models.OpeningHours.day == weekday).order_by( + models.OpeningHours.open_time).all() for time_slot in opening_hours: if current_time < time_slot.open_time: return schemas.WaitingTime(next_timetable=time_slot.open_time.strftime('%Hh%M'))