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

Fix occurence calculation #193

Merged
merged 1 commit into from
Mar 5, 2021
Merged
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
30 changes: 26 additions & 4 deletions server/occurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ func (p *Plugin) at(when string, user *model.User) (times []time.Time, err error
}

func (p *Plugin) atEN(when string, user *model.User) (times []time.Time, err error) {

T, _ := p.translation(user)
location := p.location(user)

Expand Down Expand Up @@ -607,12 +606,20 @@ func (p *Plugin) atEN(when string, user *model.User) (times []time.Time, err err
}
}
t, pErr := time.ParseInLocation(time.Kitchen, normalizedWhen+strings.ToUpper(whenSplit[2]), location)

if pErr != nil {
p.API.LogError(fmt.Sprintf("%v", pErr))
}

now := time.Now().In(location).Round(time.Hour * time.Duration(24))
occurrence := t.AddDate(now.Year(), int(now.Month())-1, now.Day()-1)

var occurrence time.Time
if now.Day() > time.Now().Day() {
occurrence = t.AddDate(now.Year(), int(now.Month())-1, now.Day()-2)
} else {
occurrence = t.AddDate(now.Year(), int(now.Month())-1, now.Day()-1)
}

return []time.Time{p.chooseClosest(user, &occurrence, true).UTC()}, nil

} else if strings.HasSuffix(normalizedWhen, T("pm")) ||
Expand Down Expand Up @@ -640,12 +647,20 @@ func (p *Plugin) atEN(when string, user *model.User) (times []time.Time, err err

}
t, pErr := time.ParseInLocation(time.Kitchen, strings.ToUpper(normalizedWhen), location)

if pErr != nil {
p.API.LogError(fmt.Sprintf("%v", pErr))
}

now := time.Now().In(location).Round(time.Hour * time.Duration(24))
occurrence := t.AddDate(now.Year(), int(now.Month())-1, now.Day()-1)

var occurrence time.Time
if now.Day() > time.Now().Day() {
occurrence = t.AddDate(now.Year(), int(now.Month())-1, now.Day()-2)
} else {
occurrence = t.AddDate(now.Year(), int(now.Month())-1, now.Day()-1)
}

return []time.Time{p.chooseClosest(user, &occurrence, true).UTC()}, nil

}
Expand Down Expand Up @@ -759,7 +774,14 @@ func (p *Plugin) atEN(when string, user *model.User) (times []time.Time, err err
}

now := time.Now().In(location).Round(time.Hour * time.Duration(24))
occurrence := t.In(location).AddDate(now.Year(), int(now.Month())-1, now.Day()-1)

var occurrence time.Time
if now.Day() > time.Now().Day() {
occurrence = t.AddDate(now.Year(), int(now.Month())-1, now.Day()-2)
} else {
occurrence = t.AddDate(now.Year(), int(now.Month())-1, now.Day()-1)
}

return []time.Time{p.chooseClosest(user, &occurrence, dayInterval).UTC()}, nil

}
Expand Down