Some Changes
This commit is contained in:
parent
6060aa5d4a
commit
c62767a5ef
34
timerlist.go
34
timerlist.go
@ -23,6 +23,40 @@ func NewTimerList() *TimerList { return &TimerList{} }
|
||||
func (timerlist *TimerList) Size() int { return len(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) {
|
||||
var found *Timer
|
||||
var latest time.Time
|
||||
|
Loading…
Reference in New Issue
Block a user