Skip to content

Commit

Permalink
handle impossible date
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennecallies committed Nov 2, 2024
1 parent c263414 commit 7eae610
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scraping/parse/explain_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()}"

Expand Down
16 changes: 16 additions & 0 deletions scraping/tests/tests_explain_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7eae610

Please sign in to comment.