-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
65 lines (54 loc) · 1.01 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
60
61
62
63
64
65
package service
import (
"os"
"time"
"github.com/Adapptor/service/v2/log"
)
// Integer min/max
func Min(x, y int32) int32 {
if x < y {
return x
}
return y
}
func Max(x, y int32) int32 {
if x > y {
return x
}
return y
}
func MapFromStringSlice(strs []string) map[string]bool {
result := make(map[string]bool)
for _, s := range strs {
result[s] = true
}
return result
}
func PerthLocation() *time.Location {
awst, err := time.LoadLocation("Australia/Perth")
if err != nil {
log.Log(log.Error, "PerthLocation() unable to find Perth timezone in local timezone db", err, nil)
os.Exit(1)
}
return awst
}
func PerthNow() time.Time {
return time.Now().In(PerthLocation())
}
func ParseProtoTime(timeStr string) (time.Time, error) {
date, err := time.Parse("2006-01-02T15:04:05", timeStr)
if err != nil {
return date, err
}
date = time.Date(
date.Year(),
date.Month(),
date.Day(),
date.Hour(),
date.Minute(),
date.Second(),
date.Nanosecond(),
PerthLocation(),
)
return date, nil
}