time: Wrong time.AddDate
calculation if months' last date is 31
#57139
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/CHijIVQtJS4
Try subtracting one month from any month whose last date is 31.
oneMonthBefore := now.AddDate(0, -1, 0)
What did you expect to see?
What did you see instead?
Hint: instead of going back 1 month, the result seems to subtract the
Now
date by the number of days in the previous month. Ex, 31 March goes back to 3 March, because February has 28 days. 31-28 = 3The text was updated successfully, but these errors were encountered: