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: change values set at year-month layout #30075

Closed
tredoe opened this issue Feb 4, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@tredoe
Copy link

commented Feb 4, 2019

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

$ go version
go version go1.11.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

Set a year-month layout with a day to zero.
https://play.golang.org/p/NYVZhLzzicL

What did you expect to see?

When I set a time to time.Date(2010, time.January, 0, 0, 0, 0, 0, time.UTC), I expected to see 2010-01-01 00:00:00 +0000 UTC

What did you see instead?

2009-12-31 00:00:00 +0000 UTC

So, to get a valid date, it changes both year and month -which had been set by me-, instead of changing the day value to 1.

@antong

This comment has been minimized.

Copy link
Contributor

commented Feb 4, 2019

The manual says:

The month, day, hour, min, sec, and nsec values may be outside their usual ranges and will be normalized during the conversion. For example, October 32 converts to November 1.

So, your result is expected. A 0 day doesn't mean "not set", but one day less than the first day.

@tredoe

This comment has been minimized.

Copy link
Author

commented Feb 4, 2019

Although the documentation says it, it's inconsistent that a date set to "2010-1-0" been modified to "2009-12-31", when the most logical is that it been changed to "2010-1-1".

@andybons

This comment has been minimized.

Copy link
Member

commented Feb 4, 2019

Thanks for the report.

I understand that it can be confusing, but changing the behavior would break the Go 1 compatibility promise for the API. There's really nothing we can do. Sorry.

@andybons andybons closed this Feb 4, 2019

@tredoe

This comment has been minimized.

Copy link
Author

commented Feb 5, 2019

Added a proposal for Go 2: #30086

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.