Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
time: make Time.Sub clamp result #5011
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.