65 Commits

Author SHA1 Message Date
Artyom Pavlov
4281e6136d
fix tests 2019-07-30 16:41:03 +00:00
Artyom Pavlov
55ee8fe852
mark div_duration methods as unstable, update tracking issue 2019-07-30 15:00:17 +00:00
newpavlov
ad3632401c unconstify methods 2019-07-17 18:58:33 +03:00
newpavlov
0a227f33a8 stabilize duration_float 2019-07-17 18:36:15 +03:00
Mazdak Farrokhzad
dbfbadeac4 libcore: deny more... 2019-04-19 01:37:12 +02:00
Taiki Endo
360432f1e8 libcore => 2018 2019-04-18 14:47:35 +09:00
Artyom Pavlov
78b248dc4c
fix typo 2019-03-12 16:42:18 +03:00
Artyom Pavlov
197efb0524
fix test 2019-03-11 18:59:41 +00:00
newpavlov
980871af27 fix tests 2019-03-11 19:57:53 +03:00
newpavlov
35c19c5b3d move MAX_NANOS_F64/32 to methods 2019-03-11 18:06:13 +03:00
newpavlov
e25df326ca consistent naming for duration_float methods and additional f32 methods 2019-03-11 17:53:22 +03:00
Mazdak Farrokhzad
73e661a0a5
Rollup merge of #58595 - stjepang:make-duration-consts-associated, r=oli-obk
Turn duration consts into associated consts

As suggested in https://github.com/rust-lang/rust/issues/57391#issuecomment-459658236, I'm moving `Duration` constants (`SECOND`, `MILLISECOND` and so on; currently behind unstable `duration_constants` feature) into the `impl Duration` block.

cc @frewsxcv @SimonSapin
2019-02-23 09:25:29 +01:00
Stjepan Glavina
c6d24cd504 Enable feature duration_constants in examples 2019-02-21 09:13:50 +01:00
Stjepan Glavina
f223c03372 Add examples for duration constants 2019-02-20 21:58:20 +01:00
Stjepan Glavina
8e219e7eb5 Turn duration consts into associated consts 2019-02-20 14:21:15 +01:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Alexander Regueiro
b87363e763 tests: doc comments 2019-02-10 23:42:32 +00:00
Stjepan Glavina
8c902b6633 Specify the tracking issue 2019-01-07 11:39:22 +01:00
Stjepan Glavina
7f7a2e9396 Add duration constants 2019-01-06 13:44:55 +01:00
Sunjay Varma
1e82618613 Stabilize duration_as_u128 2018-12-26 12:12:06 -07:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Mazdak Farrokhzad
f65b630d33 constify parts of libstd. 2018-11-10 01:10:07 +01:00
Mazdak Farrokhzad
b4c046b342 constify libcore/time.rs 2018-11-10 01:06:09 +01:00
Alex Crichton
d0060d72e5 Bump nightly to 1.32.0
* Also update the bootstrap compiler
* Update cargo to 1.32.0
* Clean out stage0 annotations
2018-10-31 11:53:50 -07:00
Oliver Schneider
9e46c0b689 Only promote calls to #[rustc_promotable] const fns 2018-10-03 10:07:05 +02:00
kennytm
a791919a62
Rollup merge of #52813 - newpavlov:duration_mul_div_extras, r=alexcrichton
Duration div mul extras

Successor of #52556.

This PR adds the following `impl`s:
- `impl Mul<Duration> for u32` (to allow `10*SECOND` in addition to `SECOND*10`)
- `impl Mul<f64> for Duration` (to allow `2.5*SECOND` vs `2*SECOND + 500*MILLISECOND`)
- `impl Mul<Duration> for f64`
- `impl MulAssign<f64> for Duration`
- `impl Div<f64> for Duration`
- `impl DivAssign<f64> for Duration`
- `impl Div<Duration> for Duration` (`Output = f64`, can be useful e.g. for `duration/MINUTE`)

`f64` is chosen over `f32` to minimize rounding errors. (52 bits fraction precision vs `Duration`'s ~94 bit)
2018-09-20 21:36:16 +08:00
Artyom Pavlov
fd7565b076
Added tracking issue, fixed check, 1.30 -> 1.31 2018-09-19 18:40:33 +03:00
Artyom Pavlov
2aca69757f
add panics section to method docs 2018-09-13 01:47:08 +00:00
Artyom Pavlov
9e78cb2446
move checks to from_float_secs 2018-09-13 01:40:38 +00:00
Artyom Pavlov
8a0aa9f3ae
remove trailing spaces 2018-09-13 00:52:59 +00:00
Artyom Pavlov
37972ae300
add as_float_secs and from_float_secs methods, refactor float methods 2018-09-13 00:43:53 +00:00
Artyom Pavlov
c11281f188
fix tests 2018-09-12 18:33:48 +03:00
Artyom Pavlov
533c0f0d1f
fix tests 2018-09-12 17:10:38 +03:00
Artyom Pavlov
c5cbea69aa
fix doctests 2018-09-12 14:17:36 +03:00
Artyom Pavlov
07c15ea645
more explicit impl 2018-09-12 11:56:39 +03:00
Artyom Pavlov
206ca68ff3
remove newline 2018-09-12 11:52:19 +03:00
Artyom Pavlov
0673417daa
Move float ops to unstable inherent methods 2018-09-12 11:50:46 +03:00
ljedrz
d46dca66c9 Remove redundant field names in structs 2018-08-04 14:58:20 +02:00
Артём Павлов [Artyom Pavlov]
d48a649a17
1.29.0 -> 1.30.0 2018-08-04 00:47:13 +03:00
Артём Павлов [Artyom Pavlov]
2cab0deb97
don't duplicate impls 2018-07-31 04:07:11 +03:00
Артём Павлов [Artyom Pavlov]
2c300fa15b
change negativity check 2018-07-30 12:12:52 +03:00
Артём Павлов [Artyom Pavlov]
3e07236a31
add MAX_NANOS_F64 constant 2018-07-29 16:01:43 +03:00
Артём Павлов [Artyom Pavlov]
12d8f2792a
review update 2018-07-29 07:35:52 +03:00
Артём Павлов [Artyom Pavlov]
c24fb126e7
duration div mul extras 2018-07-29 07:00:13 +03:00
Karoline Plum
9a86e3df99
Make rounding down clear in duration documentation
Now also the documentations of `subsec_millis`, `subsec_micros`, `as_millis` and `as_micros` make clear that the fractional nanosecond component is rounded down to whole units.
2018-07-14 15:48:52 +02:00
Pazzaz
d22ad76ca8 Optimize sum of Durations by using custom function 2018-06-16 20:56:17 +02:00
Mark Simulacrum
77c8bd0b4e
Rollup merge of #50167 - fintelia:duration-nanos, r=sfackler
Add as_nanos function to Duration

Duration has historically lacked a way to get the actual number of nanoseconds it contained as a normal Rust type because u64 was of insufficient range, and f64 of insufficient precision. The u128 type solves both issues, so I propose adding an `as_nanos` function to expose the capability.
2018-06-02 13:14:22 -06:00
Jonathan Behrens
fc895665c9 Avoid 128-bit arithmetic where possible 2018-05-28 19:01:50 -04:00
bors
444a9c3f1a Auto merge of #50364 - LukasKalbertodt:improve-duration-debug-impl, r=KodrAus
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)                 => 1s
Duration::new(1, 1)                 => 1.000000001s
Duration::new(1, 300)               => 1.0000003s
Duration::new(1, 4000)              => 1.000004s
Duration::new(1, 600000)            => 1.0006s
Duration::new(1, 7000000)           => 1.007s
Duration::new(0, 0)                 => 0ns
Duration::new(0, 1)                 => 1ns
Duration::new(0, 300)               => 300ns
Duration::new(0, 4001)              => 4.001µs
Duration::new(0, 600300)            => 600.3µs
Duration::new(0, 7000000)           => 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)
2018-05-26 07:33:06 +00:00