Blame view
format_utility.go
1019 Bytes
ea858b8a7 refactoring |
1 |
package webutility |
514fa9dd6 added formating u... |
2 3 |
import ( |
514fa9dd6 added formating u... |
4 |
"time" |
4b4ea384f hmm |
5 |
"fmt" |
514fa9dd6 added formating u... |
6 |
) |
e1fbb41f9 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 minor changes, sh... |
9 10 |
func UnixToDate(unix int64) time.Time { return time.Unix(unix, 0) |
514fa9dd6 added formating u... |
11 |
} |
e1fbb41f9 added comments |
12 |
// DateToUnix converts given date in Unix timestamp. |
33fd58161 minor changes, sh... |
13 14 15 |
func DateToUnix(date interface{}) int64 { if date != nil { t := date.(time.Time) |
514fa9dd6 added formating u... |
16 17 18 19 20 |
return t.Unix() } return 0 } |
e1fbb41f9 added comments |
21 22 |
// EqualQuotes encapsulates given string in SQL 'equal' statement and returns result. // Example: "hello" -> " = 'hello'" |
33fd58161 minor changes, sh... |
23 24 |
func EqualQuotes(stmt string) string { if stmt != "" { |
4b4ea384f hmm |
25 |
stmt = fmt.Sprintf(" = '%s'", stmt) |
514fa9dd6 added formating u... |
26 |
} |
33fd58161 minor changes, sh... |
27 |
return stmt |
514fa9dd6 added formating u... |
28 |
} |
da1d1d418 SQL EqualString f... |
29 30 31 32 33 34 |
func EqualString(stmt string) string { if stmt != "" { stmt = fmt.Sprintf(" = %s", stmt) } return stmt } |
e1fbb41f9 added comments |
35 36 |
// LikeQuotes encapsulates given string in SQL 'like' statement and returns result. // Example: "hello" -> " LIKE UPPER('%hello%')" |
33fd58161 minor changes, sh... |
37 38 |
func LikeQuotes(stmt string) string { if stmt != "" { |
e77b75ec6 proper LIKE forma... |
39 |
stmt = fmt.Sprintf(" LIKE UPPER('%s%s%s')", "%", stmt, "%") |
514fa9dd6 added formating u... |
40 |
} |
33fd58161 minor changes, sh... |
41 |
return stmt |
514fa9dd6 added formating u... |
42 |
} |