Fix USING TIMEOUT time generation (#299)
Scylla does not support fractions. We need to make sure that time is formatted the following way: XmYsZms
This commit is contained in:
26
qb/utils.go
26
qb/utils.go
@@ -6,6 +6,9 @@ package qb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// placeholders returns a string with count ? placeholders joined with commas.
|
||||
@@ -31,3 +34,26 @@ func (cols columns) writeCql(cql *bytes.Buffer) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func formatDuration(d time.Duration) string {
|
||||
// Round the duration to the nearest millisecond
|
||||
// Extract hours, minutes, seconds, and milliseconds
|
||||
minutes := d / time.Minute
|
||||
d %= time.Minute
|
||||
seconds := d / time.Second
|
||||
d %= time.Second
|
||||
milliseconds := d / time.Millisecond
|
||||
|
||||
// Format the duration string
|
||||
var res []string
|
||||
if minutes > 0 {
|
||||
res = append(res, fmt.Sprintf("%dm", minutes))
|
||||
}
|
||||
if seconds > 0 {
|
||||
res = append(res, fmt.Sprintf("%ds", seconds))
|
||||
}
|
||||
if milliseconds > 0 {
|
||||
res = append(res, fmt.Sprintf("%dms", milliseconds))
|
||||
}
|
||||
return strings.Join(res, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user