tpl/time: Handle nil values in time.AsTime

Closes #8865
This commit is contained in:
Bjørn Erik Pedersen
2021-08-09 18:44:35 +02:00
parent 9bba9a3a98
commit 3e11072892
2 changed files with 9 additions and 1 deletions

View File

@@ -19,6 +19,8 @@ import (
"time"
_time "time"
"github.com/gohugoio/hugo/common/hreflect"
"github.com/gohugoio/hugo/common/htime"
"github.com/gohugoio/locales"
@@ -43,6 +45,9 @@ type Namespace struct {
// AsTime converts the textual representation of the datetime string into
// a time.Time interface.
func (ns *Namespace) AsTime(v interface{}, args ...interface{}) (interface{}, error) {
if !hreflect.IsTruthful(v) {
return time.Time{}, nil
}
loc := ns.location
if len(args) > 0 {
locStr, err := cast.ToStringE(args[0])