github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/pkg/format/duration.go (about) 1 package format 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 // DisplayDuration used to display durations output to users 9 func DisplayDuration(d time.Duration) string { 10 if d.Minutes() > 1 { 11 return fmt.Sprintf("%.1fm", float64(d)/float64(time.Minute)) 12 } 13 if d.Seconds() > 1 { 14 return fmt.Sprintf("%.1fs", float64(d)/float64(time.Second)) 15 } 16 return fmt.Sprintf("%.1fms", float64(d)/float64(time.Millisecond)+0.1) // add .1ms so that it never returns 0.0ms 17 }