Should `dateFormat` be able to round-trip dates?

When the frontmatter says date: 2017-01-14 08:30:00Z then this use of .Date works:

{{ dateFormat "2006-01-02" .Date }}

and so does this:

{{ dateFormat "2006-01-02" "2017-01-14 08:30:00Z" }}

but this one doesn’t:

{{ $date := string .Date }}
{{ dateFormat "2006-01-02" $date }}

because:

{{ dateFormat "2006-01-02" "2017-01-14 08:30:00 +0000 UTC" }}

generates an error, and that’s printf/string's string representation of dates.

It looks like Hugo’s dateFormat doesn’t like the default string representation of dates. Is that a bug, or should the string representation be generated differently from printf/string to avoid this?

Yes, it should. It’s an issue in an upstream/sister package, but we’ll get it fixed.

1 Like

Thanks for confirming, @moorereason!