mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
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:
@@ -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
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user