format_utility.go
933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package restutility
import (
"strings"
"time"
"strconv"
)
////
//// TIME FORMAT UTILITY
////
func unixToDate(input int64) time.Time {
return time.Unix(input, 0)
}
func dateToUnix(input interface{}) int64 {
if input != nil {
t := input.(time.Time)
return t.Unix()
}
return 0
}
func aersDate(unixString string) (string, error) {
unixTime, err := strconv.ParseInt(unixString, 10, 64)
if err != nil {
return "", err
}
date := unixToDate(unixTime).String()
tokens := strings.Split(date, "-")
dateString := tokens[0] + tokens[1] + strings.Split(tokens[2], " ")[0]
return dateString, nil
}
////
//// STRING UTILITY
////
// surrondWithSingleQuotes is used when url param is of type string
func putQuotes(input string) string {
if input != "" {
return " = '" + input + "'"
}
return ""
}
func putLikeQuotes(input string) string {
if input != "" {
return " LIKE UPPER('%" + input + "%')"
}
return ""
}