-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.go
52 lines (42 loc) · 1022 Bytes
/
time.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
package helper
import (
"time"
)
const (
Nanosecond int64 = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
Minute = 60 * Second
Hour = 60 * Minute
)
func SecToDuration(sec int64) time.Duration {
return time.Duration(Second * sec)
}
func MinToDuration(min int64) time.Duration {
return time.Duration(min * Minute)
}
func HourToDuration(hour int64) time.Duration {
return time.Duration(hour * Hour)
}
func TimeToDuration(hour, min, sec int64) time.Duration {
return time.Duration(sec*Second + min*Minute + hour*Hour)
}
func DurationToSecond(d time.Duration) int64 {
return int64(d) / Second
}
func DurationToMin(d time.Duration) int64 {
return int64(d) / Minute
}
func DurationToHour(d time.Duration) int64 {
return int64(d) / Hour
}
func DurationToTime(d time.Duration) (hour, min, sec int64) {
dd := int64(d)
hour = dd / Hour
dd %= Hour
min = dd / Minute
dd %= Minute
sec = dd / Second
return
}