-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std::time inconsistencies #48980
Comments
|
Moreover, we've run into this issue on Windows too. let times = [
UNIX_EPOCH,
UNIX_EPOCH + Duration::new(13, 23),
SystemTime::now(),
SystemTime::now() + Duration::new(17, 15),
UNIX_EPOCH + Duration::new(0, u32::max_value()),
UNIX_EPOCH + Duration::new(i64::max_value() as u64, 0),
UNIX_EPOCH + Duration::new(i64::max_value() as u64, 999_999_999),
UNIX_EPOCH + Duration::new(i64::max_value() as u64 - 1, 1_000_000_000),
UNIX_EPOCH + Duration::new(i64::max_value() as u64 - 4, 4_000_000_000),
UNIX_EPOCH + Duration::new(i64::max_value() as u64 - 4, u32::max_value()),
]; I also think that the behavior must be consistent on all three main platforms, at least. This issue might be related: #44394 |
|
@sfackler I see your point, but what we're asking for, is to make behaviour consistent on every platform. |
The behavior can't be consistent across platforms, because this is inherently platform specific behavior. Different platforms support different ranges and have different precisions. |
At the very least, this ought to be better documented. There aren't any explicit warnings that On the other hand, unless the documentation regarding |
But yes, better documentation is a good idea. |
This appears to be because on non-mac unix systems |
@Vurich no, |
@retep007 encountered this error recently. When doing pure time calculations one would expect that adding a nanosecond would give a duration of 1 nanosecond.
does not return a nanosecond on windows. Is there any argument for not making the Instant nanosecond-precise regardless of platform and just truncate it when doing syscalls? |
@retep998 one for you ☝️ 😅 |
I'm not sure, if my problem is worth it's own issue: |
I encountered something strange on Windows 10. In an unittest with the following code let t = Instant::now() - Duration::from_secs(3600); I get some let d = Duration::from_secs(3600);
let mut now = Instant::now();
now -= d;
let t = now; After that I can move my code back to let t = Instant::now() - Duration::from_secs(3600); and it starts working again. I am really wondering what is going on compiler and/or OS side to have such behavior. |
@ririsoft This is platform specific limitation and there is not much that can be done about it. |
This is it, thanks a bunch. For my use case |
I can add the documentation about the system-specificities but I'm not exactly clear on where it should go: |
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fixes rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fixes rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
…ies, r=shepmaster Complete the std::time documentation to warn about the inconsistencies between OS Fixes rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
When investigating one of the issues in parity-ethereum repo I noticed several inconsistencies in
std::time
.I prepared two short snippets
snippet A
snippet B
Both of the attached snippets are properly executed on linux (gist), but they panic on macos.
snippet A panics with
'overflow when adding duration to instant'
snippet B panics with
'overflow converting duration to nanoseconds'
This is an inconsistent behaviour of standard library and I believe that above snippets should panic (or work) on all platforms in the same way
The text was updated successfully, but these errors were encountered: