Some Changes

This commit is contained in:
Brian Buller 2023-08-03 16:02:43 -05:00
parent 6060aa5d4a
commit c62767a5ef

View File

@ -23,6 +23,40 @@ func NewTimerList() *TimerList { return &TimerList{} }
func (timerlist *TimerList) Size() int { return len(timerlist.timers) } func (timerlist *TimerList) Size() int { return len(timerlist.timers) }
func (timerlist *TimerList) GetTimerSlice() []*Timer { return timerlist.timers } func (timerlist *TimerList) GetTimerSlice() []*Timer { return timerlist.timers }
func (timerlist *TimerList) Contains(t *Timer) bool {
for _, tmr := range timerlist.timers {
if tmr == t {
return true
}
}
return false
}
func (timerlist *TimerList) GetActiveOrMostRecent() (*Timer, error) {
var found *Timer
var latest time.Time
activeTimers := timerlist.Filter(func(t *Timer) bool { return !t.Finished })
if len(activeTimers.timers) > 0 {
return activeTimers.GetMostRecentTimer()
}
for _, t := range timerlist.timers {
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) GetMostRecentTimer() (*Timer, error) { func (timerlist *TimerList) GetMostRecentTimer() (*Timer, error) {
var found *Timer var found *Timer
var latest time.Time var latest time.Time