Uh oh!
There was an error while loading. Please reload this page.
std/time: Give an example to get UNIX_EPOCH in seconds - #44301
Conversation
rust-highfive
commented
Sep 3, 2017
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
sfackler
commented
Sep 3, 2017
| /// # Examples | ||
| /// | ||
| /// ```no_run | ||
| /// use std::time::{SystemTime,UNIX_EPOCH}; |
There was a problem hiding this comment.
Use missing whitespace after comma.
| /// ```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.
Can please not use unwrap? We try to avoid it in the docs.
kallisti5
commented
Sep 4, 2017
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.
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
commented
Sep 4, 2017
Once updated, please squash your commits. |
kallisti5
commented
Sep 4, 2017
Well, since squashing involves rebasing and you can't rewrite remote histories... i'm just going to open another PR :-| |
Mark-Simulacrum
commented
Sep 4, 2017
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.