-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #![feature(duration_constants)] | ||
| #![feature(time_systemtime_limits)] | ||
|
|
||
| use std::fmt::Debug; | ||
| use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; | ||
|
|
@@ -237,9 +238,27 @@ fn system_time_duration_since_max_range_on_unix() { | |
| let min = SystemTime::UNIX_EPOCH - (Duration::new(i64::MAX as u64 + 1, 0)); | ||
| let max = SystemTime::UNIX_EPOCH + (Duration::new(i64::MAX as u64, 999_999_999)); | ||
|
|
||
| assert_eq!(min, SystemTime::MIN); | ||
| assert_eq!(max, SystemTime::MAX); | ||
|
|
||
| let delta_a = max.duration_since(min).expect("duration_since overflow"); | ||
| let delta_b = min.duration_since(max).expect_err("duration_since overflow").duration(); | ||
|
|
||
| assert_eq!(Duration::MAX, delta_a); | ||
| assert_eq!(Duration::MAX, delta_b); | ||
| } | ||
|
|
||
| #[test] | ||
| fn system_time_max_min() { | ||
| // First, test everything with checked_* and Duration::ZERO. | ||
| assert_eq!(SystemTime::MAX.checked_add(Duration::ZERO), Some(SystemTime::MAX)); | ||
| assert_eq!(SystemTime::MAX.checked_sub(Duration::ZERO), Some(SystemTime::MAX)); | ||
| assert_eq!(SystemTime::MIN.checked_add(Duration::ZERO), Some(SystemTime::MIN)); | ||
| assert_eq!(SystemTime::MIN.checked_sub(Duration::ZERO), Some(SystemTime::MIN)); | ||
|
|
||
| // Now do the same again with checked_* but try by ± a single nanosecond. | ||
| assert!(SystemTime::MAX.checked_add(Duration::new(0, 1)).is_none()); | ||
| assert!(SystemTime::MAX.checked_sub(Duration::new(0, 1)).is_some()); | ||
| assert!(SystemTime::MIN.checked_add(Duration::new(0, 1)).is_some()); | ||
| assert!(SystemTime::MIN.checked_sub(Duration::new(0, 1)).is_none()); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concern: This only tests our internal +/- logic, but doesn't actually interface with the system. Could we add a test in That would give me a higher confidence that they're correct, or at least force us to consider what "correct" means in this context, I don't actually think this will work on platforms where
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea but this is not possible with an FS test unfortunately, because the boundaries for FS timestamps differ based on the actual FS and are not bound to a For example, the range on my APFS is See: https://dfdatetime.readthedocs.io/en/latest/sources/Date-and-time-values.html
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by "this" (or "work") :-). According to my reading of One can also observe that Functions that try to interface with the OS will have to do "something" with the 64-bit value. I haven't investigated what that is. All of this is true today. This MR doesn't touch it. If this is a bug, it's a pre-existing bug. I think we don't want (Eited to fix a u64 that ought to have been i64, and fix parens.)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My feelings exactly! I see
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
True, but these interactions and limits probably weren't thought of that much before, which is why it makes sense to consider them now.
I disagree. I think it makes sense to have For the platforms that have a 32-bit signed Once that day comes though, I think it makes much more sense that they start returning Footnotes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The current range of We have the following options:
If it is desirable to have a separate value which represents the maximum
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that option 2 is bad, and that 3 is preferable to that, but...
I disagree that this isn't an option. It isn't defined anywhere (to my knowledge) that such an operation is supported? Just because the current behaviour is observable by adding to Or do you know of a concrete case where current users would be broken by
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I disagree there. To me, In other words: A person using |
||
Uh oh!
There was an error while loading. Please reload this page.