Blame view
format_utility.go
908 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 |
} |
e1fbb41f9 added comments |
29 30 |
// LikeQuotes encapsulates given string in SQL 'like' statement and returns result. // Example: "hello" -> " LIKE UPPER('%hello%')" |
33fd58161 minor changes, sh... |
31 32 |
func LikeQuotes(stmt string) string { if stmt != "" { |
e77b75ec6 proper LIKE forma... |
33 |
stmt = fmt.Sprintf(" LIKE UPPER('%s%s%s')", "%", stmt, "%") |
514fa9dd6 added formating u... |
34 |
} |
33fd58161 minor changes, sh... |
35 |
return stmt |
514fa9dd6 added formating u... |
36 |
} |