Change Sort Constants
This commit is contained in:
parent
c62767a5ef
commit
b3e09780fb
24
sort.go
24
sort.go
@ -8,23 +8,23 @@ import (
|
||||
|
||||
// Flags for defining sort element and order.
|
||||
const (
|
||||
SORT_UNFINISHED_START = iota
|
||||
SORT_START_DATE_ASC
|
||||
SORT_START_DATE_DESC
|
||||
SORT_FINISH_DATE_ASC
|
||||
SORT_FINISH_DATE_DESC
|
||||
SORT_ERROR
|
||||
SortUnfinishedStart = iota
|
||||
SortStartDateAsc
|
||||
SortStartDateDesc
|
||||
SortFinishDateAsc
|
||||
SortFinishDateDesc
|
||||
SortError
|
||||
)
|
||||
|
||||
// Sort allows a TimerList to be sorted by certain predefined fields.
|
||||
// See constants SORT_* for fields and sort order.
|
||||
// See constants Sort* for fields and sort order.
|
||||
func (timerlist *TimerList) Sort(sortFlag int) error {
|
||||
switch sortFlag {
|
||||
case SORT_UNFINISHED_START:
|
||||
case SortUnfinishedStart:
|
||||
timerlist.sortByUnfinishedThenStart()
|
||||
case SORT_START_DATE_ASC, SORT_START_DATE_DESC:
|
||||
case SortStartDateAsc, SortStartDateDesc:
|
||||
timerlist.sortByStartDate(sortFlag)
|
||||
case SORT_FINISH_DATE_ASC, SORT_FINISH_DATE_DESC:
|
||||
case SortFinishDateAsc, SortFinishDateDesc:
|
||||
timerlist.sortByFinishDate(sortFlag)
|
||||
default:
|
||||
return errors.New("Unrecognized sort option")
|
||||
@ -81,14 +81,14 @@ func sortByDate(asc bool, date1, date2 time.Time) bool {
|
||||
|
||||
func (timerlist *TimerList) sortByStartDate(order int) *TimerList {
|
||||
timerlist.sortBy(func(t1, t2 *Timer) bool {
|
||||
return sortByDate(order == SORT_START_DATE_ASC, t1.StartDate, t2.StartDate)
|
||||
return sortByDate(order == SortStartDateAsc, t1.StartDate, t2.StartDate)
|
||||
})
|
||||
return timerlist
|
||||
}
|
||||
|
||||
func (timerlist *TimerList) sortByFinishDate(order int) *TimerList {
|
||||
timerlist.sortBy(func(t1, t2 *Timer) bool {
|
||||
return sortByDate(order == SORT_FINISH_DATE_ASC, t1.FinishDate, t2.FinishDate)
|
||||
return sortByDate(order == SortFinishDateAsc, t1.FinishDate, t2.FinishDate)
|
||||
})
|
||||
return timerlist
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// TimerList represents a list of timer.txt timer entries.
|
||||
// It is usually loasded from a whole timer.txt file.
|
||||
// It is usually loaded from a whole timer.txt file.
|
||||
type TimerList struct {
|
||||
timers []*Timer
|
||||
sortFlag int
|
||||
@ -202,7 +202,7 @@ func (timerlist *TimerList) AddTimer(timer *Timer) {
|
||||
// AddTimers adds all passed in timers to the list, sorts the list, then updates the Timer.Id values.
|
||||
func (timerlist *TimerList) AddTimers(timers []*Timer) {
|
||||
timerlist.timers = append(timerlist.timers, timers...)
|
||||
timerlist.Sort(SORT_START_DATE_ASC)
|
||||
timerlist.Sort(SortStartDateAsc)
|
||||
}
|
||||
func (timerlist *TimerList) Combine(other *TimerList) { timerlist.AddTimers(other.timers) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user