From e9efdcf94a040fd5bdcdf0c6d8428a7a5c8ca158 Mon Sep 17 00:00:00 2001 From: Roman Vynar Date: Wed, 21 Feb 2024 11:28:40 +0200 Subject: [PATCH] Fix timezone support --- template.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/template.go b/template.go index e201c32..0a32a49 100644 --- a/template.go +++ b/template.go @@ -4,7 +4,7 @@ import ( "fmt" "io" "net/url" - "strings" + "time" "github.com/CloudyKit/jet" "github.com/labstack/echo/v4" @@ -52,10 +52,9 @@ func setupRenderer(debug bool, registryHost, basePath string) *Template { } return registry.PrettySize(value) }) - view.AddGlobal("pretty_time", func(datetime interface{}) string { - d := strings.Replace(datetime.(string), "T", " ", 1) - d = strings.Replace(d, "Z", "", 1) - return strings.Split(d, ".")[0] + view.AddGlobal("pretty_time", func(timeVal interface{}) string { + t, _ := time.Parse("2006-01-02T15:04:05Z", timeVal.(string)) + return t.In(time.Local).Format("2006-01-02 15:04:05 MST") }) view.AddGlobal("parse_map", func(m interface{}) string { var res string