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

Commit

Permalink
Parses free form 'tomorrow' Issue #77
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed May 1, 2019
1 parent 86d2040 commit e695021
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions server/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@
"id": "minute",
"translation": "minute"
},
{
"id": "mins",
"translation": "mins"
},
{
"id": "min",
"translation": "min"
Expand Down
17 changes: 11 additions & 6 deletions server/occurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func (p *Plugin) inEN(when string, user *model.User) (times []time.Time, err err

case T("minutes"),
T("minute"),
T("mins"),
T("min"):

i, e := strconv.Atoi(value)
Expand Down Expand Up @@ -1046,18 +1047,22 @@ func (p *Plugin) freeFormEN(when string, user *model.User) (times []time.Time, e

whenTrim := strings.Trim(when, " ")
chronoUnit := strings.ToLower(whenTrim)
dateTimeSplit := strings.Split(chronoUnit, " "+T("at")+" ")
chronoTime := "9:00AM"
chronoDate := dateTimeSplit[0]
chronoDate := chronoUnit

if len(dateTimeSplit) > 1 {
chronoTime = dateTimeSplit[1]
if strings.Contains(chronoUnit, T("at")) {
dateTimeSplit := strings.Split(chronoUnit, " "+T("at")+" ")
chronoDate = dateTimeSplit[0]
if len(dateTimeSplit) > 1 {
chronoTime = dateTimeSplit[1]
}
} else {
_, ntErr := p.normalizeTime(dateTimeSplit[0], user)
_, ntErr := p.normalizeTime(chronoDate, user)
if ntErr == nil {
return p.at(T("at")+" "+dateTimeSplit[0], user)
return p.at(T("at")+" "+chronoDate, user)
}
}

dateUnit, ndErr := p.normalizeDate(chronoDate, user)
if ndErr != nil {
return []time.Time{}, ndErr
Expand Down
2 changes: 1 addition & 1 deletion server/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (p *Plugin) ParseRequest(request *ReminderRequest) error {
return wErr
}

toIndex := strings.Index(request.Reminder.When, T("to"))
toIndex := strings.Index(request.Reminder.When, T("to")+" ")
if toIndex > -1 {
request.Reminder.When = request.Reminder.When[0:toIndex]
}
Expand Down

0 comments on commit e695021

Please sign in to comment.