mirror of
https://github.com/aykhans/dodo.git
synced 2025-09-04 02:13:33 +00:00
🔨 Round off durations before printing
This commit is contained in:
14
utils/time.go
Normal file
14
utils/time.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import "time"
|
||||
|
||||
func DurationRoundBy(duration time.Duration, n int64) time.Duration {
|
||||
if durationLen := NumLen(duration.Nanoseconds()); durationLen > n {
|
||||
roundNum := 1
|
||||
for range durationLen - n {
|
||||
roundNum *= 10
|
||||
}
|
||||
return duration.Round(time.Duration(roundNum))
|
||||
}
|
||||
return duration
|
||||
}
|
Reference in New Issue
Block a user