Description
Go version
go version go1.21.4 linux/amd64
What operating system and processor architecture are you using (go env
)?
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/myyrakle/.cache/go-build'
GOENV='/home/myyrakle/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/myyrakle/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/myyrakle/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/myyrakle/Codes/Go/just_test/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build612091784=/tmp/go-build -gno-record-gcc-switches'
What did you do?
As follows, create a time object by entering the maximum and minimum values of int64 and output it as a string.
package main
import (
"fmt"
"math"
"time"
)
func main() {
fmt.Println(time.Unix(math.MaxInt64, 0)) // 292277026596-12-05 00:30:07 +0900 KST
fmt.Println(time.Unix(math.MinInt64, 0)) // 292277026596-12-04 23:58:00 +0827 LMT
}
What did you expect to see?
I expected max to be a very large time value, and min to be a negative time value similar to max.
What did you see instead?
In the case of the maximum value, very large time values are output as positive numbers, as intended.
However, for the minimum value, a positive number is output, even though it should be a negative value.
When I tested it myself, the minimum value that was actually output as a negative number was time.Unix(math.MinInt64+8139423736, 0)
.
An underflow occurs starting from time.Unix(math.MinInt64+8139423735, 0)
.
However, it doesn't seem to be specified in the document.
Is this behavior by design? Or is this a bug or undefined behavior?