question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

span_range and interval return times outside the specified range

See original GitHub issue

The implementation of span_range (and also interval()) is surprising to me, and is not what I would expect from a range function.

            >>> start = datetime(2013, 5, 5, 12, 30)
            >>> end = datetime(2013, 5, 5, 17, 15)
            >>> for r in arrow.Arrow.span_range('hour', start, end):
            ...     print(r)
            ...
            (<Arrow [2013-05-05T12:00:00+00:00]>, <Arrow [2013-05-05T12:59:59.999999+00:00]>)
            (<Arrow [2013-05-05T13:00:00+00:00]>, <Arrow [2013-05-05T13:59:59.999999+00:00]>)
            (<Arrow [2013-05-05T14:00:00+00:00]>, <Arrow [2013-05-05T14:59:59.999999+00:00]>)
            (<Arrow [2013-05-05T15:00:00+00:00]>, <Arrow [2013-05-05T15:59:59.999999+00:00]>)
            (<Arrow [2013-05-05T16:00:00+00:00]>, <Arrow [2013-05-05T16:59:59.999999+00:00]>)
            (<Arrow [2013-05-05T17:00:00+00:00]>, <Arrow [2013-05-05T17:59:59.999999+00:00]>)

I think the return value should be:

            (<Arrow [2013-05-05T12:30:00+00:00]>, <Arrow [2013-05-05T13:29:59.999999+00:00]>)
            (<Arrow [2013-05-05T13:30:00+00:00]>, <Arrow [2013-05-05T14:29:59.999999+00:00]>)
            (<Arrow [2013-05-05T14:30:00+00:00]>, <Arrow [2013-05-05T15:29:59.999999+00:00]>)
            (<Arrow [2013-05-05T15:30:00+00:00]>, <Arrow [2013-05-05T16:29:59.999999+00:00]>)
            (<Arrow [2013-05-05T16:30:00+00:00]>, <Arrow [2013-05-05T17:14:59.999999+00:00]>)

The first span should start at the specified start, and the final span should truncate so as not to extend beyond end.

I know “span” means something specific (arrow.utcnow().span('day')) and span_range() makes sense considering that definition, but this function still seems surprising and broken. Perhaps however I’m unaware of a use case for the existing span_range(), and I actually want to write a different function like split_range()?

At the very least, my use case is along the lines of:

start_date = arrow.get('2011-02-01')
end_date = arrow.get('2017-11-24')
for start, end in arrow.Arrow.interval('day', start_date, end_date , max_days_to_sync):
    service.syncdata(start, end)

And this breaks when I inadvertently sync data outside the dates I asked for.

I’m happy to submit a pull request or discuss further.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jadchaarcommented, Nov 8, 2020

Yeah take a look at the existing PRs for sure. It seems like there were some existing edge cases that came up during our manual testing, so the PR was 90% there, but couldn’t get merged in the end.

1reaction
systemcatchcommented, Nov 8, 2020

Hi @egannon you might want to look at the old PR for this (#731), the fix worked bar a few edge cases.

edit: actually #817 was the revamped PR by Jad.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RangesExplained · google/guava Wiki - GitHub
A range, sometimes known as an interval, is a convex (informally, ... Range.span(Range) returns the minimal range that encloses both this ...
Read more >
Given a date range how can we break it up into N contiguous ...
I thought I would speed this up by breaking up the date range into non-overlapping intervals and use multiprocessing on each interval. My ......
Read more >
Range extraction - Rosetta Code
Create a function that takes a list of integers in increasing order and returns a correctly formatted string in the range format.
Read more >
Range (Guava: Google Core Libraries for Java 19.0 API)
A range (or "interval") defines the boundaries around a contiguous span of values of some Comparable type; for example, "integers from 1 to...
Read more >
Specifying time spans - Splunk Documentation
A timescale is word or abbreviation that designates the time interval, ... If you use the predefined time ranges in the Time Range...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found