From 3dee5e19dd0ce38503fcbfa4dd1954286f104fe7 Mon Sep 17 00:00:00 2001 From: scott lee davis Date: Thu, 27 Jun 2019 23:32:51 -0400 Subject: [PATCH] handle missing 'at' for freeform day time (#131) --- server/occurrence.go | 12 +++++++++--- server/occurrence_test.go | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/server/occurrence.go b/server/occurrence.go index 6316d81..7c75e08 100755 --- a/server/occurrence.go +++ b/server/occurrence.go @@ -1104,9 +1104,15 @@ func (p *Plugin) freeFormEN(when string, user *model.User) (times []time.Time, e chronoTime = dateTimeSplit[1] } } else { - _, ntErr := p.normalizeTime(chronoDate, user) - if ntErr == nil { - return p.at(T("at")+" "+chronoDate, user) + dateTimeSplit := strings.Split(chronoDate, " ") + if len(dateTimeSplit) == 2 { + chronoDate = dateTimeSplit[0] + chronoTime = dateTimeSplit[1] + } else { + _, ntErr := p.normalizeTime(chronoDate, user) + if ntErr == nil { + return p.at(T("at")+" "+chronoDate, user) + } } } diff --git a/server/occurrence_test.go b/server/occurrence_test.go index 7fabf5c..fc0d2ee 100755 --- a/server/occurrence_test.go +++ b/server/occurrence_test.go @@ -686,6 +686,13 @@ func TestFreeForm(t *testing.T) { times[0].In(location).Hour() == 16) } + times, err = p.freeFormEN("tomorrow 8:00", user) + assert.Nil(t, err) + if err == nil { + assert.True(t, times[0].In(location).Weekday().String() == time.Now().In(location).AddDate(0, 0, 1).Weekday().String() && + (times[0].In(location).Hour() == 8 || times[0].In(location).Hour() == 20)) + } + times, err = p.freeFormEN("everyday", user) assert.Nil(t, err) if err == nil {