-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Consider making std::time::SystemTime
platform-independent
#44394
Comments
What would the epoch be for this? Would we still use the platform specific epoch or would we have a platform agnostic epoch? |
I'd suggest everyone uses 1970 Jan 1st (Unix epoch) for consistency. Since the public APIs won't see the raw numbers at all, special-casing Windows to use 1601 Jan 1st as epoch is also possible. However converting a The range of Another choice is keep Windows to use |
Using the Unix Epoch for consistency would completely break any times on Windows from before the the unix epoch. If someone manually changes a file to be created in the 1600s, Rust better damn well support that. |
@retep998 How exactly does that break times before the epoch? |
@sfackler Oh, right. Anyway, this would still cause an increase in the size of |
@retep998 Sure, but there are no functions that set the file time using There is the |
@kennytm Maybe one day |
@retep998 those functions would return |
Since Windows represents time as a 64-bit value representing 100-ns intervals, this would only happen if you tried to set a file time that was:
Wanting to use these kinds of times to set file timestamps and other system operations (as in, other than just doing computations in pure-Rust land) seems very very unlikely in practice. |
@joshlf Trying to set a file time to any time before the Windows epoch would result in an error, not only 30K years before. |
Oh so file times can't be negative? Because the function that I linked to returns a signed integer. Do you know if the same limitation exists on Unix? |
@joshlf |
Gotcha, thanks! |
Triage: it's not clear to me what the conclusion of this discussion is, or if this is still desired or not. |
fwiw, if there is no reason to bind rust's This is causing problems for sequoia on platforms like i386 and armhf (where |
This is still a problem for Sequoia:
Internally, we store timestamps as our own type, which comes down to |
It was found in #44220 (comment) that certain systems in Tier-2 support still uses a 32-bit
time_t
.SystemTime
on them will suffer from the Year-2038 problem, and also cannot perform arithmetic for a duration >68 years. This introduces a portability hazard, in which on some systems the time arithmetic works normally, and in some more legacy system it suddenly panics.The
SystemTime
struct is a wrapper aroundtimespec
on Unix and Redox, andFILETIME
on Windows. Nevertheless, the public API involvingSystemTime
never exposes this detail:You cannot construct a
SystemTime
from atimespec
/FILETIME
, nor the other way roundThe only place where
SystemTime
interacts with the OS are being returnedSystemTime::now
, returning aSystemTime
Metadata::{modified, accessed, created}
, returning anio::Result<SystemTime>
There are no OS-specific APIs reading a
SystemTime
.This means expanding the precision and range of
SystemTime
is safe. In fact, we could even make theSystemTime
structure itself platform-agnostic, just likeDuration
:The text was updated successfully, but these errors were encountered: