Skip to content

Commit

Permalink
add TimeFormatMap and GetTimeFormat to utils pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
alehechka committed Jul 1, 2022
1 parent 52f4aa7 commit b77ab5c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions utils/timeFormat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package utils

import "time"

// TimeFormatMap map of time formats
var TimeFormatMap = map[string]string{
"Layout": time.Layout,
"ANSIC": time.ANSIC,
"UnixDate": time.UnixDate,
"RubyDate": time.RubyDate,
"RFC822": time.RFC822,
"RFC822Z": time.RFC822Z,
"RFC850": time.RFC850,
"RFC1123": time.RFC1123,
"RFC1123Z": time.RFC1123Z,
"RFC3339": time.RFC3339,
"RFC3339Nano": time.RFC3339Nano,
"Kitchen": time.Kitchen,
"Stamp": time.Stamp,
"StampMilli": time.StampMilli,
"StampMicro": time.StampMicro,
"StampNano": time.StampNano,
}

// GetTimeFormat attempts to find a standard time format, else will return the fallback on empty strings or unaltered.
func GetTimeFormat(format string, fallback string) string {
if len(format) == 0 {
return fallback
}

if standard, exists := TimeFormatMap[format]; exists {
return standard
}

return format
}

0 comments on commit b77ab5c

Please sign in to comment.