From 018f737428b36e6605ed108fe0cbea6b596669b0 Mon Sep 17 00:00:00 2001 From: Luca Scalzotto Date: Fri, 8 Dec 2023 22:23:41 +0100 Subject: [PATCH] Format took time as minutes and seconds --- internal/execTime.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/execTime.go b/internal/execTime.go index cdedd56..5f08034 100644 --- a/internal/execTime.go +++ b/internal/execTime.go @@ -3,6 +3,7 @@ package internal import ( "fmt" "gokart-prompt/internal/ansi" + "math" "os" "strconv" ) @@ -28,5 +29,17 @@ func CmdTime() string { return "" } - return ansi.Color(ansi.Yellow, " took "+fmt.Sprintf("%.1f", execTime)+"s") + return ansi.Color(ansi.Yellow, " took "+formatMinutesSeconds(execTime)) +} + +func formatMinutesSeconds(totalSeconds float64) string { + seconds := math.Mod(totalSeconds, 60) + result := fmt.Sprintf("%.1fs", seconds) + + minutes := math.Floor(totalSeconds / 60) + if minutes > 0 { + result = fmt.Sprintf("%.0fm %s", minutes, result) + } + + return result }