0.5: Let TimeDelta::{weeks, days, hours, minutes, seconds}
take i32
#1515
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Making these methods fallible is not ergonomic. Especially because they are usually used with small values that comfortably fit in an
i32
.This PR converts
TimeDelta::{weeks, days, hours, minutes, seconds}
to being infallible, and to take ani32
as argument.They can no longer be used to create values that cover the entire range of
TimeDelta
. If that is needed users can useTimeDelta::new
.Also they no longer support easy round-tripping with their
num_*
variants that return ani64
. Constructing a value is much more common that round-tripping, so it is best to make constructing ergonomic.Because the range of
TimeDelta
is defined as-i64::MAX..=i64::MAX
theTimeDelta::milliseconds
constructor still takes ani64
as argument and remains fallible. That way a mapping betweenTimeDelta
and a single integer remains easy.If users want an infallible alternative, they can multiply by
1000
and useTimeDelta::microseconds
.