Description
For some use cases I need to work directly with integers instead of chrono::Duration (called chrono::TimeDelta in the not-yet-released chrono 0.5). In such cases I want my code to work reliably with all time units, including microseconds and nanoseconds. Currently, calling num_microseconds()
or num_nanoseconds()
returns Option<i64>
, which requires special handling for these cases, which makes the code more complicated than it has to be.
Looking at std::time::Duration
and at time::Duration
from the time 0.3 crate, they return u128
and i128
respectively. I know it's possible to use one of these instead, however, chrono::TimeDelta (chrono::Duration in 0.4) is the only duration type which currently works with chrono::DateTime (which is one of the main reasons why I need chrono). I also know that it's possible to convert between std::time::Duration and chrono::Duration, but the conversion function returns a Result
(which makes sense considering it uses unsigned integers), which again makes the code more complicated than it has to be, as special handling is required.
Because chrono 0.5 won't depend on time 0.1 at all anymore, I propose the following:
- Add support for
i128
to chrono::TimeDelta in chrono 0.5 ->num_microseconds()
andnum_nanoseconds()
should returni128
. Furthermore,num_milliseconds()
should also returni128
- see my next point. - Extend the min/max limits of chrono::TimeDelta. Currently, a maximum of i64::MAX and a minimum of i64::MIN milliseconds are supported. However, I think it would make more sense to have the same limits as
time::Duration
from the time 0.3 crate - that is, having a maximum limit of i64::MAX seconds and 999,999,999 nanoseconds, and a minimum limit of i64::MIN seconds and -999,999,999 nanoseconds.