<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/src/libcore/tests/time.rs, branch 1.44.0</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.44.0</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.44.0'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2020-04-06T21:08:12+00:00</updated>
<entry>
<title>Use integer assoc consts in libcore</title>
<updated>2020-04-06T21:08:12+00:00</updated>
<author>
<name>Linus Färnstrand</name>
<email>faern@faern.net</email>
</author>
<published>2020-04-06T21:08:12+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=3e4396b8b5f8a494272ea520e528c22da1ae0888'/>
<id>urn:sha1:3e4396b8b5f8a494272ea520e528c22da1ae0888</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Test `Duration::new` panics on overflow</title>
<updated>2020-02-21T16:04:16+00:00</updated>
<author>
<name>Michael Mc Donnell</name>
<email>michael@mcdonnell.dk</email>
</author>
<published>2020-02-21T00:01:08+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e1c8c8cf63b48c798c1954749e58e99c6cc50093'/>
<id>urn:sha1:e1c8c8cf63b48c798c1954749e58e99c6cc50093</id>
<content type='text'>
A `Duration` is created from a second and nanoseconds variable. The
documentation says: "This constructor will panic if the carry from the
nanoseconds overflows the seconds counter". This was, however, not tested
in the tests. I doubt the behavior will ever regress, but it is usually a
good idea to test all documented behavior.
</content>
</entry>
<entry>
<title>Format libcore with rustfmt (including tests and benches)</title>
<updated>2019-12-07T04:20:51+00:00</updated>
<author>
<name>David Tolnay</name>
<email>dtolnay@gmail.com</email>
</author>
<published>2019-12-07T04:18:12+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=c737169fe579327bd42bf04134a375ae8d8d0d7b'/>
<id>urn:sha1:c737169fe579327bd42bf04134a375ae8d8d0d7b</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Improve test output for libcore/time</title>
<updated>2019-08-09T07:17:27+00:00</updated>
<author>
<name>Sayan Nandan</name>
<email>17377258+sntdevco@users.noreply.github.com</email>
</author>
<published>2019-08-09T07:17:27+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e9ee2cbc53af43dc007bfd81054fb20e57d5da67'/>
<id>urn:sha1:e9ee2cbc53af43dc007bfd81054fb20e57d5da67</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>
</feed>
