I cannot confirm this: The following code returns 100ns.
EDIT: Irrelevant because constants are typeless. See @Rio_M’s reply.
var t1 time.Duration
t1 = 10
fmt.Println(t1 * 10)
// Output: 100ns
Can you paste the code that errors out when multiplying a duration with an int? I suspect there might be a different reason for the error.
It is true that Go has no types like “SquareDuration”, but I don’t know of any programming language that incorporates SI units into its type system, including square and cube variants of each SI unit, as well as the resulting conversions when doing multiplications
You can always define your own SI types if required, for example:
type feet int
type squarefeet int
func (f feet) times(ft feet) squarefeet {
return squarefeet(f*ft)
}
func main() {
var f1, f2 feet
f1 = 7
f2 = 6
fmt.Println(f1.times(f2))
}