a clock already past rolls to its next occurrence (V-544)
At 14:41 "напомни в половине первого пообедать" was set for 12:30 the same day, two hours gone, and confirmed as "напомню сегодня в 12:30". dateparser is handed PREFER_DATES_FROM future and does not apply it to an HH:MM time on today's date. parseClock in the stub has always rolled forward, so the two parsers disagreed and the production one was the wrong half. rollPastClockForward runs on the python result. Only a bare clock rolls: a sentence naming its day keeps it, so a deliberate "сегодня в 12:30" stays where he put it, and past by a day or more is not a clock resolved onto today. NamesADay reads weekdays by lemma, the relative day words and the month names, all from the lexicon. Measured against real dateparser in a venv: "в половине первого" 05 Aug 12:30 to 06 Aug 12:30, "в 12:30" the same, "сегодня в 12:30" unchanged, and the relative and named-day cases unchanged. Left open: a reminder he places in the past is still accepted silently. Saying the hour has gone is a phrasing gap, not this fix.
This commit is contained in:
@@ -91,9 +91,32 @@ func (p *PythonDateParser) Parse(ctx context.Context, text string, now time.Time
|
||||
log.Printf("router: python dateparser unavailable, falling back to stub: %v", err)
|
||||
return p.fallback.Parse(ctx, text, now)
|
||||
}
|
||||
if ok {
|
||||
t = rollPastClockForward(t, now, text)
|
||||
}
|
||||
return t, ok, nil
|
||||
}
|
||||
|
||||
// rollPastClockForward moves a clock that has already gone by to its next
|
||||
// occurrence.
|
||||
//
|
||||
// dateparser is handed PREFER_DATES_FROM future and does not apply it to an
|
||||
// HH:MM time on today's date, so at 14:41 "напомни в половине первого пообедать"
|
||||
// resolved to 12:30 the same day and the reminder was two hours in the past
|
||||
// (V-544). parseClock in the stub has always rolled forward, so this is the
|
||||
// production parser agreeing with the floor rather than a new rule.
|
||||
//
|
||||
// Only a bare clock rolls. A sentence that names its day keeps it, so a
|
||||
// deliberate "сегодня в 12:30" stays where he put it, and the backdated write
|
||||
// path (V-518) is a different seam entirely. Past by a day or more is not a
|
||||
// clock resolved onto today, so it is left alone too.
|
||||
func rollPastClockForward(t, now time.Time, text string) time.Time {
|
||||
if t.After(now) || now.Sub(t) >= 24*time.Hour || NamesADay(text) {
|
||||
return t
|
||||
}
|
||||
return t.Add(24 * time.Hour)
|
||||
}
|
||||
|
||||
// parseWithPython runs the dateparser script and parses the timestamp output.
|
||||
// Returns (zero, false, error) on process/exec failure; (zero, false, nil)
|
||||
// when the script ran but found no date.
|
||||
|
||||
Reference in New Issue
Block a user