From 21675bdb8da7a44479a2e918edc576fabfcedb23 Mon Sep 17 00:00:00 2001 From: Amolith Date: Sun, 21 Dec 2025 15:43:05 -0700 Subject: [PATCH] refactor(ui): use lctime for date formatting Assisted-by: Claude Opus 4.5 via Crush --- go.mod | 1 + go.sum | 2 ++ internal/ui/styles.go | 26 +++----------------------- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 913b86f2f5c1e6828b718b68d41c1c168882b076..46cb52fd5d7fc4dc350af031ef60621e7a5d64c7 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/charmbracelet/huh/spinner v0.0.0-20251215014908-6f7d32faaff3 github.com/charmbracelet/lipgloss v1.1.0 github.com/google/uuid v1.6.0 + github.com/klauspost/lctime v0.1.0 github.com/spf13/cobra v1.10.2 github.com/zalando/go-keyring v0.2.6 ) diff --git a/go.sum b/go.sum index 2c329febfe0f0d5c8073f5cbf4a0412a267ba417..26c2cd116e0ae0e96d8de97bb7133880d2324c11 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/klauspost/lctime v0.1.0 h1:nINsuFc860M9cyYhT6vfg6U1USh7kiVBj/s/2b04U70= +github.com/klauspost/lctime v0.1.0/go.mod h1:OwdMhr8tbQvusAsnilqkkgDQqivWlqyg0w5cfXkLiDk= github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= diff --git a/internal/ui/styles.go b/internal/ui/styles.go index 4f8ad59a05ba5c342fe9c03cfdc79ad3c553785e..4a3c5a362087df9857ff5714729f62df2adacd51 100644 --- a/internal/ui/styles.go +++ b/internal/ui/styles.go @@ -6,10 +6,10 @@ package ui import ( - "os" "time" "github.com/charmbracelet/lipgloss" + "github.com/klauspost/lctime" ) // Terminal output styles using ANSI colors for broad compatibility. @@ -21,28 +21,8 @@ var ( Bold = lipgloss.NewStyle().Bold(true) ) -// dateFormat holds the date format string derived from locale. -var dateFormat = initDateFormat() - -// initDateFormat determines the date format based on LC_TIME or LANG. -func initDateFormat() string { - locale := os.Getenv("LC_TIME") - if locale == "" { - locale = os.Getenv("LANG") - } - - // US English uses month-first; most other locales use day-first or ISO - switch { - case len(locale) >= 2 && locale[:2] == "en" && len(locale) >= 5 && locale[3:5] == "US": - return "01/02/2006" - case len(locale) >= 2 && locale[:2] == "en": - return "02/01/2006" - default: - return "2006-01-02" // ISO 8601 as sensible default - } -} - // FormatDate formats a time.Time as a date string using the user's locale. +// Locale is auto-detected from LC_TIME, LC_ALL, or LANG environment variables. func FormatDate(t time.Time) string { - return t.Format(dateFormat) + return lctime.Strftime("%x", t) }