Skip to content

time AddDate(0, -1, 0) does not work for March. #31145

@happilymarrieddad

Description

@happilymarrieddad

What version of Go are you using (go version)?

$ go version
go version go1.12.1 linux/amd64

Does this issue reproduce with the latest release?

Yes, I tested it on golang.org and my local machine

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/nick/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/nick/Projects/Go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build101166364=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm trying to go back 1 month from March and I get a really weird result. It goes from March 30th to March 2nd. I'm assuming it's taking the number of days in February and subtracting that from March. It should take the number of days in March and subtract it.

https://play.golang.org/p/n2xvzVFnA4G

What did you expect to see?

It should have been a date in February at least. Momentjs, not I don't like javascript, sets it to February 28 which is a little weird but at least it's February.

What did you see instead?

It set it to March 2nd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions