Get most recent timer
This commit is contained in:
parent
b9dd8302dc
commit
d35b67037e
23
timerlist.go
23
timerlist.go
@ -19,6 +19,29 @@ func NewTimerList() *TimerList {
|
|||||||
return &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 {
|
func (timerlist *TimerList) GetTimersInRange(start, end time.Time) *TimerList {
|
||||||
fltr := func(t Timer) bool {
|
fltr := func(t Timer) bool {
|
||||||
if t.StartDate.Before(end) && t.StartDate.After(start) {
|
if t.StartDate.Before(end) && t.StartDate.After(start) {
|
||||||
|
Loading…
Reference in New Issue
Block a user