-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from alehechka/feature/refactor-time-format
Refactor Time Format
- Loading branch information
Showing
2 changed files
with
38 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |