mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-16 01:43:13 +00:00
15 lines
308 B
Go
15 lines
308 B
Go
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
|
|
}
|