1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# [FEATURE] Reorder task list by urgency
## Description
List past due tasks, then tasks with a specific time today, then 12am (all-day) tasks today, then future tasks.
## User Story
As a user, I want tasks sorted by urgency tiers so I see what needs attention first.
## Technical Context
- Affects: `internal/handlers/handlers.go` — sorting logic before template render
- Requires distinguishing "has specific time" vs "all-day" (midnight/00:00)
- Todoist API may return all-day tasks with time set to 00:00:00
## Test Strategy
### Unit Test (Red)
**File:** `internal/handlers/handlers_test.go`
```go
func TestSortTasksByUrgency(t *testing.T) {
tasks := []Task{
{Name: "future", DueDate: tomorrow},
{Name: "overdue", DueDate: yesterday},
{Name: "today-timed", DueDate: todayAt(14, 30)},
{Name: "today-allday", DueDate: todayAt(0, 0)},
}
sorted := SortTasksByUrgency(tasks)
// Expected order: overdue, today-timed, today-allday, future
assert.Equal(t, "overdue", sorted[0].Name)
assert.Equal(t, "today-timed", sorted[1].Name)
assert.Equal(t, "today-allday", sorted[2].Name)
assert.Equal(t, "future", sorted[3].Name)
}
```
## Proposed Approach
1. Define sort buckets with priority:
- Priority 0: Overdue (due_date < today)
- Priority 1: Today with specific time (due_date == today && time != 00:00)
- Priority 2: Today all-day (due_date == today && time == 00:00)
- Priority 3: Future (due_date > today)
2. Within each bucket, sort by due_date ascending
3. Implement stable sort to preserve original order within equal items
## Traps to Avoid
- **Timezone handling:** Ensure consistent timezone (user's local or UTC?) for date comparisons
- **Null due dates:** Decide where tasks with no due date should appear (suggest: after future tasks)
- **All-day detection:** Todoist may use different conventions; verify API response format
## Affected Components
- `internal/handlers/handlers.go`
- `internal/handlers/handlers_test.go`
## Definition of Done
- [ ] Tasks sorted in specified order
- [ ] Overdue tasks appear first
- [ ] Timed tasks today before all-day tasks today
- [ ] Future tasks appear last
- [ ] Null due date tasks handled gracefully
- [ ] Unit tests cover all buckets and edge cases
|