-
Notifications
You must be signed in to change notification settings - Fork 14k
Add SystemTime::{MIN, MAX} #148825
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
base: main
Are you sure you want to change the base?
Add SystemTime::{MIN, MAX} #148825
Conversation
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.
|
For what it is worth: Right now, the Rust ecosystem does weird stuff in order to figure out a limit.
|
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.
143f4ce to
481fe49
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
I'm pretty sure, though I could be wrong that this will need an ACP first before any work |
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()? #133525This is a draft to figure out some CI problems, before making this ready for review.