Truncate sub-{mili,}second durations to 1

This commit is contained in:
Roman Volosatovs 2020-06-10 13:52:12 +02:00
parent ef82e3705c
commit 7f89f75288
No known key found for this signature in database
GPG Key ID: 2660C5FDCEBE6F87
1 changed files with 4 additions and 2 deletions

View File

@ -16,9 +16,10 @@ func usePrecise(dur time.Duration) bool {
func formatMs(dur time.Duration) int64 { func formatMs(dur time.Duration) int64 {
if dur > 0 && dur < time.Millisecond { if dur > 0 && dur < time.Millisecond {
internal.Logger.Printf( internal.Logger.Printf(
"specified duration is %s, but minimal supported value is %s", "specified duration is %s, but minimal supported value is %s - truncate to 1",
dur, time.Millisecond, dur, time.Millisecond,
) )
return 1
} }
return int64(dur / time.Millisecond) return int64(dur / time.Millisecond)
} }
@ -26,9 +27,10 @@ func formatMs(dur time.Duration) int64 {
func formatSec(dur time.Duration) int64 { func formatSec(dur time.Duration) int64 {
if dur > 0 && dur < time.Second { if dur > 0 && dur < time.Second {
internal.Logger.Printf( internal.Logger.Printf(
"specified duration is %s, but minimal supported value is %s", "specified duration is %s, but minimal supported value is %s - truncate to 1",
dur, time.Second, dur, time.Second,
) )
return 1
} }
return int64(dur / time.Second) return int64(dur / time.Second)
} }