Description
What version of Go are you using (go version
)?
1.11.5
Does this issue reproduce with the latest release?
Yes the playground has this too
The playground uses the latest stable release of Go.
The current version is go1.12.5.
What operating system and processor architecture are you using (go env
)?
Windows, linux,
What did you do?
https://play.golang.org/p/N9x0jGCS8XC
package main
import (
"fmt"
"time"
"math"
)
func main() {
d:=make([]int64,15)
for i:=range(d){
d[i]=1*int64(math.Pow(10,float64(i)))
fmt.Printf("duration%d %v\n",i, d[i])
}
//d[0]=1
//d[1]=1000000000 //the max
//d[2]=100000000000//overflow
for i,j:=range(d){
t:=time.Duration(j)*time.Second
fmt.Printf("duration%d value int64 %d, %v\n",i,j, t)
}
}
What did you expect to see?
time.Duration correctly working with 64 bit values
What did you see instead?
time.Duration accepting an 64 bit integer and overflowing.
From duration 10 onward
duration0 value int64 1, 1s
duration1 value int64 10, 10s
duration2 value int64 100, 1m40s
duration3 value int64 1000, 16m40s
duration4 value int64 10000, 2h46m40s
duration5 value int64 100000, 27h46m40s
duration6 value int64 1000000, 277h46m40s
duration7 value int64 10000000, 2777h46m40s
duration8 value int64 100000000, 27777h46m40s
duration9 value int64 1000000000, 277777h46m40s
duration10 value int64 10000000000, -2346317h47m53.709551616s
duration11 value int64 100000000000, 2157299h53m51.45224192s
duration12 value int64 1000000000000, 1076616h40m19.684212736s
duration13 value int64 10000000000000, 517975h34m9.423024128s
duration14 value int64 100000000000000, 55660h7m0.520689664s
###The problem
It accepts 64 bit integers but doesnt handle them correctly....It is misleading that you can put 64 bit integers in...but you shouldnt go beyond a 32bit integer....
Then make it a 32 bit integer....
type Duration int64