Get most recent timer

This commit is contained in:
Brian Buller 2021-03-02 11:06:37 -06:00
parent b9dd8302dc
commit d35b67037e

View File

@ -19,6 +19,29 @@ func NewTimerList() *TimerList {
return &TimerList{}
}
func (timerlist *TimerList) GetMostRecentTimer() (*Timer, error) {
var found *Timer
var latest time.Time
for i := range *timerlist {
t := &([]Timer(*timerlist))[i]
if t.FinishDate.IsZero() {
if t.StartDate.After(latest) {
found = t
latest = t.StartDate
}
} else {
if t.FinishDate.After(latest) {
latest = t.FinishDate
found = t
}
}
}
if found == nil {
return nil, errors.New("No timer found")
}
return found, nil
}
func (timerlist *TimerList) GetTimersInRange(start, end time.Time) *TimerList {
fltr := func(t Timer) bool {
if t.StartDate.Before(end) && t.StartDate.After(start) {