From 42a4e32daca13b518e64e5821080ff3d6adf0e39 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Mon, 26 Jan 2026 16:49:44 -1000 Subject: Use configured timezone throughout codebase - Add config/timezone.go with timezone utilities: - SetDisplayTimezone(), GetDisplayTimezone() - Now(), Today() - current time/date in display TZ - ParseDateInDisplayTZ(), ToDisplayTZ() - parsing helpers - Initialize timezone at startup in main.go - Update all datetime logic to use configured timezone: - handlers/handlers.go - all time.Now() calls - handlers/timeline.go - date parsing - handlers/timeline_logic.go - now calculation - models/atom.go - ComputeUIFields() - models/timeline.go - ComputeDaySection() - api/plantoeat.go - meal date parsing - api/todoist.go - due date parsing - api/trello.go - due date parsing This ensures all dates/times display correctly regardless of server timezone setting. Co-Authored-By: Claude Opus 4.5 --- internal/handlers/handlers.go | 15 +++++++-------- internal/handlers/timeline.go | 10 ++++------ internal/handlers/timeline_logic.go | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'internal/handlers') diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 595ab67..1e376b5 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -124,7 +124,7 @@ func (h *Handler) HandleGetTasks(w http.ResponseWriter, r *http.Request) { // HandleGetMeals returns meals as JSON func (h *Handler) HandleGetMeals(w http.ResponseWriter, r *http.Request) { - startDate := time.Now() + startDate := config.Now() endDate := startDate.AddDate(0, 0, 7) meals, err := h.store.GetMeals(startDate, endDate) @@ -183,7 +183,7 @@ func (h *Handler) HandleRefreshTab(w http.ResponseWriter, r *http.Request) { // aggregateData fetches and caches data from all sources concurrently func (h *Handler) aggregateData(ctx context.Context, forceRefresh bool) (*models.DashboardData, error) { data := &models.DashboardData{ - LastUpdated: time.Now(), + LastUpdated: config.Now(), Errors: make([]string, 0), } @@ -423,7 +423,7 @@ func (h *Handler) convertSyncItemToTask(item api.SyncItemResponse, projectMap ma // fetchMeals fetches meals from cache or API func (h *Handler) fetchMeals(ctx context.Context, forceRefresh bool) ([]models.Meal, error) { - startDate := time.Now() + startDate := config.Now() endDate := startDate.AddDate(0, 0, 7) fetcher := &CacheFetcher[models.Meal]{ @@ -741,7 +741,7 @@ func (h *Handler) HandleUnifiedAdd(w http.ResponseWriter, r *http.Request) { var dueDate *time.Time if dueDateStr != "" { - if parsed, err := time.ParseInLocation("2006-01-02", dueDateStr, time.Local); err == nil { + if parsed, err := config.ParseDateInDisplayTZ(dueDateStr); err == nil { dueDate = &parsed } } @@ -978,7 +978,7 @@ func (h *Handler) HandleTabTasks(w http.ResponseWriter, r *http.Request) { Atoms: currentAtoms, FutureAtoms: futureAtoms, Boards: boards, - Today: time.Now().Format("2006-01-02"), + Today: config.Now().Format("2006-01-02"), } HTMLResponse(w, h.templates, "tasks-tab", data) @@ -986,8 +986,7 @@ func (h *Handler) HandleTabTasks(w http.ResponseWriter, r *http.Request) { // HandleTabPlanning renders the Planning tab with structured sections func (h *Handler) HandleTabPlanning(w http.ResponseWriter, r *http.Request) { - now := time.Now() - today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) + today := config.Today() tomorrow := today.AddDate(0, 0, 1) in3Days := today.AddDate(0, 0, 4) @@ -1121,7 +1120,7 @@ func (h *Handler) HandleTabPlanning(w http.ResponseWriter, r *http.Request) { // HandleTabMeals renders the Meals tab (PlanToEat) func (h *Handler) HandleTabMeals(w http.ResponseWriter, r *http.Request) { - startDate := time.Now() + startDate := config.Now() endDate := startDate.AddDate(0, 0, 7) meals, err := h.store.GetMeals(startDate, endDate) diff --git a/internal/handlers/timeline.go b/internal/handlers/timeline.go index ce0e831..9821452 100644 --- a/internal/handlers/timeline.go +++ b/internal/handlers/timeline.go @@ -5,6 +5,7 @@ import ( "strconv" "time" + "task-dashboard/internal/config" "task-dashboard/internal/models" ) @@ -25,19 +26,16 @@ func (h *Handler) HandleTimeline(w http.ResponseWriter, r *http.Request) { var start time.Time if startStr != "" { - parsed, err := time.ParseInLocation("2006-01-02", startStr, time.Local) + parsed, err := config.ParseDateInDisplayTZ(startStr) if err == nil { start = parsed } else { - start = time.Now() + start = config.Today() } } else { - start = time.Now() + start = config.Today() } - // Normalize start to beginning of day - start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location()) - days := 3 // Default if daysStr != "" { if d, err := strconv.Atoi(daysStr); err == nil && d > 0 { diff --git a/internal/handlers/timeline_logic.go b/internal/handlers/timeline_logic.go index 0d4595f..bead98f 100644 --- a/internal/handlers/timeline_logic.go +++ b/internal/handlers/timeline_logic.go @@ -14,7 +14,7 @@ import ( // BuildTimeline aggregates and normalizes data into a timeline structure func BuildTimeline(ctx context.Context, s *store.Store, calendarClient api.GoogleCalendarAPI, start, end time.Time) ([]models.TimelineItem, error) { var items []models.TimelineItem - now := time.Now() + now := config.Now() // 1. Fetch Tasks tasks, err := s.GetTasksByDateRange(start, end) -- cgit v1.2.3