🔨 Round off durations before printing

This commit is contained in:
2024-12-19 21:40:53 +04:00
parent 77ddcf722a
commit 18b1c7dae3
4 changed files with 59 additions and 22 deletions

14
utils/time.go Normal file
View 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
}