Fix AutoCora last-month tag crash on 31-day months
now.replace(month=now.month-1) crashes on e.g. Mar 31 -> Feb 31. Use first-of-current-month minus one day instead, which always lands on a valid date in the previous month. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>clickup-runner
parent
abb6e1841b
commit
9de9fdb39a
|
|
@ -11,7 +11,7 @@ import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from . import tool
|
from . import tool
|
||||||
|
|
@ -117,11 +117,8 @@ def _find_qualifying_tasks_sweep(client, config, categories: list[str]):
|
||||||
|
|
||||||
# Current and last month tags (e.g. "feb26", "jan26")
|
# Current and last month tags (e.g. "feb26", "jan26")
|
||||||
current_month_tag = now.strftime("%b%y").lower()
|
current_month_tag = now.strftime("%b%y").lower()
|
||||||
# Go back one month
|
# Go back one month (use 1st-of-current-month minus 1 day to avoid day-out-of-range)
|
||||||
if now.month == 1:
|
last_month = now.replace(day=1) - timedelta(days=1)
|
||||||
last_month = now.replace(year=now.year - 1, month=12)
|
|
||||||
else:
|
|
||||||
last_month = now.replace(month=now.month - 1)
|
|
||||||
last_month_tag = last_month.strftime("%b%y").lower()
|
last_month_tag = last_month.strftime("%b%y").lower()
|
||||||
|
|
||||||
# Fetch all "to do" tasks with due dates up to lookahead
|
# Fetch all "to do" tasks with due dates up to lookahead
|
||||||
|
|
|
||||||
|
|
@ -442,13 +442,10 @@ class TestFindQualifyingTasksSweep:
|
||||||
assert any(t.id == "t2" for t in result)
|
assert any(t.id == "t2" for t in result)
|
||||||
|
|
||||||
def test_finds_last_month_tagged(self):
|
def test_finds_last_month_tagged(self):
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime, timedelta
|
||||||
|
|
||||||
now = datetime.now(UTC)
|
now = datetime.now(UTC)
|
||||||
if now.month == 1:
|
last = now.replace(day=1) - timedelta(days=1)
|
||||||
last = now.replace(year=now.year - 1, month=12)
|
|
||||||
else:
|
|
||||||
last = now.replace(month=now.month - 1)
|
|
||||||
last_tag = last.strftime("%b%y").lower()
|
last_tag = last.strftime("%b%y").lower()
|
||||||
# No due date needed for month-tag pass
|
# No due date needed for month-tag pass
|
||||||
task = FakeTask(id="t3", name="Last Month", tags=[last_tag])
|
task = FakeTask(id="t3", name="Last Month", tags=[last_tag])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue