about summary refs log tree commit diff
path: root/src/libcore/time.rs
AgeCommit message (Collapse)AuthorLines
2019-07-30fix testsArtyom Pavlov-0/+2
2019-07-30mark div_duration methods as unstable, update tracking issueArtyom Pavlov-2/+2
2019-07-17unconstify methodsnewpavlov-2/+2
2019-07-17stabilize duration_floatnewpavlov-20/+10
2019-04-19libcore: deny more...Mazdak Farrokhzad-2/+2
2019-04-18libcore => 2018Taiki Endo-5/+5
2019-03-12fix typoArtyom Pavlov-1/+1
2019-03-11fix testArtyom Pavlov-2/+2
2019-03-11fix testsnewpavlov-5/+9
2019-03-11move MAX_NANOS_F64/32 to methodsnewpavlov-2/+4
2019-03-11consistent naming for duration_float methods and additional f32 methodsnewpavlov-9/+121
2019-02-23Rollup merge of #58595 - stjepang:make-duration-consts-associated, r=oli-obkMazdak Farrokhzad-16/+52
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-21Enable feature duration_constants in examplesStjepan Glavina-0/+4
2019-02-20Add examples for duration constantsStjepan Glavina-0/+32
2019-02-20Turn duration consts into associated constsStjepan Glavina-16/+16
2019-02-10libs: doc commentsAlexander Regueiro-1/+1
2019-02-10tests: doc commentsAlexander Regueiro-1/+1
2019-01-07Specify the tracking issueStjepan Glavina-4/+4
2019-01-06Add duration constantsStjepan Glavina-0/+16
2018-12-26Stabilize duration_as_u128Sunjay Varma-6/+3
2018-12-25Remove licensesMark Rousskov-9/+0
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-3/+3
2018-11-10constify parts of libstd.Mazdak Farrokhzad-0/+0
2018-11-10constify libcore/time.rsMazdak Farrokhzad-8/+4
2018-10-31Bump nightly to 1.32.0Alex Crichton-4/+4
* Also update the bootstrap compiler * Update cargo to 1.32.0 * Clean out stage0 annotations
2018-10-03Only promote calls to `#[rustc_promotable]` const fnsOliver Schneider-0/+4
2018-09-20Rollup merge of #52813 - newpavlov:duration_mul_div_extras, r=alexcrichtonkennytm-1/+120
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-19Added tracking issue, fixed check, 1.30 -> 1.31Artyom Pavlov-8/+8
2018-09-13add panics section to method docsArtyom Pavlov-0/+9
2018-09-13move checks to from_float_secsArtyom Pavlov-25/+15
2018-09-13remove trailing spacesArtyom Pavlov-2/+2
2018-09-13add as_float_secs and from_float_secs methods, refactor float methodsArtyom Pavlov-36/+55
2018-09-12fix testsArtyom Pavlov-3/+3
2018-09-12fix testsArtyom Pavlov-1/+4
2018-09-12fix doctestsArtyom Pavlov-0/+6
2018-09-12more explicit implArtyom Pavlov-1/+1
2018-09-12remove newlineArtyom Pavlov-1/+0
2018-09-12Move float ops to unstable inherent methodsArtyom Pavlov-84/+83
2018-08-04Remove redundant field names in structsljedrz-4/+4
2018-08-041.29.0 -> 1.30.0Артём Павлов [Artyom Pavlov]-7/+7
2018-07-31don't duplicate implsАртём Павлов [Artyom Pavlov]-17/+2
2018-07-30change negativity checkАртём Павлов [Artyom Pavlov]-12/+12
2018-07-29add MAX_NANOS_F64 constantАртём Павлов [Artyom Pavlov]-3/+4
2018-07-29review updateАртём Павлов [Artyom Pavlov]-26/+19
2018-07-29duration div mul extrasАртём Павлов [Artyom Pavlov]-0/+115
2018-07-14Make rounding down clear in duration documentationKaroline Plum-4/+4
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-06-16Optimize sum of Durations by using custom functionPazzaz-2/+32
2018-06-02Rollup merge of #50167 - fintelia:duration-nanos, r=sfacklerMark Simulacrum-0/+51
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-05-28Avoid 128-bit arithmetic where possibleJonathan Behrens-2/+2
2018-05-26Auto merge of #50364 - LukasKalbertodt:improve-duration-debug-impl, r=KodrAusbors-1/+118
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)