arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.71k stars 673 forks source link

Add 'exact' keyword in span_range, span and interval methods #888

Closed svanita00 closed 3 years ago

svanita00 commented 3 years ago

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

Merged PR #817 with updated master. Added edge cases in span_range function when exact keyword is True. Added correlated tests for span_range.

Closes: #498

codecov[bot] commented 3 years ago

Codecov Report

Merging #888 (57a5184) into master (0aebf57) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #888   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines         1798      1817   +19     
  Branches       313       320    +7     
=========================================
+ Hits          1798      1817   +19     
Impacted Files Coverage Δ
arrow/arrow.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0aebf57...57a5184. Read the comment docs.

svanita00 commented 3 years ago

I'm not sure why the lint is failing here, I ran it locally and it passed there..

systemcatch commented 3 years ago

Seems like the bug found in the old PR is now fixed. :+1:

from datetime import datetime
import arrow

start = datetime(2013, 5, 5, 12, 30)
end = datetime(2013, 5, 5, 12, 40)

for r in arrow.Arrow.span_range('minute', start, end, exact=True):
    print(r)

Old bug

(<Arrow [2013-05-05T12:30:00+00:00]>, <Arrow [2013-05-05T12:30:59.999999+00:00]>)
(<Arrow [2013-05-05T12:31:00+00:00]>, <Arrow [2013-05-05T12:31:59.999999+00:00]>)
(<Arrow [2013-05-05T12:32:00+00:00]>, <Arrow [2013-05-05T12:32:59.999999+00:00]>)
(<Arrow [2013-05-05T12:33:00+00:00]>, <Arrow [2013-05-05T12:33:59.999999+00:00]>)
(<Arrow [2013-05-05T12:34:00+00:00]>, <Arrow [2013-05-05T12:34:59.999999+00:00]>)
(<Arrow [2013-05-05T12:35:00+00:00]>, <Arrow [2013-05-05T12:35:59.999999+00:00]>)
(<Arrow [2013-05-05T12:36:00+00:00]>, <Arrow [2013-05-05T12:36:59.999999+00:00]>)
(<Arrow [2013-05-05T12:37:00+00:00]>, <Arrow [2013-05-05T12:37:59.999999+00:00]>)
(<Arrow [2013-05-05T12:38:00+00:00]>, <Arrow [2013-05-05T12:38:59.999999+00:00]>)
(<Arrow [2013-05-05T12:39:00+00:00]>, <Arrow [2013-05-05T12:39:59.999999+00:00]>)
(<Arrow [2013-05-05T12:40:00+00:00]>, <Arrow [2013-05-05T12:39:59.999999+00:00]>)

New correct

(<Arrow [2013-05-05T12:30:00+00:00]>, <Arrow [2013-05-05T12:30:59.999999+00:00]>)
(<Arrow [2013-05-05T12:31:00+00:00]>, <Arrow [2013-05-05T12:31:59.999999+00:00]>)
(<Arrow [2013-05-05T12:32:00+00:00]>, <Arrow [2013-05-05T12:32:59.999999+00:00]>)
(<Arrow [2013-05-05T12:33:00+00:00]>, <Arrow [2013-05-05T12:33:59.999999+00:00]>)
(<Arrow [2013-05-05T12:34:00+00:00]>, <Arrow [2013-05-05T12:34:59.999999+00:00]>)
(<Arrow [2013-05-05T12:35:00+00:00]>, <Arrow [2013-05-05T12:35:59.999999+00:00]>)
(<Arrow [2013-05-05T12:36:00+00:00]>, <Arrow [2013-05-05T12:36:59.999999+00:00]>)
(<Arrow [2013-05-05T12:37:00+00:00]>, <Arrow [2013-05-05T12:37:59.999999+00:00]>)
(<Arrow [2013-05-05T12:38:00+00:00]>, <Arrow [2013-05-05T12:38:59.999999+00:00]>)
(<Arrow [2013-05-05T12:39:00+00:00]>, <Arrow [2013-05-05T12:39:59.999999+00:00]>)