summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-01-26 16:49:44 -1000
committerPeter Stone <thepeterstone@gmail.com>2026-01-26 16:49:44 -1000
commit42a4e32daca13b518e64e5821080ff3d6adf0e39 (patch)
tree639c790e25b961ecf51ab6ea75206bc3432f1548 /internal/config
parent8de1b5cb8915ed9a6e32566431d05fafafeb338d (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/timezone.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/config/timezone.go b/internal/config/timezone.go
new file mode 100644
index 0000000..04f218e
--- /dev/null
+++ b/internal/config/timezone.go
@@ -0,0 +1,56 @@
+package config
+
+import (
+ "sync"
+ "time"
+)
+
+var (
+ displayTimezone *time.Location
+ tzOnce sync.Once
+)
+
+// SetDisplayTimezone sets the global display timezone (call once at startup)
+func SetDisplayTimezone(tz string) {
+ tzOnce.Do(func() {
+ loc, err := time.LoadLocation(tz)
+ if err != nil {
+ loc = time.UTC
+ }
+ displayTimezone = loc
+ })
+}
+
+// GetDisplayTimezone returns the configured display timezone
+func GetDisplayTimezone() *time.Location {
+ if displayTimezone == nil {
+ return time.UTC
+ }
+ return displayTimezone
+}
+
+// Now returns the current time in the configured display timezone
+func Now() time.Time {
+ return time.Now().In(GetDisplayTimezone())
+}
+
+// Today returns today's date at midnight in the configured timezone
+func Today() time.Time {
+ now := Now()
+ return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, GetDisplayTimezone())
+}
+
+// ParseDateInDisplayTZ parses a date string (2006-01-02) in the display timezone
+func ParseDateInDisplayTZ(dateStr string) (time.Time, error) {
+ return time.ParseInLocation("2006-01-02", dateStr, GetDisplayTimezone())
+}
+
+// ParseDateTimeInDisplayTZ parses a datetime string in the display timezone
+func ParseDateTimeInDisplayTZ(layout, value string) (time.Time, error) {
+ return time.ParseInLocation(layout, value, GetDisplayTimezone())
+}
+
+// ToDisplayTZ converts a time to the display timezone
+func ToDisplayTZ(t time.Time) time.Time {
+ return t.In(GetDisplayTimezone())
+}