consider schedule without validity dates to be valid for current time (#18948)
This commit is contained in:
parent
2149f2adc2
commit
26f3687afd
|
@ -191,14 +191,14 @@ def get_slots_from_mairie_format(data, base_datetime):
|
|||
known_format = False
|
||||
slots = []
|
||||
exclusion_slots = []
|
||||
previous_week = base_datetime - datetime.timedelta(7)
|
||||
next_week = base_datetime + datetime.timedelta(7)
|
||||
if len(data.get('openinghours', [])) or len(data.get('openinghoursspecification', [])):
|
||||
known_format = True
|
||||
# prepare annual opening exclusions
|
||||
for specification in data.get('openinghoursspecification', []):
|
||||
valid_from, valid_through = (
|
||||
parse_datetime(specification.get('validFrom')),
|
||||
parse_datetime(specification.get('validThrough'))
|
||||
)
|
||||
valid_from = parse_datetime(specification.get('validFrom')) if specification.get('validFrom') else previous_week
|
||||
valid_through = parse_datetime(specification.get('validThrough')) if specification.get('validThrough') else next_week
|
||||
if not valid_from or not valid_through:
|
||||
continue
|
||||
if 'opens' in specification and 'closes' in specification:
|
||||
|
@ -254,13 +254,14 @@ def get_mairie_opening_hours(mairie_data):
|
|||
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" % (time_table['start_hour'], time_table['start_minute'], time_table['end_hour'], time_table['end_minute'])
|
||||
|
||||
if not known_format:
|
||||
# some mairie only have openinghoursspecification (e.g. Jonage)
|
||||
previous_week = base_datetime - datetime.timedelta(7)
|
||||
next_week = base_datetime + datetime.timedelta(7)
|
||||
for specification in mairie_data.get('openinghoursspecification', []):
|
||||
valid_from, valid_through = (
|
||||
parse_datetime(specification.get('validFrom')),
|
||||
parse_datetime(specification.get('validThrough'))
|
||||
)
|
||||
valid_from = parse_datetime(specification.get('validFrom')) if specification.get('validFrom') else previous_week
|
||||
valid_through = parse_datetime(specification.get('validThrough')) if specification.get('validThrough') else next_week
|
||||
if not valid_from or not valid_through:
|
||||
continue
|
||||
# case when opening periods are defined
|
||||
|
|
Loading…
Reference in New Issue