-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
src/libstd/time/mod.rs
Outdated
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// use std::time::{SystemTime,UNIX_EPOCH}; |
There was a problem hiding this comment.
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.
src/libstd/time/mod.rs
Outdated
/// ```no_run | ||
/// use std::time::{SystemTime,UNIX_EPOCH}; | ||
/// | ||
/// let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(); |
There was a problem hiding this comment.
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.
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}; |
There was a problem hiding this comment.
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!"),
}
Once updated, please squash your commits. |
Well, since squashing involves rebasing and you can't rewrite remote histories... i'm just going to open another PR :-| |
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. |
A tiny doc improvement. I always end up looking for EPOCH and always find obtaining it less-than-obvious from the docs.