From c6a9ee27141fd1a57813fcc7f54fe370408bae14 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 4 Mar 2026 00:05:49 +0200 Subject: worktime: centralize active category status logic --- internal/cli/work.go | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'internal/cli') diff --git a/internal/cli/work.go b/internal/cli/work.go index 775a0d7..1f34cf9 100644 --- a/internal/cli/work.go +++ b/internal/cli/work.go @@ -7,7 +7,6 @@ import ( "os" "os/exec" "path/filepath" - "sort" "strconv" "strings" "time" @@ -296,7 +295,7 @@ func newWorkStatusCmd() *cobra.Command { return err } - active := activeCategories(entries) + active := worktime.ActiveCategories(entries) if len(active) == 0 { return printOutput(cmd, "Not logged in.") } @@ -396,33 +395,6 @@ func parseAtOrNow(value string) (time.Time, error) { return timefmt.Parse(value) } -func activeCategories(entries []worktime.Entry) []string { - status := map[string]bool{} - - for _, entry := range entries { - category := strings.TrimSpace(entry.What) - if category == "" { - category = "work" - } - - switch strings.ToLower(strings.TrimSpace(entry.Action)) { - case "login": - status[category] = true - case "logout": - status[category] = false - } - } - - active := make([]string, 0) - for category, isActive := range status { - if isActive { - active = append(active, category) - } - } - sort.Strings(active) - return active -} - func importReportFile(ctx workContext, report io.Reader) (int, error) { return worktime.ImportReport(ctx.dbDir, ctx.host, report) } -- cgit v1.2.3