forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Add SystemTime::{MIN, MAX} #1
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f508099 to
10b48fb
Compare
ijackson
reviewed
Nov 11, 2025
library/std/src/time.rs
Outdated
Comment on lines
516
to
517
| /// This value differs a lot between platforms, but it is ensured that any | ||
| /// positive addition to [`SystemTime::MAX`] will fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| /// This value differs a lot between platforms, but it is ensured that any | |
| /// positive addition to [`SystemTime::MAX`] will fail. | |
| /// This value differs a lot between platforms, but it is always the case that any | |
| /// positive addition to [`SystemTime::MAX`] will fail. |
library/std/src/time.rs
Outdated
|
|
||
| /// Represents the minimum value representable by [`SystemTime`] on this platform. | ||
| /// | ||
| /// This value differs a lot between platforms, but it is ensured that any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| /// This value differs a lot between platforms, but it is ensured that any | |
| /// This value differs a lot between platforms, but it is always the case that any |
This commit introduces two new constants to SystemTime: `MIN` and `MAX`,
whose value represent the maximum values for the respective data type,
depending upon the platform.
Technically, this value is already obtainable during runtime with the
following algorithm: Use `SystemTime::UNIX_EPOCH` and call `checked_add`
(or `checked_sub`) repeatedly with `Duration::new(0, 1)` on it, until it
returns None. Mathematically speaking, this algorithm will terminate
after a finite amount of steps, yet it is impractical to run it, as it
takes practically forever.
Besides, this commit also adds a unit test. Concrete implementation
depending upon the platform is done in later commits.
In the future, the hope of the authors lies within the creation of a
`SystemTime::saturating_add` and `SystemTime::saturating_sub`, similar
to the functions already present in `std::time::Duration`. However, for
those, these constants are crucially required, thereby this should be
seen as the initial step towards this direction.
This feature (and a related saturating version of `checked_{add, sub}`
has been requested multiple times over the course of the past few years,
most notably:
* rust-lang#100141
* rust-lang#133525
* rust-lang#105762
* rust-lang#71224
* rust-lang#45448
* rust-lang#52555
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for for HermitOS, which itself is more or less identical to the Unix implementation.
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for sgx. The implementation uses a `Duration` to store the Unix time, thereby implying `Duration::ZERO` and `Duration::MAX` as the limits.
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for solid. The implementation uses a `time_t` to store the system time within a single value (i.e. no dual secs/nanosecs handling), thereby implying its `::MIN` and `::MAX` values as the respective boundaries.
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for the UEFI platform. UEFI has a weird way to store times, i.e. a very complicated struct. The standard proclaims "1900-01-01T00:00:00+0000" to be the lowest possible value and `MAX_UEFI_TIME` is already present for the upper limit.
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for wasip1. Similar to sgx, a `Duration` is used to store the time, thereby depending on those limits.
See the wasip1 implementation, which is functionally equivalent.
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for the Windows platform. Windows is weird. The Win32 documentation makes no statement on a maximum value here. Next to this, there are two conflicting types: `SYSTEMTIME` and `FILETIME`. Rust's Standard Library uses `FILETIME`, whose limit will (probably) be `i64::MAX` packed into two integers. However, `SYSTEMTIME` has a lower-limit.
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for xous. It is similar to wasip1, wasip2, and sgx in the sense of once again using a `Duration` to store the value.
This commit implements `SystemTime::MIN` and `SystemTime::MAX` for all unsupported platforms. Unsupported platforms store a `SystemTime` in a `Duration`, just like wasip1, sgx, and a few others, thereby implying `Duration::ZERO` and `Duration::MAX` as the respective limits.
10b48fb to
143f4ce
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This merge request introduces two new constants to
SystemTime:MINandMAX, whose values represent the maximum values for the respective data type, depending upon the platform.Technically, this value is already obtainable during runtime with the following algorithm:
Use
SystemTime::UNIX_EPOCHand callchecked_add(orchecked_sub) repeatedly withDuration::new(0, 1)on it, until it returns None.Mathematically speaking, this algorithm will terminate after a finite amount of steps, yet it is impractical to run it, as it takes practically forever.
Besides, this commit also adds a unit test to verify those values represent the respective minimum and maximum, by letting a
checked_addandchecked_subon it fail.In the future, the hope of the authors lies within the creation of a
SystemTime::saturating_addandSystemTime::saturating_sub, similar to the functions already present instd::time::Duration.However, for those, these constants are crucially required, thereby this should be seen as the initial step towards this direction.
With this change, implementing these functions oneself outside the standard library becomes feasible in a portable manner for the first time.
This feature (and a related saturating version of
checked_{add, sub}has been requested multiple times over the course of the past few years, most notably:std::time::Instant::saturating_duration_since()? rust-lang/rust#133525This is a draft before it gets upstreamed, cc @ijackson.