Skip to content
Snippets Groups Projects
Commit 58ab9602 authored by Francé Wilke's avatar Francé Wilke
Browse files

Add some util functions

parent 27cc74b1
Branches
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
const TimeZoneString = "Africa/Johannesburg" const TimeZoneString = "Africa/Johannesburg"
func DateLayoutYearMonthDayTimeT() string { func DateLayoutYearMonthDayTimeT() string {
layout := "2006-01-02T15:04" layout := "2006-01-02T15:04:05"
return layout return layout
} }
...@@ -47,6 +47,20 @@ func DateLayoutHumanReadable() string { ...@@ -47,6 +47,20 @@ func DateLayoutHumanReadable() string {
return layout return layout
} }
func DateLayoutTrimmed() string {
layout := "20060102150405"
return layout
}
func DateDBFormattedString(date time.Time) string {
return date.Format("2006-01-02 15:04:05.000000-07")
}
func DateDBFormattedStringDateOnly(date time.Time) string {
return date.Format("2006-01-02")
}
func CurrentLocation() *time.Location { func CurrentLocation() *time.Location {
loc, _ := time.LoadLocation(TimeZoneString) loc, _ := time.LoadLocation(TimeZoneString)
return loc return loc
...@@ -88,3 +102,13 @@ func TimeBefore(a string, b string) bool { ...@@ -88,3 +102,13 @@ func TimeBefore(a string, b string) bool {
return hoursA < hoursB return hoursA < hoursB
} }
// ConvertToNoDateTimeString - Converts a PSQL Time type to Go Time type
func ConvertToNoDateTimeString(timeString *string) (*string, error) {
parsedTime, err := time.Parse("15:04:05", *timeString)
if err != nil {
return nil, err
}
formattedTime := parsedTime.Format("15:04")
return &formattedTime, nil
}
...@@ -2,8 +2,10 @@ package encryption ...@@ -2,8 +2,10 @@ package encryption
import ( import (
"crypto/hmac" "crypto/hmac"
"crypto/md5"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"fmt"
) )
func Hash(input string, key string) string { func Hash(input string, key string) string {
...@@ -12,3 +14,9 @@ func Hash(input string, key string) string { ...@@ -12,3 +14,9 @@ func Hash(input string, key string) string {
h.Write([]byte(input)) h.Write([]byte(input))
return base64.StdEncoding.EncodeToString(h.Sum(nil)) return base64.StdEncoding.EncodeToString(h.Sum(nil))
} }
func Md5HashString(bytesToHash []byte) string {
hash := md5.Sum(bytesToHash)
hashString := fmt.Sprintf("%X", hash)
return hashString
}
package string_utils package string_utils
import ( import (
"crypto/md5"
"encoding/json" "encoding/json"
"fmt" "fmt"
"regexp" "regexp"
...@@ -192,3 +193,21 @@ func StringTrimQuotes(stringToTrim string) string { ...@@ -192,3 +193,21 @@ func StringTrimQuotes(stringToTrim string) string {
return stringToTrim return stringToTrim
} }
func KeyToHumanReadable(s string) string {
s = strings.TrimSpace(s)
re := regexp.MustCompile("(_|-)")
s = re.ReplaceAllString(s, " ")
return sentenceCase(string(s))
}
func sentenceCase(str string) string {
for i, v := range str {
return string(unicode.ToUpper(v)) + str[i+1:]
}
return ""
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment