Go and date-time formatting

Really surprising for a language released in March 2012 that they would have such a messed-up default formatting (not just parsing).

Ran across this line in Hugo (a static html site builder):
{{ .Date.Format “2006-01-02” }}

Then the output you get is: “2022-04-09” (a blog post date, correct).

If you change it to:
{{ .Date.Format “2000-01-02” }}

Then the output you get is: “9000-04-09”

As the documentation says:

// The reference time used in these layouts is the specific time stamp:
//
//	01/02 03:04:05PM '06 -0700
//

i.e. “01” is the month, “02” is the day, “03” is the hour, etc.

Of interest is the extra “20” in front of “06” – is it just hard-coding “20” in front of what the “06” is generating? It sure could be. And no, not going to try to read the source to find out.

This is egregiously bad behavior. It is pretty much a “Done with Go” moment.

This entry was posted in Software Engineering. Bookmark the permalink.