▲ | pansa2 4 days 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 3 days ago | parent [-] | ||||||||||||||||
That 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.
is valid, but x := 3 would need float64(x)*f to be valid. Same is true for addition etc. | |||||||||||||||||
|