Skip to content

time: make Time.Sub clamp result #5011

@rsc

Description

@rsc
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions