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: make Time.Sub clamp result #5011

Closed
rsc opened this issue Mar 8, 2013 · 2 comments
Closed

time: make Time.Sub clamp result #5011

rsc opened this issue Mar 8, 2013 · 2 comments
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Mar 8, 2013

It happens that people subtract times more than 292 years apart (usually because of use
of the zero time), resulting in an incorrect Duration. The current subtraction does not
check for overflow so the duration wraps and may be positive or negative but is
certainly not correct.

We can't return the correct answer, but we could help avoid surprises by clamping the
result of Sub to -maxDuration or +maxDuration.

This would apply to time.Since as well.

Too late for Go 1.1. Probably do for Go 1.2.
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 17, 2013

Comment 1 by rickarnoldjr:

Attempted fix: https://golang.org/cl/10328043/
@robpike
Copy link
Contributor

@robpike robpike commented Jun 22, 2013

Comment 2:

This issue was closed by revision fc0b5ef.

Status changed to Fixed.

@rsc rsc added fixed labels Jun 22, 2013
@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.