Fix timezone bug in task kanban categorization
Task creation/update responses were using UTC time for kanban column categorization, causing tasks to incorrectly appear as overdue when the server had passed midnight UTC but the user's local time was still the previous day. Changes: - Add timezone-aware response functions (NewTaskResponseWithTime, etc.) - Pass userNow from middleware to all task service methods - Update handlers to use timezone-aware time from X-Timezone header - Update tests to pass the now parameter 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -214,8 +214,20 @@ func NewTaskResponse(t *models.Task) TaskResponse {
|
||||
return NewTaskResponseWithThreshold(t, 30)
|
||||
}
|
||||
|
||||
// NewTaskResponseWithThreshold creates a TaskResponse with a custom days threshold for kanban column
|
||||
// NewTaskResponseWithThreshold creates a TaskResponse with a custom days threshold for kanban column.
|
||||
// WARNING: Uses UTC time for kanban column. Prefer NewTaskResponseWithTime for timezone-aware responses.
|
||||
func NewTaskResponseWithThreshold(t *models.Task, daysThreshold int) TaskResponse {
|
||||
return newTaskResponseInternal(t, daysThreshold, time.Now().UTC())
|
||||
}
|
||||
|
||||
// NewTaskResponseWithTime creates a TaskResponse with timezone-aware kanban column categorization.
|
||||
// The `now` parameter should be the start of day in the user's timezone.
|
||||
func NewTaskResponseWithTime(t *models.Task, daysThreshold int, now time.Time) TaskResponse {
|
||||
return newTaskResponseInternal(t, daysThreshold, now)
|
||||
}
|
||||
|
||||
// newTaskResponseInternal is the internal implementation for creating task responses
|
||||
func newTaskResponseInternal(t *models.Task, daysThreshold int, now time.Time) TaskResponse {
|
||||
resp := TaskResponse{
|
||||
ID: t.ID,
|
||||
ResidenceID: t.ResidenceID,
|
||||
@@ -236,7 +248,7 @@ func NewTaskResponseWithThreshold(t *models.Task, daysThreshold int) TaskRespons
|
||||
IsArchived: t.IsArchived,
|
||||
ParentTaskID: t.ParentTaskID,
|
||||
CompletionCount: predicates.GetCompletionCount(t),
|
||||
KanbanColumn: DetermineKanbanColumn(t, daysThreshold),
|
||||
KanbanColumn: DetermineKanbanColumnWithTime(t, daysThreshold, now),
|
||||
CreatedAt: t.CreatedAt,
|
||||
UpdatedAt: t.UpdatedAt,
|
||||
}
|
||||
@@ -328,12 +340,19 @@ func NewTaskCompletionListResponse(completions []models.TaskCompletion) []TaskCo
|
||||
return results
|
||||
}
|
||||
|
||||
// NewTaskCompletionWithTaskResponse creates a TaskCompletionResponse with the updated task included
|
||||
// NewTaskCompletionWithTaskResponse creates a TaskCompletionResponse with the updated task included.
|
||||
// WARNING: Uses UTC time for kanban column. Prefer NewTaskCompletionWithTaskResponseWithTime for timezone-aware responses.
|
||||
func NewTaskCompletionWithTaskResponse(c *models.TaskCompletion, task *models.Task, daysThreshold int) TaskCompletionResponse {
|
||||
return NewTaskCompletionWithTaskResponseWithTime(c, task, daysThreshold, time.Now().UTC())
|
||||
}
|
||||
|
||||
// NewTaskCompletionWithTaskResponseWithTime creates a TaskCompletionResponse with timezone-aware kanban categorization.
|
||||
// The `now` parameter should be the start of day in the user's timezone.
|
||||
func NewTaskCompletionWithTaskResponseWithTime(c *models.TaskCompletion, task *models.Task, daysThreshold int, now time.Time) TaskCompletionResponse {
|
||||
resp := NewTaskCompletionResponse(c)
|
||||
|
||||
if task != nil {
|
||||
taskResp := NewTaskResponseWithThreshold(task, daysThreshold)
|
||||
taskResp := NewTaskResponseWithTime(task, daysThreshold, now)
|
||||
resp.Task = &taskResp
|
||||
}
|
||||
|
||||
@@ -343,10 +362,20 @@ func NewTaskCompletionWithTaskResponse(c *models.TaskCompletion, task *models.Ta
|
||||
// DetermineKanbanColumn determines which kanban column a task belongs to.
|
||||
// Delegates to internal/task/categorization package which is the single source
|
||||
// of truth for task categorization logic.
|
||||
//
|
||||
// WARNING: This uses UTC time which may cause incorrect categorization when
|
||||
// server time is past midnight UTC but user's local time is still the previous day.
|
||||
// Prefer DetermineKanbanColumnWithTime for timezone-aware categorization.
|
||||
func DetermineKanbanColumn(task *models.Task, daysThreshold int) string {
|
||||
return categorization.DetermineKanbanColumn(task, daysThreshold)
|
||||
}
|
||||
|
||||
// DetermineKanbanColumnWithTime determines which kanban column a task belongs to
|
||||
// using a specific time (should be start of day in user's timezone).
|
||||
func DetermineKanbanColumnWithTime(task *models.Task, daysThreshold int, now time.Time) string {
|
||||
return categorization.DetermineKanbanColumnWithTime(task, daysThreshold, now)
|
||||
}
|
||||
|
||||
// === Response Wrappers with Summary ===
|
||||
// These wrap CRUD responses with TotalSummary to eliminate extra API calls
|
||||
|
||||
|
||||
Reference in New Issue
Block a user