diff --git a/internal/config/config.go b/internal/config/config.go index 5913425..db0fca7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -107,7 +107,7 @@ func Save(cfg Config) error { return fmt.Errorf("creating config dir: %w", err) } - f, err := os.Create(ConfigPath()) + f, err := os.OpenFile(ConfigPath(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { return fmt.Errorf("creating config file: %w", err) } diff --git a/internal/pipeline/aggregator.go b/internal/pipeline/aggregator.go index 906d6a1..39f191b 100644 --- a/internal/pipeline/aggregator.go +++ b/internal/pipeline/aggregator.go @@ -97,6 +97,17 @@ func AggregateDays(sessions []model.SessionStats, since, until time.Time) []mode ds.EstimatedCost += s.EstimatedCost } + // Fill in every day in the range so the chart shows gaps as zeros + day := since.Local().Truncate(24 * time.Hour) + end := until.Local().Truncate(24 * time.Hour) + for !day.After(end) { + dayKey := day.Format("2006-01-02") + if _, ok := dayMap[dayKey]; !ok { + dayMap[dayKey] = &model.DailyStats{Date: day} + } + day = day.AddDate(0, 0, 1) + } + // Convert to sorted slice (most recent first) days := make([]model.DailyStats, 0, len(dayMap)) for _, ds := range dayMap {