-
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
More methods for std::time::Duration #1917
Comments
Yes, Go uses constants to work with durations. Maybe we could introduce this idea in Rust: let four_seconds = time::SECOND * 4;
let five_hundred_millis = time::MILLISECOND * 500;
let one_and_a_half_second = time::SECOND + time::SECOND / 2;
let one_day = time::HOUR * 24; Similarly, |
The [duration reform rfc](
https://github.com/nox/rust-rfcs/blob/master/text/1040-duration-reform.md)
explicitly avoids adding units such as hours or days.
…On Mar 17, 2017 4:33 PM, "polyfloyd" ***@***.***> wrote:
Yes, time::Duration is lacking quite some functionality.
Go <https://golang.org/pkg/time/#Duration> uses constants to work with
durations. Maybe we could introduce this idea in Rust:
let four_seconds = time::SECOND * 4;
let five_hundred_millis = time::MILLISECOND * 500;
let one_and_a_half_second = time::SECOND + time::SECOND / 2;
let one_day = time::HOUR * 24;
Similarly, as_* could be realized by division and subsec_* by the
remainder.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1917 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AApc0kQw6293PzpBZgrCO2PtdzOoT3Ffks5rmpmmgaJpZM4MIAni>
.
|
The reason why these larger, more-confusing units should be included (IMHO) is precisely because they are hard to get right. I think C#'s If this should not be included in core, there should at least be a blessed crate for this; already there is a huge and unwieldy gap between std and the |
Some of these seem to be open as rust-lang/rust#47097 |
Why is only |
Right now, we have:
from_secs
from_millis
as_secs
subsec_nanos
It'd be nice if we also had:
from_hours
(note: potential for overflow)from_mins
(note: potential for overflow)from_micros
from_nanos
as_hours
as_mins
subsec_millis
subsec_micros
And potentially also:
from_days
(note: potential for overflow)as_days
as_millis
(note: potential for overflow)as_micros
(note: potential for overflow)as_nanos
(note: potential for overflow)(Note that
as_millis
is already suggested by #1545).time::Duration
already has a lot of these, and it'd be nice if the libstd version did too. These don't seem that hard to implement or maintain, and they seem useful enough to have.The text was updated successfully, but these errors were encountered: