-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathutils.go
59 lines (51 loc) · 1.18 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2017 ScyllaDB
// Use of this source code is governed by a ALv2-style
// license that can be found in the LICENSE file.
package qb
import (
"bytes"
"fmt"
"strings"
"time"
)
// placeholders returns a string with count ? placeholders joined with commas.
func placeholders(cql *bytes.Buffer, count int) {
if count < 1 {
return
}
for i := 0; i < count-1; i++ {
cql.WriteByte('?')
cql.WriteByte(',')
}
cql.WriteByte('?')
}
type columns []string
func (cols columns) writeCql(cql *bytes.Buffer) {
for i, c := range cols {
cql.WriteString(c)
if i < len(cols)-1 {
cql.WriteByte(',')
}
}
}
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, "")
}