-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathformat.go
34 lines (29 loc) · 855 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
package main
import (
"fmt"
"math"
"time"
)
func formatDays(timeLeft time.Duration) string {
days := int(timeLeft.Hours() / 24)
hours := int(timeLeft.Hours()) % 24
minutes := int(timeLeft.Minutes()) % 60
seconds := int(timeLeft.Seconds()) % 60
return fmt.Sprintf("%d:%02d:%02d:%02d",
days, hours, minutes, seconds)
}
func formatHours(timeLeft time.Duration) string {
hours := int(timeLeft.Hours())
minutes := int(timeLeft.Minutes()) % 60
seconds := int(timeLeft.Seconds()) % 60
return fmt.Sprintf("%d:%02d:%02d",
hours, minutes, seconds)
}
func formatMinutes(timeLeft time.Duration) string {
minutes := int(timeLeft.Minutes())
seconds := int(timeLeft.Seconds()) % 60
return fmt.Sprintf("%d:%02d", minutes, seconds)
}
func formatSeconds(timeLeft time.Duration) string {
return fmt.Sprintf("%02.1f", math.Abs(timeLeft.Seconds()))
}