Hacker News new | ask | show | jobs
by icholy 1913 days ago
Are you talking about `time.Duration`? Because you can definitely do that.
2 comments

Has that changed? I couldn't before!
You 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). 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

So I'm not wrong then? You're needing to cast an Int into a time duration in order to divide a time duration?
Go requires explicit type conversions. If that was your original point, it was very poorly worded.
A time unit can only be divided by a time unit (or integer converted to a time unit)? That doesn't make sense to an engineer or mathematician.
But don't try to use BC dates with time.Duration, because they don't work!