Fix bug in the recurring flexible date
This commit is contained in:
parent
1675ba6455
commit
0b0b67e473
4 changed files with 25 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
|||
.mise.local.toml
|
||||
.latest-run.txt
|
||||
.latest-gitrun.txt
|
||||
.env.sh
|
||||
|
|
|
|||
|
|
@ -1,2 +1,5 @@
|
|||
[tools]
|
||||
python = { version = "3.12", venv = ".venv" }
|
||||
python = "3.12"
|
||||
|
||||
[env]
|
||||
_.python.venv = { path = ".venv", create = true }
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import calendar
|
||||
import datetime
|
||||
import os
|
||||
import requests
|
||||
import yaml
|
||||
|
||||
from datetime import datetime, date, time, timedelta
|
||||
from dateutil.relativedelta import relativedelta, TH, FR, SA, SU, MO, TU, WE
|
||||
from dateutil.rrule import rrulestr
|
||||
from recurrent.event_parser import RecurringEvent
|
||||
|
||||
# --- Configuration ---
|
||||
|
|
@ -52,11 +53,11 @@ def priorty(s):
|
|||
def is_task_due_today(task_def, check_date=None):
|
||||
"""Evaluates if a YAML task definition is due on check_date (defaults to today)."""
|
||||
if check_date is None:
|
||||
check_date = datetime.date.today()
|
||||
check_date = date.today()
|
||||
|
||||
rec = task_def.get("recurrence", {})
|
||||
rec_type = rec.get("type")
|
||||
# print(f"Analyzing {rec}")
|
||||
print(f"Analyzing {rec}")
|
||||
|
||||
if not rec_type:
|
||||
return False
|
||||
|
|
@ -85,18 +86,26 @@ def is_task_due_today(task_def, check_date=None):
|
|||
interval = rec.get("interval", 2)
|
||||
start_str = rec.get("start")
|
||||
# anchor = (
|
||||
# datetime.date.fromisoformat(start_str)
|
||||
# date.fromisoformat(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 - start_str).days
|
||||
return delta >= 0 and delta % interval == 0
|
||||
|
||||
elif rec_type.startswith("flex"):
|
||||
r = RecurringEvent()
|
||||
target_date = r.parse(rec.get("day"))
|
||||
return check_date == target_date.date()
|
||||
event_parser = RecurringEvent()
|
||||
rule_date = event_parser.parse(rec.get("day"))
|
||||
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
|
||||
|
||||
|
|
@ -144,7 +153,7 @@ def create_habitica_task(task_def):
|
|||
|
||||
# --- Main Logic ---
|
||||
def sync_tasks():
|
||||
today = datetime.date.today()
|
||||
today = date.today()
|
||||
print(f"=== Syncing Habitica Tasks for {today} ===")
|
||||
|
||||
# 1. Load YAML rules
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ tasks:
|
|||
• Deez nuts
|
||||
recurrence:
|
||||
type: flex
|
||||
day: Friday
|
||||
day: Every Friday
|
||||
|
||||
- text: Play a Puzzle Game
|
||||
notes: |
|
||||
|
|
@ -149,4 +149,4 @@ tasks:
|
|||
• Bordergrams
|
||||
recurrence:
|
||||
type: flex
|
||||
day: Saturday
|
||||
day: Every Saturday
|
||||
|
|
|
|||
Loading…
Reference in a new issue