tpl/time: Add time.Duration and time.ParseDuration template funcs

And with time.Duration with the convenient alias `duration`:

```
{{ mul 60 60 | duration "second" }}
```

Fixes #3828
This commit is contained in:
Bjørn Erik Pedersen
2017-09-08 17:58:39 +02:00
parent 0462c96a5a
commit f4bf214137
3 changed files with 107 additions and 0 deletions

View File

@@ -65,6 +65,20 @@ func init() {
},
)
ns.AddMethodMapping(ctx.Duration,
[]string{"duration"},
[][2]string{
{`{{ mul 60 60 | duration "second" }}`, `1h0m0s`},
},
)
ns.AddMethodMapping(ctx.ParseDuration,
nil,
[][2]string{
{`{{ "1h12m10s" | time.ParseDuration }}`, `1h12m10s`},
},
)
return ns
}