diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-28 18:02:42 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-28 18:02:42 +0200 |
commit | b5de37ee793c01f2acccdea7119be05c4182723f (patch) | |
tree | 3e756ee580e20c77a364a71231872e29b1c1dd23 /common | |
parent | bf301daf158e5e9673ad5f457ea3a264315942b5 (diff) |
Handle toml.LocalDate and toml.LocalDateTime in front matter
See #8801
Diffstat (limited to 'common')
-rw-r--r-- | common/htime/time.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/common/htime/time.go b/common/htime/time.go index cd294b3a2..f5a19b961 100644 --- a/common/htime/time.go +++ b/common/htime/time.go @@ -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) +} |