-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add as_millis function to std::time::Duration #1545
Comments
You cannot convert duration to milliseconds losslessly whereas you can do that in the other direction. |
@nagisa of course not, but it would still be very useful, nonetheless. An |
The duration RFC explicitly mentions acceptable losses:
So it is surprising that everyone has to implement the reductions manually. |
Yes, this patttern is virtually everywhere. |
See #1547 |
Looks like with rust-lang/rust#35118 ( |
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) |
Perhaps we could offer |
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 |
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. 🤥 |
Any progress on this ? |
I've created a poll about it https://internals.rust-lang.org/t/duration-as-milliseconds/7605 |
And there is this: rust-lang/rust#50167 |
Closing in favor of rust-lang/rust#50202. |
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
The text was updated successfully, but these errors were encountered: