From 7dae3def51f63a7e3048889d0016bedf51a15ba5 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Mon, 10 Jul 2023 23:27:18 +0200 Subject: [PATCH] Adds the GetYearsOld function to the templates --- server/server.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/server.go b/server/server.go index ead52aa..4d1caad 100644 --- a/server/server.go +++ b/server/server.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "text/template" + "time" "git.ctrlz.es/mgdelacroix/birthdaybot/model" "git.ctrlz.es/mgdelacroix/birthdaybot/notification" @@ -94,6 +95,12 @@ func New(options ...Option) (*Server, error) { if err != nil { return nil, fmt.Errorf("cannot parse template file %q: %w", srv.Config.Birthdays.Template, err) } + + srv.tmpl.Funcs(template.FuncMap{ + "GetYearsOld": func(yearOfBirth int) int { + return time.Now().Year() - yearOfBirth + }, + }) } return srv, nil