From 9b1554d72cda849e2d4bc4eb2f921e1519036759 Mon Sep 17 00:00:00 2001 From: teernisse Date: Mon, 23 Feb 2026 09:36:59 -0500 Subject: [PATCH] fix: sort top-spending days by date after cost-based limiting The top-spending-days card first sorts all days by cost descending to find the N highest-cost days, then was iterating over the full sorted slice instead of the limited subset. Additionally, the limited days appeared in cost order rather than chronological order, making the timeline hard to scan. Fix: after slicing to the top N, re-sort that subset by date (most recent first) before rendering, and iterate over the correct limited slice. Co-Authored-By: Claude Opus 4.6 --- internal/tui/tab_costs.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/tui/tab_costs.go b/internal/tui/tab_costs.go index 19ab6de..1d3cfb9 100644 --- a/internal/tui/tab_costs.go +++ b/internal/tui/tab_costs.go @@ -160,9 +160,13 @@ func (a App) renderCostsTab(cw int) string { sorted := make([]model.DailyStats, len(days)) copy(sorted, days) sort.Slice(sorted, func(i, j int) bool { - return sorted[i].Date.After(sorted[j].Date) + return sorted[i].EstimatedCost > sorted[j].EstimatedCost }) - for _, d := range sorted[:spendLimit] { + topDays := sorted[:spendLimit] + sort.Slice(topDays, func(i, j int) bool { + return topDays[i].Date.After(topDays[j].Date) + }) + for _, d := range topDays { fmt.Fprintf(&spendBody, "%s %s\n", valueStyle.Render(d.Date.Format("Jan 02")), lipgloss.NewStyle().Foreground(t.Green).Render(cli.FormatCost(d.EstimatedCost)))