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

proposal: Go 2: time: change the Time behavior #30086

Closed
tredoe opened this issue Feb 5, 2019 · 7 comments
Closed

proposal: Go 2: time: change the Time behavior #30086

tredoe opened this issue Feb 5, 2019 · 7 comments
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Milestone

Comments

@tredoe
Copy link

tredoe commented Feb 5, 2019

  1. When you set a time with layout "15:04:05", then the date side is set to value "0000-01-01"; but the zero value of time.Time{}is set to "0001-01-01". So, to get a better consistence, it should get the same zero value ("0001-01-01").

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

  1. 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".

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

@gopherbot gopherbot added this to the Proposal milestone Feb 5, 2019
@andybons andybons added the v2 A language change or incompatible library change label Feb 5, 2019
@ianlancetaylor
Copy link
Contributor

These changes will presumably break some working code in ways that are very hard to detect, which carries a cost. The second suggestion in particular seems completely arbitrary to me. What is the benefit of making these changes?

@tredoe
Copy link
Author

tredoe commented Feb 5, 2019

The benefit would be to get a consistent modification of data set by the user, to avoid unexpected results at working with data related to dates.

@ianlancetaylor
Copy link
Contributor

I have no intuition that "2010-01-00" should be "2010-01-01". In fact to me it seems intuitive that "2010-01-00" is "the before 2010-01-01", and so "2009-12-31" seems correct.

@tredoe
Copy link
Author

tredoe commented Feb 6, 2019

The issue is that it changes three data.

Instead of be handled with "before of", it could be handled thinking in both minimum and maximum values for a field:

  • Whether the minimum of a field (year, month, day) is one, then whatever value lesser to 1 could be converted to 1.
  • And for maximum values (9999 for year, 12 for month, 29/30/31 for day), then the values greater than those, should be changed to the maximum value.

@ianlancetaylor
Copy link
Contributor

I think that suggested change would be strictly worse than the current behavior, because it would make it much harder to write code like time.Date(t.Year(), t.Month(), t.Day() - 1, 0, 0, 0, 0, t.Location()) to get the day before.

@antong
Copy link
Contributor

antong commented Feb 7, 2019

In my opinion the current time.Date() function is useful and clearly documented. Its usefulness can be seen for instance in how time.AddDate() is implemented. Changing this will break existing code and reduce the usefulness, while the suggested prenormalization can easily be done in a wrapper function by the user if really needed.

@ianlancetaylor
Copy link
Contributor

The current behavior is documented and works and is not clearly wrong. Changing it will break existing programs for a very small benefit. We are not going to do this.

@golang golang locked and limited conversation to collaborators Feb 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

5 participants