From 9219a8d376e239496186619aa94ec38f1917f5e0 Mon Sep 17 00:00:00 2001 From: Luis Felipe Dominguez Vega Date: Fri, 18 Feb 2022 09:38:18 -0500 Subject: [PATCH] Expose time.LoadLocation to template system This allow to render time dates with custom time zones, for example if you have a devops team in different time zones and you want create a message template with the `.app.status.operationState.finishedAt` rendered to different locations. --- expr/time/time.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/expr/time/time.go b/expr/time/time.go index 6457b75d..695619ae 100644 --- a/expr/time/time.go +++ b/expr/time/time.go @@ -8,6 +8,7 @@ func NewExprs() map[string]interface{} { return map[string]interface{}{ "Parse": parse, "Now": now, + "LoadLocation": load_location, } } @@ -22,3 +23,11 @@ func parse(timestamp string) time.Time { func now() time.Time { return time.Now() } + +func load_location(location string) time.Location { + loc, err := time.LoadLocation(location) + if err != nil { + panic(err) + } + return loc +}