fix: _parse_dt does not understand 'tonight' so event start/end breaks (#1488)

This commit is contained in:
Afonso Coutinho
2026-06-03 06:14:41 +01:00
committed by GitHub
parent eb5727abda
commit 96d59d2ff9
2 changed files with 28 additions and 2 deletions

View File

@@ -338,8 +338,8 @@ def _parse_dt(s: str) -> datetime:
return None return None
return h, mn return h, mn
# today/tomorrow/yesterday [at] TIME # today/tonight/tomorrow/yesterday [at] TIME
m = _re.match(r'^(today|tomorrow|tmrw|yesterday)(?:\s+at)?\s*(.*)$', lower) m = _re.match(r'^(today|tonight|tomorrow|tmrw|yesterday)(?:\s+at)?\s*(.*)$', lower)
if m: if m:
word, rest = m.group(1), m.group(2).strip() word, rest = m.group(1), m.group(2).strip()
base = today base = today

View File

@@ -0,0 +1,26 @@
"""Regression: _parse_dt must understand "tonight" like parse_due_for_user does.
parse_due_for_user's natural-language regex accepts
`(today|tonight|tomorrow|tmrw|yesterday)`, but _parse_dt (the parser
_parse_dt_pair falls back to for calendar event start/end) only had
`(today|tomorrow|tmrw|yesterday)`. So an event start like "tonight at 9pm"
missed the today-branch and fell through to dateutil, which does not know the
word "tonight" and raises, breaking event creation for a phrasing that works
fine for reminders. "tonight" is now handled, mapped to today like the sibling.
"""
from routes.calendar_routes import _parse_dt
def test_tonight_with_time_parses_to_today_evening():
got = _parse_dt("tonight at 9pm")
ref = _parse_dt("today at 9pm")
assert got.hour == 21 and got.minute == 0
assert got.date() == ref.date()
def test_bare_tonight_is_today():
assert _parse_dt("tonight").date() == _parse_dt("today").date()
def test_tonight_matches_today_time_exactly():
assert _parse_dt("tonight at 7:30pm") == _parse_dt("today at 7:30pm")