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

Commit

Permalink
handle missing 'at' for freeform day time (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis authored Jun 28, 2019
1 parent c403345 commit 3dee5e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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

0 comments on commit 3dee5e1

Please sign in to comment.