Time in Go
bl.ocks.org
Time in Go
1–10 of 80 posts
Re: Time in Go
#2Re: Time in Go
#3Golang to me has the best time manipulation I ever seen, wannabe change the timezone, easy as eat pie, wanna add seconds? No prob, wanna compare dates? No biggie
Re: Time in Go
#4Golang to me has the best time manipulation I ever seen, wannabe change the timezone, easy as eat pie, wanna add seconds? No prob, wanna compare dates? No biggie
I'm new to the language but I'm really happy with the simplicity and the design decisions made by the core team.
Re: Time in Go
#5As someone who has written a lot of Go for years, I am always very quick to say that "time" is my favorite Go standard library. I love it.
The "time" library is to Go what the "requests" [non-standard] library is to Python, in terms of a great API and simplicity. For some reason in every other language I've used (important, I don't know every time library! :P) the time library has always been adequate, but not much else.
I think Python's "datetime" is a great example of a not great time library. At one point I was writing Python every day for a couple years. During that time, I could never ever remember the API for datetime, despite it being able to do what I needed to do well enough. I always had to open the docs. I think this is an example of an adequate library that just doesn't have a great API.
Or, take the more generic problem of: I have a time, I have a duration, how do I tell if that duration has passed? Most developers I know (including myself) stumble on this for some period of time (see what I did there?), remembering what do I add to what and is it a greater than or a less than or do I subtract, etc. It is an easy problem, but always seems to require a little bit of thinking.
Go's "time" library is nothing like this.
Go's "time" library you will remember the API, it is intuitive. You can even guess it after writing Go for some period of time. It is that easy (ignoring the constants and non-standard printf-like function in it).
Go's "time" comparison/arithmetic is incredible. Comparing times? Determining expiration? You'll almost never get this wrong the first time. (But write tests anyways)
What I'm trying to say is: even if you don't like Go, take a look at how Go's "time" library works. I think it would be valuable for other languages. Other languages can probably even do it better (imagining better type systems around units), but I've never seen an API that feels as right for manipulating time as Go's time stdlib.
Re: Time in Go
#6Golang to me has the best time manipulation I ever seen, wannabe change the timezone, easy as eat pie, wanna add seconds? No prob, wanna compare dates? No biggie
True, and for most cases the parsing is great too, but once you get off the beaten path of standard time formats, parsing times can be annoying.
Re: Time in Go
#7Earlier quoted context omitted.
True, and for most cases the parsing is great too, but once you get off the beaten path of standard time formats, parsing times can be annoying.
Do you have any examples of annoying to parse time formats?
Because it seems that golang does not recognize the abbreviations at all.
Re: Time in Go
#8More languages should copy Go's time library. As someone who has written a lot of Go for years, I am always very quick to say that "time" is my favorite Go standard library. I love it. The "time" library is to Go what the "requests" [non-standard] library is to Python, in terms of a great API and simplicity. For some reason in every other language I've used (important, I don't know every time library! :P) the time li…
Using a preset date (the 2006-01-02) instead of format strings was really inspired; it took me about 10 minutes of staring at the documentation to understand how it worked, but it's a lot more readable once you get it.
Re: Time in Go
#9and it did NOT work as expected: http://play.golang.org/p/Xd9oEeSffd
(timezone offset is zero)
Re: Time in Go
#10Earlier quoted context omitted.
True, and for most cases the parsing is great too, but once you get off the beaten path of standard time formats, parsing times can be annoying.
Do you have any examples of annoying to parse time formats?
Still, this is the only issue I have with the time library, and even that has only bothered me a couple of times in 3 years of work, so no biggie. Other than that it's indeed the best time library I've ever worked with.