v0.1.14
This commit is contained in:
25
img.go
25
img.go
@@ -130,6 +130,7 @@ var funcMap = template.FuncMap{
|
||||
"formatNumber": FormatNumber,
|
||||
"div": Div,
|
||||
"formatDateFromSec": formatDateFromSec,
|
||||
"formatDateFromStr": formatDateFromStr,
|
||||
}
|
||||
|
||||
func renderTemplate(tmp string, data map[string]interface{}) (string, error) {
|
||||
@@ -563,3 +564,27 @@ func formatDateFromSec(input any, layout string) string {
|
||||
t = t.In(loc)
|
||||
return t.Format(layout)
|
||||
}
|
||||
|
||||
func formatDateFromStr(input, inputFormat, outputLayout string) string {
|
||||
var parsedTime time.Time
|
||||
var err error
|
||||
|
||||
switch inputFormat {
|
||||
case "RFC3339Nano":
|
||||
inputFormat = time.RFC3339Nano
|
||||
case "RFC1123":
|
||||
inputFormat = time.RFC1123
|
||||
case "RFC1123Z":
|
||||
inputFormat = time.RFC1123Z
|
||||
case "RFC822":
|
||||
inputFormat = time.RFC822
|
||||
case "RFC822Z":
|
||||
inputFormat = time.RFC822Z
|
||||
}
|
||||
parsedTime, err = time.Parse(inputFormat, input)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing time:", err)
|
||||
return ""
|
||||
}
|
||||
return parsedTime.Format(outputLayout)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user