-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Consider making std::time::SystemTime platform-independent #44394
Copy link
Copy link
Open
Labels
A-timeArea: TimeArea: TimeC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-timeArea: TimeArea: TimeC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
It was found in #44220 (comment) that certain systems in Tier-2 support still uses a 32-bit
time_t.SystemTimeon 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
SystemTimestruct is a wrapper aroundtimespecon Unix and Redox, andFILETIMEon Windows. Nevertheless, the public API involvingSystemTimenever exposes this detail:You cannot construct a
SystemTimefrom atimespec/FILETIME, nor the other way roundThe only place where
SystemTimeinteracts with the OS are being returnedSystemTime::now, returning aSystemTimeMetadata::{modified, accessed, created}, returning anio::Result<SystemTime>There are no OS-specific APIs reading a
SystemTime.This means expanding the precision and range of
SystemTimeis safe. In fact, we could even make theSystemTimestructure itself platform-agnostic, just likeDuration: