Adds the GetYearsOld function to the templates
This commit is contained in:
parent
cdd29a7ae8
commit
7dae3def51
1 changed files with 7 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue