Change Sort Constants

This commit is contained in:
2023-08-23 09:58:04 -05:00
parent c62767a5ef
commit b3e09780fb
2 changed files with 14 additions and 14 deletions

24
sort.go
View File

@@ -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
}