format_utility.go 933 Bytes
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 ""
}