htime: Set zone of datetime from from `go-toml`
authorsatotake <doublequotation@gmail.com>
Mon, 25 Oct 2021 17:49:44 +0000 (02:49 +0900)
committerGitHub <noreply@github.com>
Mon, 25 Oct 2021 17:49:44 +0000 (19:49 +0200)
`go-toml/v2`'s unmarshaler does not specify zone name even if value has
offset explicitly.
To make time-formatting behaviour consistent, convert them into string
in hugo.

Close #8895

common/htime/time.go

index 33a77ead5c25c3107edfb8b6d53ffc9e5ab4429a..5071b08585ba3709a87bb348ca0e3aa1aefb4c7d 100644 (file)
@@ -136,6 +136,11 @@ func ToTimeInDefaultLocationE(i interface{}, location *time.Location) (tim time.
                return vv.AsTime(location), nil
        case toml.LocalDateTime:
                return vv.AsTime(location), nil
+       // issue #8895
+       // datetimes parsed by `go-toml` have empty zone name
+       // convert back them into string and use `cast`
+       case time.Time:
+               i = vv.Format(time.RFC3339)
        }
        return cast.ToTimeInDefaultLocationE(i, location)
 }