Skip to content

update documentation for UNIX_EPOCH and comparison between SystemTimes to clarify handling of failure#151685

Open
david-d-h wants to merge 1 commit intorust-lang:mainfrom
david-d-h:main
Open

update documentation for UNIX_EPOCH and comparison between SystemTimes to clarify handling of failure#151685
david-d-h wants to merge 1 commit intorust-lang:mainfrom
david-d-h:main

Conversation

@david-d-h
Copy link
Contributor

@david-d-h david-d-h commented Jan 26, 2026

This documentation change is meant to clarify that SystemTimes may (platform-dependently) be "less" than the UNIX_EPOCH and a developer ought to take care in comparing between the two, as this might lead to an error. It also explicitly mentions SystemTimeError::duration for when such an error does occur.

I'm not sure on whether it would be helpful to document such a thing on the SystemTime itself rather than on it's methods and assoc consts? Perhaps it could be, since the documentation for the item also mentions the UNIX_EPOCH anchor and encourages comparisons with it. Anyways, open to suggestions.

closes #52522

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 26, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2026

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

///
/// If successful, <code>[Ok]\([Duration])</code> is returned where the duration represents
/// the amount of time elapsed from the specified measurement to this one.
/// If `self` lies further ahead, or at the same point in time compared to `earlier`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a very roundabout way to express that earlier is not later than self.

/// Also note that the `UNIX_EPOCH` may not be equal to the minimum representable
/// value of [`SystemTime`]; [`SystemTime::MIN`] is platform-dependent.
/// Thus, the developer ought to anticipate that comparison with `UNIX_EPOCH` may
/// result in "failure", even within legitimate, real-world use-cases.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the complaints was that pretending that the Err variant represents a failure contributes to wrong interpretation of the return value of this function.

/// Returns an [`Err`] if `earlier` is later than `self`, and the error
/// contains how far from `self` the time is.
/// Returns an [`Err`] if `earlier` is later than `self`, where the error contains how far
/// from `self` the time is, publicly exposed through [`SystemTimeError::duration`].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what "publicly exposed through" is supposed to mean.

/// returned where the duration represents the amount of time elapsed from
/// This function may return a [`SystemTimeError`] as the underlying system clock
/// is susceptible to drift and updates (e.g., the system clock could go backwards),
/// so this function might not always succeed. If successful, an [`Ok::<Duration>`](Ok)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of the failure/success analogy which should be avoided.

@joboet
Copy link
Member

joboet commented Feb 7, 2026

@rustbot author
I agree with hkBst's comments (thanks 😉).

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 7, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SystemTime conversions invite programmer error

4 participants