templatetags: simplify get_period_from_data (#48919)
This commit is contained in:
parent
2e0328ed29
commit
d75a455f4d
|
@ -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" % (
|
||||
|
|
Loading…
Reference in New Issue