{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/50364","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/50364/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/50364/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/50364/events","html_url":"https://github.com/rust-lang/rust/pull/50364","id":319175707,"number":50364,"title":"Improve `Debug` impl of `time::Duration`","user":{"login":"LukasKalbertodt","id":7419664,"avatar_url":"https://avatars1.githubusercontent.com/u/7419664?v=4","gravatar_id":"","url":"https://api.github.com/users/LukasKalbertodt","html_url":"https://github.com/LukasKalbertodt","followers_url":"https://api.github.com/users/LukasKalbertodt/followers","following_url":"https://api.github.com/users/LukasKalbertodt/following{/other_user}","gists_url":"https://api.github.com/users/LukasKalbertodt/gists{/gist_id}","starred_url":"https://api.github.com/users/LukasKalbertodt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LukasKalbertodt/subscriptions","organizations_url":"https://api.github.com/users/LukasKalbertodt/orgs","repos_url":"https://api.github.com/users/LukasKalbertodt/repos","events_url":"https://api.github.com/users/LukasKalbertodt/events{/privacy}","received_events_url":"https://api.github.com/users/LukasKalbertodt/received_events","type":"User","site_admin":false},"labels":[{"id":583426710,"url":"https://api.github.com/repos/rust-lang/rust/labels/S-waiting-on-review","name":"S-waiting-on-review","color":"d3dddd","default":false},{"id":211668062,"url":"https://api.github.com/repos/rust-lang/rust/labels/T-libs","name":"T-libs","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":{"login":"KodrAus","id":6721458,"avatar_url":"https://avatars0.githubusercontent.com/u/6721458?v=4","gravatar_id":"","url":"https://api.github.com/users/KodrAus","html_url":"https://github.com/KodrAus","followers_url":"https://api.github.com/users/KodrAus/followers","following_url":"https://api.github.com/users/KodrAus/following{/other_user}","gists_url":"https://api.github.com/users/KodrAus/gists{/gist_id}","starred_url":"https://api.github.com/users/KodrAus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KodrAus/subscriptions","organizations_url":"https://api.github.com/users/KodrAus/orgs","repos_url":"https://api.github.com/users/KodrAus/repos","events_url":"https://api.github.com/users/KodrAus/events{/privacy}","received_events_url":"https://api.github.com/users/KodrAus/received_events","type":"User","site_admin":false},"assignees":[{"login":"KodrAus","id":6721458,"avatar_url":"https://avatars0.githubusercontent.com/u/6721458?v=4","gravatar_id":"","url":"https://api.github.com/users/KodrAus","html_url":"https://github.com/KodrAus","followers_url":"https://api.github.com/users/KodrAus/followers","following_url":"https://api.github.com/users/KodrAus/following{/other_user}","gists_url":"https://api.github.com/users/KodrAus/gists{/gist_id}","starred_url":"https://api.github.com/users/KodrAus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KodrAus/subscriptions","organizations_url":"https://api.github.com/users/KodrAus/orgs","repos_url":"https://api.github.com/users/KodrAus/repos","events_url":"https://api.github.com/users/KodrAus/events{/privacy}","received_events_url":"https://api.github.com/users/KodrAus/received_events","type":"User","site_admin":false}],"milestone":null,"comments":20,"created_at":"2018-05-01T11:26:29Z","updated_at":"2018-05-26T04:52:09Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/50364","html_url":"https://github.com/rust-lang/rust/pull/50364","diff_url":"https://github.com/rust-lang/rust/pull/50364.diff","patch_url":"https://github.com/rust-lang/rust/pull/50364.patch"},"body":"Hi there!\r\n\r\nFor a long time now, I was getting annoyed by the derived `Debug` impl of `Duration`. Usually, I use `Duration` to either do quick'n'dirty benchmarking or measuring the time of some operation in general. The output of the derived Debug impl is hard to parse for humans: is { secs: 0, nanos: 968360102 } or { secs: 0, nanos 98507324 } longer? \r\n\r\nSo after running into the annoyance several times (sometimes building my own function to print the Duration properly), I decided to tackle this. Now the output looks like this:\r\n\r\n```\r\nDuration::new(1, 0)                 => 1s\r\nDuration::new(1, 1)                 => 1.000000001s\r\nDuration::new(1, 300)               => 1.0000003s\r\nDuration::new(1, 4000)              => 1.000004s\r\nDuration::new(1, 600000)            => 1.0006s\r\nDuration::new(1, 7000000)           => 1.007s\r\nDuration::new(0, 0)                 => 0ns\r\nDuration::new(0, 1)                 => 1ns\r\nDuration::new(0, 300)               => 300ns\r\nDuration::new(0, 4001)              => 4.001µs\r\nDuration::new(0, 600300)            => 600.3µs\r\nDuration::new(0, 7000000)           => 7ms\r\n```\r\n\r\nNote that I implemented the formatting manually and didn't use floats. No information is \"lost\" when printing. So `Duration::new(123_456_789_000, 900_000_001)` prints as `123456789000.900000001s`.\r\n\r\n~~This is not yet finished~~, but I wanted to open the PR now already in order to get some feedback (maybe everyone likes the derived impl).\r\n\r\n### Still ToDo:\r\n\r\n- [x] Respect precision ~~and width~~ parameter of the formatter (see [this comment](https://github.com/rust-lang/rust/pull/50364#issuecomment-386107107))\r\n\r\n### Alternatives/Decisions\r\n\r\n- Should large durations displayed in minutes, hours, days, ...? For now, I decided not to because the current formatting is close the how a `Duration` is stored. From this new `Debug` output, you can still easily see what the values of `secs` and `nanos` are. A formatting like `3h 27m 12s 9ms` might be more appropriate for a `Display` impl?\r\n- Should this rather be a `Display` impl and should `Debug` be derived? Maybe this formatting is too fancy for `Debug`? In my opinion it's not and, as already mentioned, from the current format one can still very easily determine the values for `secs` and `nanos`.\r\n- Whitespace between the number and the unit?\r\n\r\n### Notes for reviewers\r\n\r\n- ~~The combined diff sucks. Rather review both commits individually.~~\r\n- ~~In the unit test, I am building my own type implementing `fmt::Write` to test the output. Maybe there is already something like that which I can use?~~\r\n- My `Debug` impl block is marked as `#[stable(...)]`... but that's fine since the derived Debug impl was stable already, right?\r\n\r\n---\r\n\r\n~~Apart from the main change, I moved all `time` unit tests into the `tests` directory. All other `libcore` tests are there, so I guess it was simply an oversight. Prior to this change, the `time` tests weren't run, so I guess this is kind of a bug fix. If my `Debug` impl is rejected, I can of course just send the fix as PR.~~ (this was already merged in #50466)\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/392236609","html_url":"https://github.com/rust-lang/rust/pull/50364#issuecomment-392236609","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/50364","id":392236609,"user":{"login":"KodrAus","id":6721458,"avatar_url":"https://avatars0.githubusercontent.com/u/6721458?v=4","gravatar_id":"","url":"https://api.github.com/users/KodrAus","html_url":"https://github.com/KodrAus","followers_url":"https://api.github.com/users/KodrAus/followers","following_url":"https://api.github.com/users/KodrAus/following{/other_user}","gists_url":"https://api.github.com/users/KodrAus/gists{/gist_id}","starred_url":"https://api.github.com/users/KodrAus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KodrAus/subscriptions","organizations_url":"https://api.github.com/users/KodrAus/orgs","repos_url":"https://api.github.com/users/KodrAus/repos","events_url":"https://api.github.com/users/KodrAus/events{/privacy}","received_events_url":"https://api.github.com/users/KodrAus/received_events","type":"User","site_admin":false},"created_at":"2018-05-26T04:52:09Z","updated_at":"2018-05-26T04:52:09Z","author_association":"NONE","body":"This looks good to me!\r\n\r\n@bors r+"}}
{"actor":{"display_login":"KodrAus"}}