From c0d31ce0c70b3f37b1fe6c373ec24619b0302caa Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Thu, 21 Jan 2021 18:09:50 +0100 Subject: [PATCH] templatetags: ease undestanding openinghoursspecification is used as default (#50419) --- combo_plugin_gnm/templatetags/gnm.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/combo_plugin_gnm/templatetags/gnm.py b/combo_plugin_gnm/templatetags/gnm.py index 4eb0469..85cfb71 100644 --- a/combo_plugin_gnm/templatetags/gnm.py +++ b/combo_plugin_gnm/templatetags/gnm.py @@ -254,10 +254,12 @@ def parse_mairie_formats(data, base_datetime, oh_add, ohs_add, ohs_del): if 'properties' in data: data = data['properties'] + some_opening_periods_defined = False known_format = False previous_week = base_datetime - datetime.timedelta(7) next_week = base_datetime + datetime.timedelta(7) for specification in data.get('openinghoursspecification', []): + known_format = True valid_from, valid_through = previous_week, next_week if specification.get('validFrom'): valid_from = parse_valid_from(specification) @@ -265,21 +267,22 @@ def parse_mairie_formats(data, base_datetime, oh_add, ohs_add, ohs_del): valid_through = parse_valid_through(specification) if not valid_from or not valid_through: continue + # parse specification only for the current period relative to utcnow() + if not valid_from <= base_datetime < valid_through: + continue if specification.get('opens') and specification.get('closes'): - known_format = True # case when opening periods are defined - if valid_from <= base_datetime < valid_through: - # parse specification only for the current period relative to utcnow() - try: - day_number, time_table = get_time_table_from_specification(specification) - except ValueError: - continue - ohs_add(day_number, time_table) + some_opening_periods_defined = True + try: + day_number, time_table = get_time_table_from_specification(specification) + except ValueError: + continue + ohs_add(day_number, time_table) else: # case when exclusions are defined ohs_del(valid_from, valid_through) - if not known_format: + if not some_opening_periods_defined: # some mairie may only have opening periods defined into openinghours (e.g. Bron) for days_list, time_table in parse_opening_hours_data(data): known_format = True