I couldn’t figure out where 2006 Jan 2 came into play so I looked up the documentation:
Parse parses a formatted string and returns the time value it represents. The layout defines the format by showing how the reference time, defined to be Mon Jan 2 15:04:05 -0700 MST 2006
What an odd function. Why parse a seemingly arbitrary date (birth of Go?) constant and not a template like YYYY mmm d?
The reference time is selected to prevent ambiguity in the representation (e.g. dd-mm-YYYY or mm-dd-YYYY? You can tell because the day is always 2).
Personally, I don’t like this API. It massively increases the number of edge cases, unexpected or confusing behavior, and complexity over a simple format string, and it ignores the de facto standard time format API set by strftime. But it is in principle consistent, and I can see the reasoning behind it (to avoid the strftime DSL and make it easier to go from an example formatted date to format string).
I would have understood it if they had picked some ascending or descending order, but “01/02 03:04:05PM ‘06 -0700” looks pretty random to me. Not sure what their reasoning was … “this thing with inches and footsies is not confusing enough, let’s mess up time too”?
I noticed this in one of the slides:
_, err := time.Parse("2006 Jan 2", day)I couldn’t figure out where
2006 Jan 2came into play so I looked up the documentation:What an odd function. Why parse a seemingly arbitrary date (birth of Go?) constant and not a template like
YYYY mmm d?Edit: from an old revision of the code:
The reference time is selected to prevent ambiguity in the representation (e.g. dd-mm-YYYY or mm-dd-YYYY? You can tell because the day is always 2).
Personally, I don’t like this API. It massively increases the number of edge cases, unexpected or confusing behavior, and complexity over a simple format string, and it ignores the de facto standard time format API set by strftime. But it is in principle consistent, and I can see the reasoning behind it (to avoid the strftime DSL and make it easier to go from an example formatted date to format string).
You’re not the only one finding it annoying ;) This page helps.
Why is the day always 2?
I would have understood it if they had picked some ascending or descending order, but “01/02 03:04:05PM ‘06 -0700” looks pretty random to me. Not sure what their reasoning was … “this thing with inches and footsies is not confusing enough, let’s mess up time too”?