3 ms·
I think every language I've used has annoyed me in how it handles dates and times. I've been tempted several times to sit down and repeatedly read Dershowitz a
by tzs 4y ago
I think every language I've used has annoyed me in how it handles dates and times.
I've been tempted several times to sit down and repeatedly read Dershowitz and Reingold's book "Calendrical Calculations" [1] cover to cover until I thoroughly understand it, and then write my own date and time library and port it to every language I use.
That would mean that when I learn a new language I'd have to take some time to port my date and time library, but looking at the languages I already know that would have been less than the time it took me to find and learn to deal with the quirks and annoyances in their libraries. I see no reason to believe that this will be different for any future languages I decide to learn.
Yes, I know this would be annoying to whoever has to take over my code when I'm gone, but I tend to stick around on projects until they reach end of life and so there almost never is anyone that comes after me.
[1] https://www.amazon.com/Calendrical-Calculations-Ultimate-Edward-Reingold-dp-1107683165/dp/1107683165/ https://www.amazon.com/Calendrical-Calculations-Ultimate-Edw...
- scubbo 4y agoI cordially invite you to look into the clusterfuck that is Go's treatment of date formatting. Everything else will seem clean and logical by comparison. Per https://golang.cafe/blog/golang-time-format-example.html https://golang.cafe/blog/golang-time-format-example.html: > Format returns a textual representation of the time value formatted according to layout, which defines the format by showing how the reference time, defined to be Mon Jan 2 15:04:05 -0700 MST 2006 would be displayed if it were the value; it serves as an example of the desired output. The same display rules will then be applied to the time value. So, for instance, if you want to format a date in ISO format (YYYT-MM-DDTHH:mm:ss), you have to figure out how the reference date would be displayed in that format ("2006-01-02T15:04:05"), and pass that as the format string.
- DangitBobby 4y agoI agree, of all the date formatting I've encountered, Go's is the worst.
- dragonwriter 4y agoIf I didn't know that was actually an accurate description of Go date formatting, I’d think it was satirical.
- xigoi 4y agoAnd durations: package main import "fmt" import "time" func main() { three_secs, _ := time.ParseDuration("3s") five := 5 fmt.Println(five * three_secs) // error: type mismatch fmt.Println(three_secs * three_secs) // 2500000h0m0s }
- scubbo 4y agoGood Lord. EDIT: Wait, I don't even understand how that can work, even in a broken way. Since I guessed 25000006060=9,000,000,000, I guessed that a "second duration" is really just a wrapper around `3,000` (ms) or `3,000,000` (ns) - but neither of those square to 9E9. In fact, the square root of 9E9 is a distinctly non-round number. What's going on here?