From eaf25d7b79abc0e42b4d02b67e7b88e48ed32428 Mon Sep 17 00:00:00 2001 From: Patrick Maloney Date: Tue, 23 Jan 2024 16:35:56 +0100 Subject: [PATCH] do a better job formatting elapsed time --- cmd/ls.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/ls.go b/cmd/ls.go index a2c56f2..81fd95c 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -64,6 +64,14 @@ var taskCmd = &cobra.Command{ }, } +func fmtDuration(d time.Duration) string { + d = d.Round(time.Minute) + h := d / time.Hour + d -= h * time.Hour + m := d / time.Minute + return fmt.Sprintf("%02d:%02d", h, m) +} + var activityCmd = &cobra.Command{ Use: "activity", Short: "List activities", @@ -84,7 +92,7 @@ var activityCmd = &cobra.Command{ } id := fmt.Sprintf("%d", activity.Id) date := activity.Date - time := duration.String() + time := fmtDuration(duration) desc := activity.Description rows = append(rows, []string{id, date, time, desc}) }