diff --git a/format.go b/format.go index 755b97f..c7759e2 100644 --- a/format.go +++ b/format.go @@ -24,6 +24,33 @@ func DateToUnix(date interface{}) int64 { return 0 } +// UnixPtrToDate converts given Unix time to local time in format and returns result: +// YYYY-MM-DD hh:mm:ss +zzzz UTC +func UnixPtrToDatePtr(unix *int64) *time.Time { + var t time.Time + if unix == nil { + return nil + } + t = time.Unix(*unix, 0) + return &t +} + +// DateToUnix converts given date in Unix timestamp. +func DatePtrToUnixPtr(date interface{}) *int64 { + var unix int64 + + if date != nil { + t, ok := date.(time.Time) + if !ok { + return nil + } + unix = t.Unix() + return &unix + + } + return nil +} + // EqualQuotes encapsulates given string in SQL 'equal' statement and returns result. // Example: "hello" -> " = 'hello'" func EqualQuotes(stmt string) string { @@ -49,4 +76,3 @@ func LikeQuotes(stmt string) string { } return stmt } -