dates: a bare hour after a day word is an hour, not the current clock (V-551)

At 21:12 "напомни мне завтра в семь позвонить маме" confirmed a reminder for
21:12 tomorrow. The hour was dropped and the wall clock carried onto the named
day. She did not ask; she named a time nobody gave her, on a path that fires.
A bare "напомни в семь" declines correctly, so adding "завтра" turned a decline
into an invented answer.

dateparser only reads a bare hour when it carries a qualifier or a colon.
"завтра в 7" keeps the current clock and "завтра в 7 часов" is read as seven
hours from now, which moves the day as well. English "at 7" fails identically,
so this is not a Russian defect and both prepositions are rewritten.

The script now gives it the colon: "в 7", "в 7 часов" and "at 7" become
"в 07:00" beside the existing утра/вечера rewrites. A duration is untouched,
because "через 2 часа" has no preposition to match, and so are "в 7:30",
"в 30 минут" and "в 2026 году".

The stub parser has always read the token after the day word, so the floor was
right and the production parser was not. No test on the stub could have caught
this. The four new cases are in TestPythonDateParser, which runs where
dateparser is installed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SoL7EBdYC5Mhz3DJd49GJy
This commit is contained in:
2026-08-05 21:17:21 +04:00
parent 337a777d2e
commit 44320ee496
2 changed files with 54 additions and 0 deletions
+7
View File
@@ -49,6 +49,13 @@ try:
text = re.sub(r'(\d+)\s+(?:час(?:а|ов)?\s+)?вечера\b', r'\1 pm', text, flags=re.IGNORECASE)
text = re.sub(r'(\d+)\s+(?:час(?:а|ов)?\s+)?дня\b', r'\1 pm', text, flags=re.IGNORECASE)
text = re.sub(r'(\d+)\s+(?:час(?:а|ов)?\s+)?ночи\b', r'\1 am', text, flags=re.IGNORECASE)
# A bare hour after a preposition is dropped on the floor by dateparser:
# "завтра в 7" resolves to tomorrow at the CURRENT clock, and "завтра в 7
# часов" is read as seven hours from now. Only a qualifier (already an
# am/pm above) or a colon makes it read the hour, so give it the colon.
# English "at 7" fails identically, so both prepositions are rewritten.
text = re.sub(r'(?<![\w:])(в|во|at)\s+([01]?\d|2[0-3])(?:\s+час(?:а|ов)?)?(?![\d:.\w])',
lambda m: '%s %02d:00' % (m.group(1), int(m.group(2))), text, flags=re.IGNORECASE)
settings = {'PREFER_DATES_FROM': 'future', 'RELATIVE_BASE': now}
# Two-step: search_dates finds the date substring in text,
# parse() gets the time right (search_dates mishandles AM/PM).
+47
View File
@@ -103,6 +103,53 @@ func TestPythonDateParser(t *testing.T) {
}
},
},
// A bare hour after a day word used to be dropped, and the current
// clock carried onto that day: at 21:12 "завтра в семь" confirmed a
// reminder for 21:12 tomorrow (Vikunja #551). She invented a time
// instead of asking, on a path that then fires.
{
name: "ru bare hour — завтра в семь",
text: "напомни мне завтра в семь позвонить маме",
wantOK: true,
checkT: func(t *testing.T, got, now time.Time) {
if got.Hour() != 7 || got.Minute() != 0 {
t.Errorf("завтра в семь: %02d:%02d, want 07:00", got.Hour(), got.Minute())
}
},
},
{
// "7 часов" was read as seven hours from now, which also moved the day.
name: "ru bare hour — завтра в 7 часов",
text: "напомни завтра в 7 часов позвонить",
wantOK: true,
checkT: func(t *testing.T, got, now time.Time) {
if got.Hour() != 7 || got.Minute() != 0 {
t.Errorf("завтра в 7 часов: %02d:%02d, want 07:00", got.Hour(), got.Minute())
}
},
},
{
name: "en bare hour — tomorrow at 7",
text: "remind me tomorrow at 7 to call mum",
wantOK: true,
checkT: func(t *testing.T, got, now time.Time) {
if got.Hour() != 7 || got.Minute() != 0 {
t.Errorf("tomorrow at 7: %02d:%02d, want 07:00", got.Hour(), got.Minute())
}
},
},
{
// The rewrite must not touch a duration: "через 2 часа" is not "в 2".
name: "ru duration is untouched — через 2 часа",
text: "напомни через 2 часа выпить воды",
wantOK: true,
checkT: func(t *testing.T, got, now time.Time) {
d := got.Sub(now)
if d < 110*time.Minute || d > 130*time.Minute {
t.Errorf("через 2 часа: got %v from now, want ~2h", d)
}
},
},
{
name: "no date — напомни мне",
text: "напомни мне",