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

Commit

Permalink
Fix occurence calculation (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKitAs authored Mar 5, 2021
1 parent 2ca3878 commit 39d6b97
Showing 1 changed file with 26 additions and 4 deletions.
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

0 comments on commit 39d6b97

Please sign in to comment.