Skip to content

Commit

Permalink
Format took time as minutes and seconds (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScorpion authored Dec 8, 2023
1 parent 5c0e792 commit bfec874
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/execTime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"fmt"
"gokart-prompt/internal/ansi"
"math"
"os"
"strconv"
)
Expand All @@ -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
}

0 comments on commit bfec874

Please sign in to comment.