3 ms·
As long as you don’t need to do `hours := 8` and `+= hours * time.Hour`. Incredibly the only way to get that multiplication to work is to cast `hours` to a `tim
by pansa2 1y ago
As long as you don’t need to do `hours := 8` and `+= hours * time.Hour`. Incredibly the only way to get that multiplication to work is to cast `hours` to a `time.Duration`.
In Go, `int * Duration = error`, but `Duration * Duration = Duration`!
- porridgeraisin 1y agoThat is consistent though. Constants take type based on context, so 8 * time.Hour has 8 as a time.Duration. If you have an int variable hours := 8, you have to cast it before multiplying. This is also true for simple int and float operations. f := 2.0 3 * f is valid, but x := 3 would need float64(x)*f to be valid. Same is true for addition etc.
- throwawaymaths 1y agoIt's also completely insane if youve ever done any scientific work.
- porridgeraisin 1y agoApart from the extra verbosity, what gives?