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: i find some problems when using addDate to do date calculation #66374

Closed
Gao-Vidor opened this issue Mar 18, 2024 · 1 comment
Closed

Comments

@Gao-Vidor
Copy link

Gao-Vidor commented Mar 18, 2024

Go version

go version go1.20.5 darwin/amd64

go env :

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/Library/Caches/go-build"
GOENV="/Users/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"

What did i do?

package main

import (
"fmt"
"time"
)

func main() {
d := time.Date(2023, 1, 30, 23, 0, 0, 0, time.Local)
dd := d.AddDate(0, 1, 0)
fmt.Println(dd)
}

What did i see happen?

2023-03-02 23:00:00 +0000 UTC

What did i expect to see?

In my intuitive understanding, I believe the output should be 2023-02-28 (9) 23:00:00 +0000 UTC

@ALTree
Copy link
Member

ALTree commented Mar 18, 2024

This is working as intended. From the AddDate documentation:

AddDate normalizes its result in the same way that Date does, so, for example, adding one month to October 31 yields December 1, the normalized form for November 31.

Closing here since this is not a bug.

@ALTree ALTree closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants