Does anybody else dislike the way go handles dates? I just did the booking up for beauty exercise and I found it to be a ‘guess the missing character’ mini-game. It was the only exercise I didn’t enjoy at no fault of the creator of the execise. I don’t like that go uses essentially a ‘magic number’ to specify day/time in history. stings like YYYY-MM-DD HH:MM:SS are so much easier to read. I understand dateTime is an annoying thing to have to parse but I can’t be alone in thinking this way?
1 Like
I’m with you
Go is certainly unique in their approach to the time package and it’s definitely a bit of a hassle the first few times you use it.
1 Like
100% agree
It’s definitely worth creating some constants for the formats. In my solution, I put
const shortLayout = "1/2/2006 15:04:05"
const mediumLayout = "January 2, 2006 15:04:05"
const longLayout = "Monday, January 2, 2006 15:04:05"
and then
t, err := time.Parse(shortLayout, date)
3 Likes
While not necessarily applicable top this exercise, do note the time package itself has some similar constants.
2 Likes
Really awesome feedback there. Thanks gents.