Blame view

format.go 1.02 KB
ea858b8a7   Marko Tikvić   refactoring
1
  package webutility
514fa9dd6   Marko Tikvić   added formating u...
2
3
  
  import (
4b4ea384f   Marko Tikvić   hmm
4
  	"fmt"
a205e8f40   Marko Tikvić   changes
5
  	"time"
514fa9dd6   Marko Tikvić   added formating u...
6
  )
e1fbb41f9   Marko Tikvić   added comments
7
8
  // UnixToDate converts given Unix time to local time in format and returns result:
  // YYYY-MM-DD hh:mm:ss +zzzz UTC
33fd58161   markotikvic   minor changes, sh...
9
10
  func UnixToDate(unix int64) time.Time {
  	return time.Unix(unix, 0)
514fa9dd6   Marko Tikvić   added formating u...
11
  }
e1fbb41f9   Marko Tikvić   added comments
12
  // DateToUnix converts given date in Unix timestamp.
33fd58161   markotikvic   minor changes, sh...
13
14
  func DateToUnix(date interface{}) int64 {
  	if date != nil {
a205e8f40   Marko Tikvić   changes
15
16
17
18
  		t, ok := date.(time.Time)
  		if !ok {
  			return 0
  		}
514fa9dd6   Marko Tikvić   added formating u...
19
20
21
22
23
  		return t.Unix()
  
  	}
  	return 0
  }
e1fbb41f9   Marko Tikvić   added comments
24
25
  // EqualQuotes encapsulates given string in SQL 'equal' statement and returns result.
  // Example: "hello" -> " = 'hello'"
33fd58161   markotikvic   minor changes, sh...
26
27
  func EqualQuotes(stmt string) string {
  	if stmt != "" {
4b4ea384f   Marko Tikvić   hmm
28
  		stmt = fmt.Sprintf(" = '%s'", stmt)
514fa9dd6   Marko Tikvić   added formating u...
29
  	}
33fd58161   markotikvic   minor changes, sh...
30
  	return stmt
514fa9dd6   Marko Tikvić   added formating u...
31
  }
da1d1d418   Marko Tikvić   SQL EqualString f...
32
33
34
35
36
37
  func EqualString(stmt string) string {
  	if stmt != "" {
  		stmt = fmt.Sprintf(" = %s", stmt)
  	}
  	return stmt
  }
e1fbb41f9   Marko Tikvić   added comments
38
39
  // LikeQuotes encapsulates given string in SQL 'like' statement and returns result.
  // Example: "hello" -> " LIKE UPPER('%hello%')"
33fd58161   markotikvic   minor changes, sh...
40
41
  func LikeQuotes(stmt string) string {
  	if stmt != "" {
e77b75ec6   Marko Tikvić   proper LIKE forma...
42
  		stmt = fmt.Sprintf(" LIKE UPPER('%s%s%s')", "%", stmt, "%")
514fa9dd6   Marko Tikvić   added formating u...
43
  	}
33fd58161   markotikvic   minor changes, sh...
44
  	return stmt
514fa9dd6   Marko Tikvić   added formating u...
45
  }