span: add Span::to_duration and TryFrom impls for Duration #47
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.
This PR dips our toes into the water of integration with
std::time::Duration
. I do somewhat expect there to be more integrationpoints, particularly in the datetime arithmetic APIs, but this at least
paves a path for folks to correctly convert between a
Duration
and aSpan
. The error cases for the new APIs will ensure you can nevermisuse these APIs.
This adds a few new APIs:
Span::is_positive
, since we already haveSpan::is_negative
andSpan::is_zero
.Span::signum
, since it's signed and it's sometimes convenient.TryFrom<std::time::Duration> for Span
.TryFrom<Span> for std::time::Duration
that returns an error ifthe span is negative or has non-zero units bigger than days.
Span::to_duration
that requires a relative date and can convert anypositive span into a
Duration
(modulo overflow).Partially addresses #21
Fixes #40