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:
@@ -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: "напомни мне",
|
||||
|
||||
Reference in New Issue
Block a user