Skip to content
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: Give an example to get UNIX_EPOCH in seconds #44301

Closed
wants to merge 3 commits into from

Conversation

kallisti5
Copy link
Contributor

A tiny doc improvement. I always end up looking for EPOCH and always find obtaining it less-than-obvious from the docs.

@rust-highfive
Copy link
Contributor

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@sfackler
Copy link
Member

sfackler commented Sep 3, 2017

r? @GuillaumeGomez

/// # Examples
///
/// ```no_run
/// use std::time::{SystemTime,UNIX_EPOCH};
Copy link
Member

Choose a reason for hiding this comment

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

Use missing whitespace after comma.

/// ```no_run
/// use std::time::{SystemTime,UNIX_EPOCH};
///
/// let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();
Copy link
Member

Choose a reason for hiding this comment

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

Can please not use unwrap? We try to avoid it in the docs.

@kallisti5
Copy link
Contributor Author

Done. I know unwraps are generally not great with docs.. but if the system time is before UNIX_EPOCH (which shouldn't even be possible in most modern BIOS's, a panic is well deserved.)

Adjusted to show the panic occurring.

/// # Examples
///
/// ```no_run
/// use std::time::{SystemTime, UNIX_EPOCH};
Copy link
Member

Choose a reason for hiding this comment

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

You could just rewrite it as follows:

match SystemTime::now().duration_since(UNIX_EPOCH) {
    Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", now.as_secs()),
    Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}

@GuillaumeGomez
Copy link
Member

Once updated, please squash your commits.

@kallisti5
Copy link
Contributor Author

Well, since squashing involves rebasing and you can't rewrite remote histories... i'm just going to open another PR :-|

@kallisti5 kallisti5 closed this Sep 4, 2017
@Mark-Simulacrum
Copy link
Member

It's fine to squash and push to the PR branch. At least for Rust's repositories, PR branches are generally not considered "public" in that others' have pulled them and as such can be freely rewritten and force pushed at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants