diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-23 00:42:44 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-23 00:42:44 +0000 |
| commit | 6c767194d9470b368f8d337e0719795f235f683c (patch) | |
| tree | 9ffbef1dfa45add88a821877a2e6c8ceb94f52f8 /internal/api/todoist_test.go | |
| parent | 8abc63efdbc0bb96cd6c9aa99d6e9166e0bcabae (diff) | |
fix: parse Todoist local datetimes, show near-future tasks, add undated tasks to timeline
- parseDueDate: handle date field containing "YYYY-MM-DDTHH:MM:SS" (local time,
no tz offset) — Todoist REST API v1 uses this format for recurring tasks with
a set time, causing due dates to silently parse as nil
- IsFuture threshold: widen from tomorrow to 7 days out so tasks due this week
show in the main tasks section with dates visible (not collapsed)
- BuildTimeline: include undated Todoist tasks in the Today section (mirrors
existing Google Tasks behavior)
- GetUndatedTasks: new store method for tasks with due_date IS NULL
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/api/todoist_test.go')
| -rw-r--r-- | internal/api/todoist_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/api/todoist_test.go b/internal/api/todoist_test.go index 99b9e80..d2c8da5 100644 --- a/internal/api/todoist_test.go +++ b/internal/api/todoist_test.go @@ -142,6 +142,53 @@ func TestTodoistClient_CreateTask_WithDueDate(t *testing.T) { } } +func TestParseDueDate_LocalDatetimeInDateField(t *testing.T) { + // Todoist REST API v1 puts local datetime (no tz offset) in the "date" field + // when datetime is not in UTC (e.g. recurring tasks with a set time) + // e.g. due={date="2026-03-22T19:00:00" datetime="" is_recurring=true} + due := &dueInfo{ + Date: "2026-03-22T19:00:00", + Datetime: "", + IsRecurring: true, + } + result := parseDueDate(due) + if result == nil { + t.Fatal("parseDueDate returned nil for date field containing local datetime — must parse YYYY-MM-DDTHH:MM:SS format") + } + if result.Hour() != 19 || result.Minute() != 0 { + t.Errorf("Expected 19:00, got %02d:%02d", result.Hour(), result.Minute()) + } +} + +func TestParseDueDate_MicrosecondDatetime(t *testing.T) { + // Todoist REST API v1 returns datetime with microseconds: "2023-01-15T10:00:00.000000Z" + // time.RFC3339 cannot parse fractional seconds — parseDueDate must use RFC3339Nano + due := &dueInfo{ + Date: "2023-01-15", + Datetime: "2023-01-15T10:00:00.000000Z", + IsRecurring: true, + } + result := parseDueDate(due) + if result == nil { + t.Fatal("parseDueDate returned nil for datetime with microseconds — RFC3339Nano required") + } + if result.Hour() != 10 || result.Minute() != 0 { + t.Errorf("Expected 10:00, got %02d:%02d", result.Hour(), result.Minute()) + } +} + +func TestParseDueDate_RFC3339Datetime(t *testing.T) { + // Standard RFC3339 without fractional seconds should also work + due := &dueInfo{ + Date: "2023-01-15", + Datetime: "2023-01-15T10:00:00Z", + } + result := parseDueDate(due) + if result == nil { + t.Fatal("parseDueDate returned nil for standard RFC3339 datetime") + } +} + func TestTodoistClient_UsesAPIv1BaseURL(t *testing.T) { client := NewTodoistClient("test-key") const want = "https://api.todoist.com/api/v1" |
