Handle toml.LocalDate and toml.LocalDateTime in front matter

See #8801
This commit is contained in:
Bjørn Erik Pedersen
2021-07-28 18:02:42 +02:00
parent bf301daf15
commit b5de37ee79
4 changed files with 21 additions and 6 deletions

View File

@@ -17,6 +17,10 @@ import (
"strings"
"time"
"github.com/spf13/cast"
toml "github.com/pelletier/go-toml/v2"
"github.com/go-playground/locales"
)
@@ -125,3 +129,13 @@ func (f TimeFormatter) Format(t time.Time, layout string) string {
return s
}
func ToTimeInDefaultLocationE(i interface{}, location *time.Location) (tim time.Time, err error) {
switch vv := i.(type) {
case toml.LocalDate:
return vv.AsTime(location), nil
case toml.LocalDateTime:
return vv.AsTime(location), nil
}
return cast.ToTimeInDefaultLocationE(i, location)
}