Fix arrow.Arrow.interval() - #466
Conversation
arrow.Arrow.interval() produces unexpected results if the interval doesn't evenly divide the range. It leaves off the last chunk of time.
>>> start = datetime(2013, 5, 5, 12, 30)
>>> end = datetime(2013, 5, 5, 17, 15)
>>> for r in arrow.Arrow.interval('hour', start, end, 4): print (r)
(<Arrow [2013-05-05T12:00:00+00:00]>, <Arrow [2013-05-05T15:59:59.999999+00:00]>)
# Expected result:
# (<Arrow [2013-05-05T12:00:00+00:00]>, <Arrow [2013-05-05T15:59:59.999999+00:00]>)
# (<Arrow [2013-05-05T16:00:00+00:00]>, <Arrow [2013-05-05T17:59:59.999999+00:00]>)
|
Can you add a test case for this? |
|
Sure, I'll do that tomorrow. Can you explain why it failed the CI build? I
can't find a full log that details exactly which text didn't pass.
…On Oct 10, 2017 17:11, "Andrew Elkins" ***@***.***> wrote:
Can you add a test case for this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#466 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFmGt-VI3O7C_HYx8uMWBl024XhR_Fdkks5srAfNgaJpZM4PySCV>
.
|
Test that interval() works correctly when the range isn't evenly divisible by the interval.
Codecov Report
@@ Coverage Diff @@
## master #466 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 14 14
Lines 3189 3195 +6
Branches 229 230 +1
=====================================
+ Hits 3189 3195 +6
Continue to review full report at Codecov.
|
|
Imho it would be better the last chunk of time be in a separate interval rather than appended to the last time's end date. That way you are guaranteed the maximum time span between any two dates is the specified interval rather than the last one potentially being higher. That seems to be how you implemented things (different from the original post) |
|
can also fix some pep8 issues along the way with this PR ;) |
|
I'm confused. I wrote it so that if, for example, you ask for intervals of 2 hours over a 5 hour range, you are returned a list of length 3. The first two elements have a 2 hour interval and the 3rd has the extra hour. The previous implementation would have dropped the 5th hour. |
|
@rhan-mentad I think you misunderstood. I'm not appending the extra chunk of time to the last pair, I'm appending it to the return list. Interval() returns a list of (start,end) tuples. I'm just appending a final (start,end) tuple in cases where there is a bit of time in the range left over. |
arrow.Arrow.interval() produces unexpected results if the interval doesn't evenly divide the range. It leaves off the last chunk of time.
Expected result: