From 7eae61068cb76685f9021b0ee07e2b61caea3982 Mon Sep 17 00:00:00 2001 From: Etienne Callies Date: Sat, 2 Nov 2024 15:28:17 +0100 Subject: [PATCH] handle impossible date --- scraping/parse/explain_schedule.py | 4 +++- scraping/tests/tests_explain_schedules.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scraping/parse/explain_schedule.py b/scraping/parse/explain_schedule.py index faeb591..f515779 100644 --- a/scraping/parse/explain_schedule.py +++ b/scraping/parse/explain_schedule.py @@ -165,7 +165,7 @@ def get_monthly_explanation(rstr: rrule) -> str: def get_one_off_explanation(one_off_rule: OneOffRule) -> str: - if one_off_rule.year: + if one_off_rule.year and one_off_rule.is_valid_date(): if one_off_rule.liturgical_day: dt_start = get_liturgical_date(one_off_rule.liturgical_day, one_off_rule.year) else: @@ -182,6 +182,8 @@ def get_one_off_explanation(one_off_rule: OneOffRule) -> str: weekday_python = one_off_rule.weekday_iso8601 - 1 full_date += f"{NAME_BY_WEEKDAY[Weekday(weekday_python)]} " full_date += f"{one_off_rule.day} {NAME_BY_MONTH[PERIOD_BY_MONTH[one_off_rule.month]]}" + if one_off_rule.year: + full_date += f" {one_off_rule.year} (⚠️ date impossible)" return f"le {full_date.lower()}" diff --git a/scraping/tests/tests_explain_schedules.py b/scraping/tests/tests_explain_schedules.py index ed336c8..fa275ec 100644 --- a/scraping/tests/tests_explain_schedules.py +++ b/scraping/tests/tests_explain_schedules.py @@ -101,6 +101,22 @@ def get_fixtures(): ), 'Le 16 du mois de 16:00 à 19:00.' ), + ( + ScheduleItem( + church_id=None, + date_rule=OneOffRule( + year=2023, + month=3, + day=26, + weekday_iso8601=4, + liturgical_day=None + ), + is_cancellation=False, + start_time_iso8601='18:00:00', + end_time_iso8601=None, + ), + 'Le jeudi 26 mars 2023 (⚠️ date impossible) à partir de 18:00.' + ), ] def test_explain_schedules(self):