Commit ff845040c172c5856d6cfbfe943cf132985e7209
1 parent
3173b06a41
Exists in
master
unix/date nullables
Showing
1 changed file
with
27 additions
and
1 deletions
Show diff stats
format.go
... | ... | @@ -24,6 +24,33 @@ func DateToUnix(date interface{}) int64 { |
24 | 24 | return 0 |
25 | 25 | } |
26 | 26 | |
27 | +// UnixPtrToDate converts given Unix time to local time in format and returns result: | |
28 | +// YYYY-MM-DD hh:mm:ss +zzzz UTC | |
29 | +func UnixPtrToDatePtr(unix *int64) *time.Time { | |
30 | + var t time.Time | |
31 | + if unix == nil { | |
32 | + return nil | |
33 | + } | |
34 | + t = time.Unix(*unix, 0) | |
35 | + return &t | |
36 | +} | |
37 | + | |
38 | +// DateToUnix converts given date in Unix timestamp. | |
39 | +func DatePtrToUnixPtr(date interface{}) *int64 { | |
40 | + var unix int64 | |
41 | + | |
42 | + if date != nil { | |
43 | + t, ok := date.(time.Time) | |
44 | + if !ok { | |
45 | + return nil | |
46 | + } | |
47 | + unix = t.Unix() | |
48 | + return &unix | |
49 | + | |
50 | + } | |
51 | + return nil | |
52 | +} | |
53 | + | |
27 | 54 | // EqualQuotes encapsulates given string in SQL 'equal' statement and returns result. |
28 | 55 | // Example: "hello" -> " = 'hello'" |
29 | 56 | func EqualQuotes(stmt string) string { |
... | ... | @@ -49,4 +76,3 @@ func LikeQuotes(stmt string) string { |
49 | 76 | } |
50 | 77 | return stmt |
51 | 78 | } |
52 | - | ... | ... |