Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd as_millis function to std::time::Duration #1545
Comments
This comment has been minimized.
This comment has been minimized.
|
You cannot convert duration to milliseconds losslessly whereas you can do that in the other direction. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa of course not, but it would still be very useful, nonetheless. An |
This comment has been minimized.
This comment has been minimized.
gkoz
commented
Mar 16, 2016
|
The duration RFC explicitly mentions acceptable losses:
So it is surprising that everyone has to implement the reductions manually. |
This comment has been minimized.
This comment has been minimized.
|
Yes, this patttern is virtually everywhere. |
This comment has been minimized.
This comment has been minimized.
|
See #1547 |
nrc
added
the
T-libs
label
Aug 18, 2016
arthurprs
referenced this issue
Dec 21, 2016
Closed
Add something like `Duration::as_fractional_secs` #38475
This comment has been minimized.
This comment has been minimized.
|
Looks like with rust-lang/rust#35118 ( |
This comment has been minimized.
This comment has been minimized.
|
The rounding problem is silly. What is a realistic use case for needing millisecond precision on a duration longer than half a billion years? (but also doesn't need duration longer than 500 billion years) |
This comment has been minimized.
This comment has been minimized.
|
Perhaps we could offer |
This comment has been minimized.
This comment has been minimized.
lolgesten
commented
Nov 19, 2017
|
I think the time handling in rust a pretty serious ergonomic issue. To easily do a So whilst I agree rust std should stop short of full blown |
This comment has been minimized.
This comment has been minimized.
idubrov
commented
Jan 31, 2018
|
Totally agree. It's an ergonomic issue. Call me stupid, but this is the code I had to fix today: let sec = (elapsed.as_secs() as f64) + f64::from(elapsed.subsec_nanos()) / 1000_000.0;See the issue? It worked fine until our queries became too long. |
This comment has been minimized.
This comment has been minimized.
praetp
commented
May 21, 2018
|
Any progress on this ? |
This comment has been minimized.
This comment has been minimized.
|
I've created a poll about it https://internals.rust-lang.org/t/duration-as-milliseconds/7605 |
This comment has been minimized.
This comment has been minimized.
lolgesten
commented
May 21, 2018
|
And there is this: rust-lang/rust#50167 |
This comment has been minimized.
This comment has been minimized.
|
Closing in favor of rust-lang/rust#50202. |
paezao commentedMar 16, 2016
Hello,
It's funny because there's a from_millis function but not an as_millis one.
What do you guys think? It's a simple change.
Cheers