arrow-py / arrow

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

span_range returns unexpected result (missing days) when using frame month #1185

Open Iwerzhon opened 3 months ago

Iwerzhon commented 3 months ago

Issue Description

Describe the bug, including details regarding any error messages, version, and platform.

Sometimes (based on the start_date/end_date value), some days are missing when splitting a range of dates using span_range with frame=month

Doc: https://arrow.readthedocs.io/en/latest/api-guide.html#arrow.arrow.Arrow.span_range

Reproduction

import arrow
start_date = arrow.get("2023-01-31T00:00:00+02:00")
end_date = arrow.get("2024-08-20T16:08:09.538605+02:00")
[
    [start.isoformat(), end.isoformat()]
    for start, end in arrow.Arrow.span_range("month", start_date.datetime, end_date.datetime, exact=True)
]

Output

[
    ['2023-01-31T00:00:00+02:00', '2023-02-27T23:59:59.999999+02:00'],
    ['2023-02-28T00:00:00+02:00', '2023-03-27T23:59:59.999999+02:00'],
    ['2023-03-31T00:00:00+02:00', '2023-04-29T23:59:59.999999+02:00'],  # missing 28th to 30th march
    ['2023-04-30T00:00:00+02:00', '2023-05-29T23:59:59.999999+02:00'],
    ['2023-05-31T00:00:00+02:00', '2023-06-29T23:59:59.999999+02:00'],
    ['2023-06-30T00:00:00+02:00', '2023-07-29T23:59:59.999999+02:00'],
    ['2023-07-31T00:00:00+02:00', '2023-08-30T23:59:59.999999+02:00'],
    ['2023-08-31T00:00:00+02:00', '2023-09-29T23:59:59.999999+02:00'],
    ['2023-09-30T00:00:00+02:00', '2023-10-29T23:59:59.999999+02:00'],
    ['2023-10-31T00:00:00+02:00', '2023-11-29T23:59:59.999999+02:00'],
    ['2023-11-30T00:00:00+02:00', '2023-12-29T23:59:59.999999+02:00'],
    ['2023-12-31T00:00:00+02:00', '2024-01-30T23:59:59.999999+02:00'],
    ['2024-01-31T00:00:00+02:00', '2024-02-28T23:59:59.999999+02:00'],
    ['2024-02-29T00:00:00+02:00', '2024-03-28T23:59:59.999999+02:00'],
    ['2024-03-31T00:00:00+02:00', '2024-04-29T23:59:59.999999+02:00'],
    ['2024-04-30T00:00:00+02:00', '2024-05-29T23:59:59.999999+02:00'],
    ['2024-05-31T00:00:00+02:00', '2024-06-29T23:59:59.999999+02:00'],
    ['2024-06-30T00:00:00+02:00', '2024-07-29T23:59:59.999999+02:00'],
    ['2024-07-31T00:00:00+02:00', '2024-08-20T16:08:09.538604+02:00'] # missing 30th july
]

Expected result

We should not miss any day from span_range. However, we... go from 2023-03-27T23:59:59 to 2023-03-31T00:00:00+02:00, missing 3 days (2nd to 3rd value) go from 2024-07-29T23:59:59 to 2024-07-31T00:00:00+02:00, missing 1 day (last value)

Note :

I am unsure of the difference between month and months, but I don't think this is the expected behavior?

System Info

rkendra commented 3 weeks ago

Is anyone currently working on this? If not, I'd like to take a look into it. I was also able to reproduce the bug on Ubuntu 22.04.

krisfremen commented 3 weeks ago

Is anyone currently working on this? If not, I'd like to take a look into it. I was also able to reproduce the bug on Ubuntu 22.04.

@rkendra not at the moment, feel free to take it up