forked from go-jet/jet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_utils.go
66 lines (44 loc) · 1.27 KB
/
time_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
66
package testutils
import (
"github.com/go-jet/jet/internal/utils"
"strings"
"time"
)
// Date creates time from t string
func Date(t string) *time.Time {
newTime, err := time.Parse("2006-01-02", t)
utils.PanicOnError(err)
return &newTime
}
// TimestampWithoutTimeZone creates time from t
func TimestampWithoutTimeZone(t string, precision int) *time.Time {
precisionStr := ""
if precision > 0 {
precisionStr = "." + strings.Repeat("9", precision)
}
newTime, err := time.Parse("2006-01-02 15:04:05"+precisionStr+" +0000", t+" +0000")
utils.PanicOnError(err)
return &newTime
}
// TimeWithoutTimeZone creates time from t
func TimeWithoutTimeZone(t string) *time.Time {
newTime, err := time.Parse("15:04:05", t)
utils.PanicOnError(err)
return &newTime
}
// TimeWithTimeZone creates time from t
func TimeWithTimeZone(t string) *time.Time {
newTimez, err := time.Parse("15:04:05 -0700", t)
utils.PanicOnError(err)
return &newTimez
}
// TimestampWithTimeZone creates time from t
func TimestampWithTimeZone(t string, precision int) *time.Time {
precisionStr := ""
if precision > 0 {
precisionStr = "." + strings.Repeat("9", precision)
}
newTime, err := time.Parse("2006-01-02 15:04:05"+precisionStr+" -0700 MST", t)
utils.PanicOnError(err)
return &newTime
}