Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

handle missing 'at' for freeform day time #131

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions server/occurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions server/occurrence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down