Skip to content

time: AddDate with negative day changed behavior #68718

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

Closed
ianlancetaylor opened this issue Aug 2, 2024 · 3 comments
Closed

time: AddDate with negative day changed behavior #68718

ianlancetaylor opened this issue Aug 2, 2024 · 3 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Member

Go version

tip

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/iant/.cache/go-build'
GOENV='/home/iant/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/iant/gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/iant/gopath'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org'
GOROOT='/home/iant/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/iant/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.24-8659ad972f Wed Jul 24 00:40:06 2024 +0000'
GODEBUG=''
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/iant/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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-build3145192880=/tmp/go-build -gno-record-gcc-switches'

What did you do?

package main

import (
	"fmt"
	"time"
)

const secondsPerDay = 24 * 60 * 60

func main() {
	date := time.Date(1899, time.December, 31, 0, 0, 0, 0, time.UTC)
	uday := int(date.Unix() / secondsPerDay)
	t := time.Unix(0, 0).AddDate(0, 0, uday)
	fmt.Println(t)
}

What did you see happen?

This is the output from Go tip following https://go.dev/cl/586257.

11761121-01-20 00:00:00 +0000 UTC

What did you expect to see?

This is the output from Go 1.23:

1899-12-31 00:00:00 +0000 UTC
@ianlancetaylor
Copy link
Member Author

Testing a patch.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/602815 mentions this issue: time: restore support for large negative days in Date

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 2, 2024
@dmitshur dmitshur added this to the Go1.24 milestone Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants