list sorting

This commit is contained in:
Erik Winter 2025-01-05 10:52:41 +01:00
parent 3cd40f51d1
commit 35708710f2
3 changed files with 24 additions and 6 deletions

BIN
dist/plan vendored

Binary file not shown.

View File

@ -3,6 +3,7 @@ package command
import ( import (
"fmt" "fmt"
"slices" "slices"
"sort"
"time" "time"
"go-mod.ewintr.nl/planner/item" "go-mod.ewintr.nl/planner/item"
@ -136,6 +137,25 @@ type ListResult struct {
} }
func (lr ListResult) Render() string { func (lr ListResult) Render() string {
sort.Slice(lr.Tasks, func(i, j int) bool {
if lr.Tasks[i].Task.Project < lr.Tasks[j].Task.Project {
return true
}
if lr.Tasks[i].Task.Project > lr.Tasks[j].Task.Project {
return false
}
if lr.Tasks[i].Task.Recurrer == nil && lr.Tasks[j].Task.Recurrer != nil {
return true
}
if lr.Tasks[i].Task.Recurrer != nil && lr.Tasks[j].Task.Recurrer == nil {
return false
}
if lr.Tasks[i].Task.Date.After(lr.Tasks[j].Task.Date) {
return false
}
return lr.Tasks[i].LocalID < lr.Tasks[j].LocalID
})
var showRec, showDur bool var showRec, showDur bool
for _, tl := range lr.Tasks { for _, tl := range lr.Tasks {
if tl.Task.Recurrer != nil { if tl.Task.Recurrer != nil {

View File

@ -24,12 +24,10 @@ func TestListParse(t *testing.T) {
expErr bool expErr bool
}{ }{
{ {
name: "empty", name: "empty",
main: []string{}, main: []string{},
fields: map[string]string{}, fields: map[string]string{},
expArgs: command.ListArgs{ expArgs: command.ListArgs{},
To: today,
},
}, },
{ {
name: "today", name: "today",