calendar: fix _days_until to handle Unix timestamps from todoman --porcelain

This commit is contained in:
Yanxin Lu
2026-03-22 15:50:43 -07:00
parent cf8158c7cc
commit 912bcf53bd

View File

@@ -413,15 +413,23 @@ def _todoman_list_json(*extra_args):
return json.loads(result.stdout) return json.loads(result.stdout)
def _days_until(due_str): def _days_until(due_val):
"""Days from today until due date string. Negative means overdue.""" """Days from today until due date (string or Unix timestamp). Negative means overdue."""
if not due_str: if not due_val:
return None return None
# Unix timestamp (int/float) from todoman --porcelain
if isinstance(due_val, (int, float)):
try:
due_date = datetime.fromtimestamp(due_val, tz=timezone.utc).date()
except (ValueError, TypeError, OSError):
return None
return (due_date - date.today()).days
# String formats (ISO or YYYY-MM-DD)
try: try:
due_date = datetime.fromisoformat(due_str).date() due_date = datetime.fromisoformat(due_val).date()
except (ValueError, TypeError): except (ValueError, TypeError):
try: try:
due_date = _parse_date(due_str) due_date = _parse_date(due_val)
except ValueError: except ValueError:
return None return None
return (due_date - date.today()).days return (due_date - date.today()).days