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: add 1 month can sometimes add 2 months #10401

Closed
eclivus opened this issue Apr 9, 2015 · 2 comments
Closed

time: add 1 month can sometimes add 2 months #10401

eclivus opened this issue Apr 9, 2015 · 2 comments

Comments

@eclivus
Copy link

eclivus commented Apr 9, 2015

Hello,

This might not e related to Go itself, but I noticed that when incrementing a date month by month go sometimes leaps a month.

package main

import "fmt"
import "time"

func main() {
        date := time.Date(2013,time.January,31,23,59,59,0,time.UTC)
        fmt.Println(date.String())
        date = date.AddDate(0,1,0)
        fmt.Println(date.String())
}

Output:
2013-01-31 23:59:59 +0000 UTC
2013-03-03 23:59:59 +0000 UTC

Go version: go1.4.2 linux/amd64
System: Ubuntu 14.04.1
https://play.golang.org/p/5msN0bykp8

@robpike
Copy link
Contributor

robpike commented Apr 9, 2015

Working as intended. There is no February 31, so what happens here is reasonable. The behavior is even documented in the comment for AddDate - using almost exactly this example!

@robpike robpike closed this as completed Apr 9, 2015
@minux
Copy link
Member

minux commented Apr 9, 2015 via email

@mikioh mikioh changed the title Package time : add 1 month can sometimes add 2 months time: add 1 month can sometimes add 2 months Apr 9, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants