diff --git a/timerlist.go b/timerlist.go index 637177b..7765dca 100644 --- a/timerlist.go +++ b/timerlist.go @@ -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) {