Skip to content

Commit 5e3ed25

Browse files
authored
Merge pull request #11 from BOTbkcd/dev
Fixed reccuring task deadline sorting bug
2 parents f3de55d + 7aedd36 commit 5e3ed25

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

tui/table_utils.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ var tableNavigationKeys = keyMap{
9191
}
9292

9393
var taskFinishStatus = map[uint]bool{}
94+
var recurDeadlines = map[uint]time.Time{}
9495

9596
func stackColumns() []table.Column {
9697
return []table.Column{
@@ -126,7 +127,7 @@ func stackRows(stacks []entities.Stack) []table.Row {
126127
func taskRows(tasks []entities.Task) []table.Row {
127128
rows := make([]table.Row, len(tasks))
128129

129-
recurDeadlines := make(map[uint]time.Time)
130+
// We perform this step earlier since we need the deadline & finish status data before sorting
130131
for _, val := range tasks {
131132
if val.IsRecurring {
132133
r, count := val.LatestRecurTask()
@@ -187,22 +188,36 @@ func sortTasks(t *[]entities.Task) {
187188
//Sort by finish status, then deadline, then priority, then title
188189
sort.Slice(*t, func(i, j int) bool {
189190
if taskFinishStatus[(*t)[i].ID] == taskFinishStatus[(*t)[j].ID] {
190-
if (*t)[i].Deadline.Equal((*t)[j].Deadline) {
191+
var deadline_i time.Time
192+
if (*t)[i].IsRecurring {
193+
deadline_i = recurDeadlines[(*t)[i].ID]
194+
} else {
195+
deadline_i = (*t)[i].Deadline
196+
}
197+
198+
var deadline_j time.Time
199+
if (*t)[j].IsRecurring {
200+
deadline_j = recurDeadlines[(*t)[j].ID]
201+
} else {
202+
deadline_j = (*t)[j].Deadline
203+
}
204+
205+
if deadline_i.Equal(deadline_j) {
191206
if (*t)[i].Priority == (*t)[j].Priority {
192207
return strings.ToLower((*t)[i].Title) < strings.ToLower((*t)[j].Title)
193208
}
194209
return (*t)[i].Priority > (*t)[j].Priority
195210
}
196211

197-
if (*t)[i].Deadline.IsZero() {
212+
if deadline_i.IsZero() {
198213
return false
199214
}
200215

201-
if (*t)[j].Deadline.IsZero() {
216+
if deadline_j.IsZero() {
202217
return true
203218
}
204219

205-
return (*t)[i].Deadline.Before((*t)[j].Deadline)
220+
return deadline_i.Before(deadline_j)
206221
} else {
207222
return !taskFinishStatus[(*t)[i].ID]
208223
}

0 commit comments

Comments
 (0)