Skip to content

Commit

Permalink
Merge pull request #11 from bmcclure/due-date-offset
Browse files Browse the repository at this point in the history
Add due date offset config option to monthly chores
  • Loading branch information
bmcclure authored Apr 19, 2023
2 parents a7b2a9b + bc8cc3d commit 2e96040
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions custom_components/chore_helper/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,22 @@ async def detail_config_schema(
mode=selector.SelectSelectorMode.DROPDOWN,
)
)

options_schema[
optional(const.CONF_FORCE_WEEK_NUMBERS, handler.options)
] = selector.BooleanSelector()

options_schema[
optional(const.CONF_DUE_DATE_OFFSET, handler.options)
] = selector.NumberSelector(
selector.NumberSelectorConfig(
min=-7,
max=7,
mode=selector.NumberSelectorMode.SLIDER,
unit_of_measurement="day(s)",
)
)

if frequency in (const.WEEKLY_FREQUENCY + const.MONTHLY_FREQUENCY):
options_schema[
optional(const.CONF_CHORE_DAY, handler.options)
Expand Down
1 change: 1 addition & 0 deletions custom_components/chore_helper/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
CONF_ICON_OVERDUE = "icon_overdue"
CONF_OFFSET = "offset"
CONF_DAY_OF_MONTH = "day_of_month"
CONF_DUE_DATE_OFFSET = "due_date_offset"
CONF_FIRST_MONTH = "first_month"
CONF_LAST_MONTH = "last_month"
CONF_CHORE_DAY = "chore_day"
Expand Down
7 changes: 7 additions & 0 deletions custom_components/chore_helper/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ class MonthlyChore(Chore):
"_period",
"_weekday_order_number",
"_week_order_number",
"_due_date_offset",
)

def __init__(self, config_entry: ConfigEntry) -> None:
Expand All @@ -709,6 +710,7 @@ def __init__(self, config_entry: ConfigEntry) -> None:
self._monthly_force_week_numbers = config.get(
const.CONF_FORCE_WEEK_NUMBERS, False
)
self._due_date_offset = int(config.get(const.CONF_DUE_DATE_OFFSET, 0))
self._weekday_order_number: int | None
self._week_order_number: int | None
order_number: int = 1
Expand Down Expand Up @@ -862,6 +864,7 @@ def _find_candidate_date(self, day1: date) -> date | None:
if self._period is None or self._period == 1:
return self._monthly_candidate(day1, schedule_start_date)[0]
result = self._monthly_candidate(day1, schedule_start_date)

candidate_date = result[0]
candidate_month = result[1]
while (candidate_month - schedule_start_date.month) % self._period != 0:
Expand All @@ -874,6 +877,10 @@ def _find_candidate_date(self, day1: date) -> date | None:
)
candidate_date = result[0]
candidate_month = result[1]

if self._due_date_offset is not None:
candidate_date += timedelta(days=self._due_date_offset)

return candidate_date


Expand Down
2 changes: 2 additions & 0 deletions custom_components/chore_helper/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"first_week": "First due week (1-52)",
"start_date": "Start date",
"day_of_month": "Day of month",
"due_date_offset": "Offset each due date",
"weekday_order_number": "Order of the weekday in the month (e.g. first Wednesday of the month)",
"force_week_order_numbers": "Order of week in a month instead of order of weekday (e.g. on Wednesday of the first week)",
"date_format": "Date format (see http://strftime.org/)"
Expand Down Expand Up @@ -81,6 +82,7 @@
"first_week": "First due week (1-52)",
"start_date": "Start date",
"day_of_month": "Day of month",
"due_date_offset": "Offset each due date",
"weekday_order_number": "Order of the weekday in the month (e.g. first Wednesday of the month)",
"force_week_order_numbers": "Order of week in a month instead of order of weekday (e.g. on Wednesday of the first week)",
"date_format": "Date format (see http://strftime.org/)"
Expand Down

0 comments on commit 2e96040

Please sign in to comment.