You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
in_months behavior inconsistent in 30-day months #606
I have searched the issues of this repo and believe that this is not a duplicate.
OS version and name: macOS 11.6.1
Pendulum version: 2.1.2 and 3.0.0a0
Issue
When calculating a diff's in_months method, the following results seem inconsistent:
start
end
in_months result
2022-01-02
2023-01-01
11
2022-02-02
2023-02-01
11
2022-03-02
2023-03-01
11
2022-04-02
2023-04-01
12
2022-05-02
2023-05-01
11
2022-06-02
2023-06-01
12
2022-07-02
2023-07-01
11
2022-08-02
2023-08-01
11
2022-09-02
2023-09-01
12
2022-10-02
2023-10-01
11
2022-11-02
2023-11-01
12
2022-12-02
2023-12-01
11
It seems that whenever the end date is in one of the months with 30 days (April, June, September, November), if the start date's day of the month is one day later than the corresponding end day of the month, the number of months from in_months is one higher than it "should" be.
Obviously this is a sticky issue because the definition of a "month" is not well defined (it can be any value from 28 to 31 days), but since this behavior doesn't happen with February, the behavior seems inconsistent at the least.
Desired Result
The in_months method should be determined based on the comparison of the day of the month, not the duration of the last month in the interval, which seems to be the root of this behavior.
As you can see, February 5th to February 2nd of the following year is calculated as 12 months, but February 5th to February 3rd of the following year (one day longer) is calculated as only 11 months.
Activity
rileyjohngibbs commentedon Mar 9, 2022
Some more inconsistency, specifically with February:
As you can see, February 5th to February 2nd of the following year is calculated as 12 months, but February 5th to February 3rd of the following year (one day longer) is calculated as only 11 months.
I think, again, the root cause is this check for equality.
rileyjohngibbs commentedon Mar 9, 2022
I think I have a (remarkably brutish) fix for this but some other tests are now failing, starting with the fix exposing a masked bug (see #608).