4 ms·
I 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 h
by scubbo 4y ago
I 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?