-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.go
More file actions
43 lines (35 loc) · 828 Bytes
/
Copy pathtime.go
File metadata and controls
43 lines (35 loc) · 828 Bytes
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
package debugo
import (
"fmt"
"time"
)
func (d *Debugger) elapsed() time.Duration {
currentTime := time.Now()
defer func() { d.lastLog = currentTime }()
elapsed := time.Duration(0)
if !d.lastLog.IsZero() {
elapsed = currentTime.Sub(d.lastLog)
}
return elapsed
}
func prettyPrintDuration(d time.Duration) string {
hours := d / time.Hour
d %= time.Hour
minutes := d / time.Minute
d %= time.Minute
seconds := d / time.Second
d %= time.Second
milliseconds := d / time.Millisecond
result := ""
if hours > 0 {
result += fmt.Sprintf("%dh", hours)
}
if minutes > 0 || hours > 0 {
result += fmt.Sprintf("%dm", minutes)
}
if seconds > 0 || minutes > 0 || hours > 0 {
result += fmt.Sprintf("%ds", seconds)
}
result += fmt.Sprintf("%dms", milliseconds) // Always include milliseconds
return result
}