From c3f00d1a1f42313bf60ab5020814c919e5632a2f Mon Sep 17 00:00:00 2001 From: Antoine Gaudron-desjardins <antoine.gaudrondesjardins@student-cs.fr> Date: Wed, 20 Jul 2022 08:32:40 +0200 Subject: [PATCH] order opening hours so the next timetable is the good one --- backend/db/crud.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/db/crud.py b/backend/db/crud.py index be18e5a..1209dcc 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')) -- GitLab