4 ms·
When I realised I couldn't divide a time period by a number or integer, the penny dropped that different languages excel at different things.
by dm319 6y ago
When I realised I couldn't divide a time period by a number or integer, the penny dropped that different languages excel at different things.
- icholy 6y agoAre you talking about `time.Duration`? Because you can definitely do that.
- robbyt 6y agoBut don't try to use BC dates with time.Duration, because they don't work!
- dm319 6y agoHas that changed? I couldn't before!
- TheDong 6y agoYou have been able to divide a time.Duration by an integer since before go 1.0. As you can see in the stdlib, time.Duration is just an int64 (https://golang.org/pkg/time/#Duration https://golang.org/pkg/time/#Duration). You do have to cast the integer to a time.Duration sometimes. Here's a playground showing cases where it works and cases where it require a cast: https://play.golang.org/p/6Pbqrz8ZZ3t https://play.golang.org/p/6Pbqrz8ZZ3t
- dm319 6y agoSo I'm not wrong then? You're needing to cast an Int into a time duration in order to divide a time duration?