Fix bug in the recurring flexible date

This commit is contained in:
Howard Abrams 2026-09-04 14:47:27 -07:00
parent 1675ba6455
commit 0b0b67e473
4 changed files with 25 additions and 12 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
.mise.local.toml .mise.local.toml
.latest-run.txt .latest-run.txt
.latest-gitrun.txt .latest-gitrun.txt
.env.sh

View file

@ -1,2 +1,5 @@
[tools] [tools]
python = { version = "3.12", venv = ".venv" } python = "3.12"
[env]
_.python.venv = { path = ".venv", create = true }

View file

@ -1,12 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python
import calendar import calendar
import datetime
import os import os
import requests import requests
import yaml import yaml
from datetime import datetime, date, time, timedelta
from dateutil.relativedelta import relativedelta, TH, FR, SA, SU, MO, TU, WE from dateutil.relativedelta import relativedelta, TH, FR, SA, SU, MO, TU, WE
from dateutil.rrule import rrulestr
from recurrent.event_parser import RecurringEvent from recurrent.event_parser import RecurringEvent
# --- Configuration --- # --- Configuration ---
@ -52,11 +53,11 @@ def priorty(s):
def is_task_due_today(task_def, check_date=None): def is_task_due_today(task_def, check_date=None):
"""Evaluates if a YAML task definition is due on check_date (defaults to today).""" """Evaluates if a YAML task definition is due on check_date (defaults to today)."""
if check_date is None: if check_date is None:
check_date = datetime.date.today() check_date = date.today()
rec = task_def.get("recurrence", {}) rec = task_def.get("recurrence", {})
rec_type = rec.get("type") rec_type = rec.get("type")
# print(f"Analyzing {rec}") print(f"Analyzing {rec}")
if not rec_type: if not rec_type:
return False return False
@ -85,18 +86,26 @@ def is_task_due_today(task_def, check_date=None):
interval = rec.get("interval", 2) interval = rec.get("interval", 2)
start_str = rec.get("start") start_str = rec.get("start")
# anchor = ( # anchor = (
# datetime.date.fromisoformat(start_str) # date.fromisoformat(start_str)
# if start_str # if start_str
# else datetime.date(2000, 1, 1) # fixed default epoch # else date(2000, 1, 1) # fixed default epoch
# ) # )
# delta = (check_date - anchor).days # delta = (check_date - anchor).days
delta = (check_date - start_str).days delta = (check_date - start_str).days
return delta >= 0 and delta % interval == 0 return delta >= 0 and delta % interval == 0
elif rec_type.startswith("flex"): elif rec_type.startswith("flex"):
r = RecurringEvent() event_parser = RecurringEvent()
target_date = r.parse(rec.get("day")) rule_date = event_parser.parse(rec.get("day"))
return check_date == target_date.date() rule_str = event_parser.get_RFC_rrule()
if rule_str:
rule = rrulestr(rule_str)
# Define the start and end bounds for today's date
today_start = datetime.combine(date.today(), time.min)
today_end = today_start + timedelta(days=1)
# Check if today's window contains a rule occurrence
return len(rule.between(today_start, today_end, inc=True)) > 0
return False return False
@ -144,7 +153,7 @@ def create_habitica_task(task_def):
# --- Main Logic --- # --- Main Logic ---
def sync_tasks(): def sync_tasks():
today = datetime.date.today() today = date.today()
print(f"=== Syncing Habitica Tasks for {today} ===") print(f"=== Syncing Habitica Tasks for {today} ===")
# 1. Load YAML rules # 1. Load YAML rules

View file

@ -140,7 +140,7 @@ tasks:
• Deez nuts • Deez nuts
recurrence: recurrence:
type: flex type: flex
day: Friday day: Every Friday
- text: Play a Puzzle Game - text: Play a Puzzle Game
notes: | notes: |
@ -149,4 +149,4 @@ tasks:
• Bordergrams • Bordergrams
recurrence: recurrence:
type: flex type: flex
day: Saturday day: Every Saturday