<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/src/libcore/tests/time.rs, branch 1.35.0</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.35.0</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.35.0'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2019-03-10T16:47:42+00:00</updated>
<entry>
<title>we can now skip should_panic tests with the libtest harness</title>
<updated>2019-03-10T16:47:42+00:00</updated>
<author>
<name>Ralf Jung</name>
<email>post@ralfj.de</email>
</author>
<published>2019-03-10T16:45:45+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=4888b1fb99f1bf6a58bebaededdfbf4477383634'/>
<id>urn:sha1:4888b1fb99f1bf6a58bebaededdfbf4477383634</id>
<content type='text'>
</content>
</entry>
<entry>
<title>the formatting issue got fixed</title>
<updated>2019-02-13T17:21:13+00:00</updated>
<author>
<name>Ralf Jung</name>
<email>post@ralfj.de</email>
</author>
<published>2019-02-13T12:25:46+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e24af6c2b32679e398b2a2b1bc81ab9c258d8765'/>
<id>urn:sha1:e24af6c2b32679e398b2a2b1bc81ab9c258d8765</id>
<content type='text'>
</content>
</entry>
<entry>
<title>review or fix miri failures in iter, slice, cell, time</title>
<updated>2019-02-13T16:56:43+00:00</updated>
<author>
<name>Ralf Jung</name>
<email>post@ralfj.de</email>
</author>
<published>2019-02-09T12:16:23+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=7f5dc49214b05a469c5c4974fc4e605cb72822ea'/>
<id>urn:sha1:7f5dc49214b05a469c5c4974fc4e605cb72822ea</id>
<content type='text'>
</content>
</entry>
<entry>
<title>disable tests in Miri</title>
<updated>2019-02-07T17:24:10+00:00</updated>
<author>
<name>Ralf Jung</name>
<email>post@ralfj.de</email>
</author>
<published>2019-02-07T17:23:44+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=81613ad7cf9889a59d0a7233af9e462715945a72'/>
<id>urn:sha1:81613ad7cf9889a59d0a7233af9e462715945a72</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Remove licenses</title>
<updated>2018-12-26T04:08:33+00:00</updated>
<author>
<name>Mark Rousskov</name>
<email>mark.simulacrum@gmail.com</email>
</author>
<published>2018-12-25T15:56:47+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=2a663555ddf36f6b041445894a8c175cd1bc718c'/>
<id>urn:sha1:2a663555ddf36f6b041445894a8c175cd1bc718c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Optimize sum of Durations by using custom function</title>
<updated>2018-06-16T18:56:17+00:00</updated>
<author>
<name>Pazzaz</name>
<email>pazzaz.sundqvist@gmail.com</email>
</author>
<published>2018-06-16T18:19:19+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=d22ad76ca83acda1428829173451eee0221f685a'/>
<id>urn:sha1:d22ad76ca83acda1428829173451eee0221f685a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Auto merge of #50364 - LukasKalbertodt:improve-duration-debug-impl, r=KodrAus</title>
<updated>2018-05-26T07:33:06+00:00</updated>
<author>
<name>bors</name>
<email>bors@rust-lang.org</email>
</author>
<published>2018-05-26T07:33:06+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=444a9c3f1afad7585e7a65a05dbea8025a67b675'/>
<id>urn:sha1:444a9c3f1afad7585e7a65a05dbea8025a67b675</id>
<content type='text'>
Improve `Debug` impl of `time::Duration`

Hi there!

For 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?

So 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:

```
Duration::new(1, 0)                 =&gt; 1s
Duration::new(1, 1)                 =&gt; 1.000000001s
Duration::new(1, 300)               =&gt; 1.0000003s
Duration::new(1, 4000)              =&gt; 1.000004s
Duration::new(1, 600000)            =&gt; 1.0006s
Duration::new(1, 7000000)           =&gt; 1.007s
Duration::new(0, 0)                 =&gt; 0ns
Duration::new(0, 1)                 =&gt; 1ns
Duration::new(0, 300)               =&gt; 300ns
Duration::new(0, 4001)              =&gt; 4.001µs
Duration::new(0, 600300)            =&gt; 600.3µs
Duration::new(0, 7000000)           =&gt; 7ms
```

Note 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`.

~~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).

### Still ToDo:

- [x] Respect precision ~~and width~~ parameter of the formatter (see [this comment](https://github.com/rust-lang/rust/pull/50364#issuecomment-386107107))

### Alternatives/Decisions

- 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?
- 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`.
- Whitespace between the number and the unit?

### Notes for reviewers

- ~~The combined diff sucks. Rather review both commits individually.~~
- ~~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?~~
- My `Debug` impl block is marked as `#[stable(...)]`... but that's fine since the derived Debug impl was stable already, right?

---

~~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)
</content>
</entry>
<entry>
<title>Fix `Debug` impl of `Duration` for precisions &gt; 9</title>
<updated>2018-05-16T13:08:39+00:00</updated>
<author>
<name>Lukas Kalbertodt</name>
<email>lukas.kalbertodt@gmail.com</email>
</author>
<published>2018-05-16T13:08:39+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=59e71141029162fe4b4a3ed4cad430dace3fb995'/>
<id>urn:sha1:59e71141029162fe4b4a3ed4cad430dace3fb995</id>
<content type='text'>
Previously, the code would panic for high precision values. Now it
has the same behavior as printing normal floating point values: if
a high precision is specified, '0's are added.
</content>
</entry>
<entry>
<title>Implement rounding for `Duration`s Debug output</title>
<updated>2018-05-16T12:46:37+00:00</updated>
<author>
<name>Lukas Kalbertodt</name>
<email>lukas.kalbertodt@gmail.com</email>
</author>
<published>2018-05-16T12:46:37+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=2a28ac31e9abe0a01861bfffed85872431cc6b72'/>
<id>urn:sha1:2a28ac31e9abe0a01861bfffed85872431cc6b72</id>
<content type='text'>
Rounding is done like for printing floating point numbers. If the
first digit which isn't printed (due to the precision parameter) is
larger than '4', the number is rounded up.
</content>
</entry>
<entry>
<title>const time</title>
<updated>2018-05-10T19:10:11+00:00</updated>
<author>
<name>Roman Stoliar</name>
<email>rizakrko@rambler.ru</email>
</author>
<published>2018-05-08T20:47:50+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=4d8d0a6f85ee66c7b65c53de3039aa38d99f05af'/>
<id>urn:sha1:4d8d0a6f85ee66c7b65c53de3039aa38d99f05af</id>
<content type='text'>
added rustc_const_unstable attribute

extended tests

added conversion test

fixed tidy test

added feature attribute
</content>
</entry>
</feed>
