-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Feature Request: saturating_add(Duration) for SystemTime / Instant #71224
Copy link
Copy link
Open
Labels
A-timeArea: TimeArea: TimeC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
Both SystemTime and Instant have checked_add(Duration), but no saturating_add(Duration).
This seems like an omission, as when doing math operations on time, a developer has to choose between:
- allowing for the (hopefully very remote) potential for overflows
- determining what to do with the
Nonecase of thechecked_add() - letting it
checked_add(long_duration).unwrap()panic after an overflow
Given that the SystemTime and Instant both opaquely wrap a platform-dependent structure, it's not clear what "far future" values are valid on a given platform (e.g. issue #44394), and what values a developer could correctly use with checked_add(long_duration).unwrap_or(...?).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-timeArea: TimeArea: TimeC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.