From 0912e411dba52ffea8616ecd3d4f1befd5a0702b Mon Sep 17 00:00:00 2001 From: Dylan Ravel Date: Tue, 27 Jan 2026 21:54:00 -0800 Subject: [PATCH] Use configured timezone for date parsing and display Replaced usage of time.Local with settings.GetDisplayTimezone() in date parsing and display functions. Also exported GetDisplayTimezone for use outside the settings package, ensuring consistent timezone handling based on user configuration. --- cmd/entries/manual.go | 6 +++--- internal/settings/global_config.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/entries/manual.go b/cmd/entries/manual.go index ad7d1b0..323de46 100644 --- a/cmd/entries/manual.go +++ b/cmd/entries/manual.go @@ -308,15 +308,15 @@ func parseDateTime(date, timeStr, dateLayout string) (time.Time, error) { normalizedTime := normalizeAMPM(timeStr) dateTime := fmt.Sprintf("%s %s", date, normalizedTime) - if dt, err := time.ParseInLocation(dateLayout + " 3:04 PM", dateTime, time.Local); err == nil { + if dt, err := time.ParseInLocation(dateLayout + " 3:04 PM", dateTime, settings.GetDisplayTimezone()); err == nil { return dt, nil } - if dt, err := time.ParseInLocation(dateLayout + " 03:04 PM", dateTime, time.Local); err == nil { + if dt, err := time.ParseInLocation(dateLayout + " 03:04 PM", dateTime, settings.GetDisplayTimezone()); err == nil { return dt, nil } - return time.ParseInLocation(dateLayout + " 15:04", dateTime, time.Local) + return time.ParseInLocation(dateLayout + " 15:04", dateTime, settings.GetDisplayTimezone()) } func normalizeAMPM(input string) string { diff --git a/internal/settings/global_config.go b/internal/settings/global_config.go index 07da812..72700f4 100644 --- a/internal/settings/global_config.go +++ b/internal/settings/global_config.go @@ -92,8 +92,8 @@ func (gc *GlobalConfig) Save() error { return nil } -// getDisplayTimezone returns the user's configured timezone or local timezone as fallback -func getDisplayTimezone() *time.Location { +// GetDisplayTimezone returns the user's configured timezone or local timezone as fallback +func GetDisplayTimezone() *time.Location { cfg, err := LoadGlobalConfig() if err != nil || cfg.Timezone == "" { return time.Local @@ -109,7 +109,7 @@ func getDisplayTimezone() *time.Location { // toDisplayTime converts a UTC time to the user's display timezone func toDisplayTime(t time.Time) time.Time { - return t.In(getDisplayTimezone()) + return t.In(GetDisplayTimezone()) } func FormatTime(t time.Time) string {