Commit befe8fcc1dc1e4b13d973c00813955612d073b20

Authored by Marko Tikvić
Exists in master

Merge branch 'master' of http://git.to-net.rs/marko.tikvic/webutility

... ... @@ -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   -
... ...
... ... @@ -50,3 +50,11 @@ func BoolToInt64(b bool) int64 {
50 50 func Int64ToBool(i int64) bool {
51 51 return i != 0
52 52 }
  53 +
  54 +func StringToValidInt64(s string) (int64, bool) {
  55 + i, err := strconv.ParseInt(s, 10, 64)
  56 + if err != nil {
  57 + return i, false
  58 + }
  59 + return i, true
  60 +}
... ...