Skip to content

Document arithmetic operations on Instant #45448

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

Open
bluss opened this issue Oct 22, 2017 · 3 comments
Open

Document arithmetic operations on Instant #45448

bluss opened this issue Oct 22, 2017 · 3 comments
Labels
A-time Area: Time C-enhancement Category: An issue proposing an enhancement or a PR with one. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@bluss
Copy link
Member

bluss commented Oct 22, 2017

Some questions that have come up about using Instants:

  1. What meaning does Instant -= Duration have?
  2. What are the preconditions on the instant and the duration, so that it does not panic or cause arithmetic overflow assertions? One user noticed that instant -= duration can trip this assertion (specifically on Windows).
@bluss bluss added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 22, 2017
@retep998
Copy link
Member

The zero point of Instant is not specified and could be any time before the start of the process. If you want to ensure that you do not get any underflow errors, then do not attempt to create an Instant representing a time before the process was spawned.

@TimNN TimNN added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 24, 2017
@steveklabnik steveklabnik added the P-medium Medium priority label Oct 31, 2017
@steveklabnik steveklabnik removed the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Jan 10, 2019
@steveklabnik
Copy link
Member

@rust-lang/libs: if you can articulate which aspects of this API are guaranteed, I'm happy to document them.

@sfackler
Copy link
Member

  1. What meaning does Instant -= Duration have?

It causes Instant to have the value of an Instant created Duration time before its original value.

  1. What are the preconditions on the instant and the duration, so that it does not panic or cause arithmetic overflow assertions?

Instant currently wraps the platform-specific monotonic time type, so the overflow bounds depend on the system. Some probably safe assumptions would be to not create Instants from before your process started or Instants more than a century or so in the future. I don't know what we specifically want to guarantee here though.

@workingjubilee workingjubilee added the A-time Area: Time label Apr 25, 2021
@bjorn3 bjorn3 added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools and removed A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-time Area: Time C-enhancement Category: An issue proposing an enhancement or a PR with one. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants