MCPcopy Create free account
hub / github.com/alecthomas/devtodo2 / Less

Method Less

view.go:61–100  ·  view source on GitHub ↗
(i, j int)

Source from the content-addressed store, hash-verified

59}
60
61func (t *TaskView) Less(i, j int) bool {
62 left := t.tasks[i]
63 right := t.tasks[j]
64 less := false
65 switch t.options.Order {
66 case INDEX:
67 less = left.ID() < right.ID()
68 case CREATED:
69 less = left.CreationTime().Unix() < right.CreationTime().Unix()
70 case COMPLETED:
71 less = left.CompletionTime().Unix() < right.CompletionTime().Unix()
72 case TEXT:
73 less = left.Text() < right.Text()
74 case PRIORITY:
75 less = left.Priority() < right.Priority()
76 case DURATION:
77 var leftDuration, rightDuration int64
78 leftCompletion := left.CompletionTime()
79 rightCompletion := right.CompletionTime()
80 if !leftCompletion.IsZero() {
81 leftDuration = leftCompletion.Unix() - left.CreationTime().Unix()
82 } else {
83 leftDuration = 0
84 }
85 if !rightCompletion.IsZero() {
86 rightDuration = rightCompletion.Unix() - right.CreationTime().Unix()
87 } else {
88 rightDuration = 0
89 }
90 less = leftDuration < rightDuration
91 case DONE:
92 less = !left.CompletionTime().IsZero() && !right.CompletionTime().IsZero()
93 default:
94 panic("invalid ordering")
95 }
96 if t.options.Reversed {
97 less = !less
98 }
99 return less
100}
101
102func (t *TaskView) Swap(i, j int) {
103 t.tasks[j], t.tasks[i] = t.tasks[i], t.tasks[j]

Callers

nothing calls this directly

Calls 5

IDMethod · 0.65
CreationTimeMethod · 0.65
CompletionTimeMethod · 0.65
TextMethod · 0.65
PriorityMethod · 0.65

Tested by

no test coverage detected