Adds the GetYearsOld function to the templates

This commit is contained in:
Miguel de la Cruz 2023-07-10 23:27:18 +02:00
parent cdd29a7ae8
commit 7dae3def51

View file

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"text/template" "text/template"
"time"
"git.ctrlz.es/mgdelacroix/birthdaybot/model" "git.ctrlz.es/mgdelacroix/birthdaybot/model"
"git.ctrlz.es/mgdelacroix/birthdaybot/notification" "git.ctrlz.es/mgdelacroix/birthdaybot/notification"
@ -94,6 +95,12 @@ func New(options ...Option) (*Server, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot parse template file %q: %w", srv.Config.Birthdays.Template, err) 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 return srv, nil