Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: In time.Unix, an underflow occurs when you put a large negative value in the seconds area #64514

Open
myyrakle opened this issue Dec 2, 2023 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@myyrakle
Copy link

myyrakle commented Dec 2, 2023

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
}

image

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?

@mauri870 mauri870 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 2, 2023
@mauri870
Copy link
Member

mauri870 commented Dec 2, 2023

kindly cc @rsc, per https://dev.golang.org/owners

@AlexanderYastrebov
Copy link
Contributor

Related issues #56909 and #63844

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants