-
Notifications
You must be signed in to change notification settings - Fork 303
/
format.go
47 lines (41 loc) · 893 Bytes
/
format.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
package hud
import (
"fmt"
"math"
"time"
)
// Duplicated in web/src/format.ts
func formatBuildDuration(d time.Duration) string {
hours := int(d.Hours())
if hours > 0 {
return fmt.Sprintf("%dh", hours)
}
minutes := int(d.Minutes())
if minutes > 0 {
return fmt.Sprintf("%dm", minutes)
}
seconds := d.Seconds()
if seconds >= 9.95 {
return fmt.Sprintf("%ds", int(math.Round(seconds)))
}
fractionalSeconds := float64(d) / float64(time.Second)
return fmt.Sprintf("%0.1fs", fractionalSeconds)
}
func formatDeployAge(d time.Duration) string {
switch {
case d.Seconds() < 5:
return "<5s"
case d.Seconds() < 15:
return "<15s"
case d.Seconds() < 30:
return "<30s"
case d.Seconds() < 45:
return "<45s"
case d.Minutes() < 1:
return "<1m"
case d.Hours() < 1:
return fmt.Sprintf("%dm", int(d.Minutes()))
default:
return fmt.Sprintf("%dh", int(d.Hours()))
}
}