diff --git a/custom_components/chore_helper/chore_weekly.py b/custom_components/chore_helper/chore_weekly.py index af72336..6a8294a 100644 --- a/custom_components/chore_helper/chore_weekly.py +++ b/custom_components/chore_helper/chore_weekly.py @@ -38,12 +38,15 @@ def _find_candidate_date(self, day1: date) -> date | None: week = day1.isocalendar()[1] weekday = day1.weekday() offset = -1 + if self._chore_day is not None: + day_index = WEEKDAYS.index(self._chore_day) + else: # if chore day is not set, just repeat the start date's day + day_index = start_date.weekday() + if (week - start_week) % self._period == 0: # Chore this week - if self._chore_day is not None: - day_index = WEEKDAYS.index(self._chore_day) - if day_index >= weekday: # Chore still did not happen - offset = day_index - weekday - iterate_by_week = 7 - weekday + WEEKDAYS.index(self._chore_day) + if day_index >= weekday: # Chore still did not happen + offset = day_index - weekday + iterate_by_week = 7 - weekday + day_index while offset == -1: # look in following weeks candidate = day1 + relativedelta(days=iterate_by_week) week = candidate.isocalendar()[1]