From d75a455f4d92ff84707935dbcd4061154a57d880 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Sat, 5 Dec 2020 19:27:22 +0100 Subject: [PATCH] templatetags: simplify get_period_from_data (#48919) --- combo_plugin_gnm/templatetags/gnm.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/combo_plugin_gnm/templatetags/gnm.py b/combo_plugin_gnm/templatetags/gnm.py index 96147ce..6d8ac73 100644 --- a/combo_plugin_gnm/templatetags/gnm.py +++ b/combo_plugin_gnm/templatetags/gnm.py @@ -138,15 +138,16 @@ def openinghours_to_datetime(codename, hour, minute): return None -def get_period_from_data(weekday, open_close_time_string=None, opening_time=None, closing_time=None): +def get_period_from_data(weekday, time_table): """Return am or pm and all_day_hours from opening_time and closing_time """ - if open_close_time_string is not None: - (start_hour, start_minute, end_hour, end_minute) = open_close_time_string - if closing_time is None: - closing_time = openinghours_to_datetime(weekday, int(end_hour), int(end_minute)) - if opening_time is None: - opening_time = openinghours_to_datetime(weekday, int(start_hour), int(start_minute)) + start_hour = int(time_table['start_hour']) + start_minute = int(time_table['start_minute']) + end_hour = int(time_table['end_hour']) + end_minute = int(time_table['end_minute']) + + closing_time = openinghours_to_datetime(weekday, end_hour, end_minute) + opening_time = openinghours_to_datetime(weekday, start_hour, start_minute) all_day_hours = False if (opening_time < closing_time # closing_time may last on the night @@ -329,10 +330,7 @@ def get_mairie_opening_hours(mairie_data): } for i in range(7)])) def update_opening_hours(weekday, time_table): - period, all_day_hours = get_period_from_data( - weekday, open_close_time_string=( - time_table['start_hour'], time_table['start_minute'], - time_table['end_hour'], time_table['end_minute'])) + period, all_day_hours = get_period_from_data(weekday, time_table) if all_day_hours and period == 'am': opening_hours_dict[weekday]['pm'] = '' # empty string to avoid displaying fermé opening_hours_dict[weekday][period] = "%sh%s-%sh%s" % (