diff --git a/combo_plugin_gnm/templatetags/gnm.py b/combo_plugin_gnm/templatetags/gnm.py index ce01a83..52d5032 100644 --- a/combo_plugin_gnm/templatetags/gnm.py +++ b/combo_plugin_gnm/templatetags/gnm.py @@ -97,8 +97,8 @@ def get_slots_from_mdr_format(data, today): continue # add to slots the opening hours in chronological order beginning from today slots.append(TimeSlot( - datetime.datetime(today.year, today.month, today.day, int(parts[0]), int(parts[1])), - datetime.datetime(today.year, today.month, today.day, int(parts[2]), int(parts[3])) + datetime.datetime(today.year, today.month, today.day, int(parts[0]), int(parts[1]), tzinfo=today.tzinfo), + datetime.datetime(today.year, today.month, today.day, int(parts[2]), int(parts[3]), tzinfo=today.tzinfo) )) today = today + datetime.timedelta(days=1) @@ -180,7 +180,7 @@ def as_opening_hours_badge(data, base_datetime=None): exclusion_slots = [] today = base_datetime.date() - (slots, known_format) = get_slots_from_mdr_format(data, today) + (slots, known_format) = get_slots_from_mdr_format(data, base_datetime) if not known_format: (slots, exclusion_slots, known_format) = get_slots_from_mairie_format(data, base_datetime) diff --git a/tests/test_as_opening_hours.py b/tests/test_as_opening_hours.py index 184f28d..851b18c 100644 --- a/tests/test_as_opening_hours.py +++ b/tests/test_as_opening_hours.py @@ -77,3 +77,19 @@ def test_all_mdr_data_parsed_correct(): """everything got parsed correctly""" opening_hours = [as_opening_hours_badge(x) for x in MDR_GEOJSON] assert opening_hours.count('') == 0 + +def test_mdr_closing_time(): + test_datetime = parse("2018-03-05T14:59:00+01:00") + test_html = [as_opening_hours_badge(x, base_datetime=test_datetime) for x in MDR_GEOJSON if x['properties']['nom'] == u'Maison de la Métropole Bramet'][0] + klass, label = 'open', u"Ouvert jusqu'à 16h45" + assert test_html == mark_safe(u'
%s
'% (klass, label)) + + test_datetime = parse("2018-03-05T15:50:00+01:00") + test_html = [as_opening_hours_badge(x, base_datetime=test_datetime) for x in MDR_GEOJSON if x['properties']['nom'] == u'Maison de la Métropole Bramet'][0] + klass, label = 'soon-to-be-closed', u"Ouvert jusqu'à 16h45" + assert test_html == mark_safe(u'
%s
'% (klass, label)) + + test_datetime = parse("2018-03-10T17:30:00+01:00") + test_html = [as_opening_hours_badge(x, base_datetime=test_datetime) for x in MDR_GEOJSON if x['properties']['nom'] == u'Maison de la Métropole Bramet'][0] + klass, label = 'closed', u"Réouvre lundi à 8h30" + assert test_html == mark_safe(u'
%s
'% (klass, label))