Repository navigation
Conversation
The 'exactly a full month' shortcut fired whenever the day difference equalled days_in_month - days_in_last_month, so e.g. May 12 -> June 11 was reported as 1 month. Only treat it as a full month when d2 is the last day of its month (clamped) and the time of day did not borrow. Fixes python-pendulum#790, fixes python-pendulum#402.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #402. Also covers the #790 cases.
Note: #1043 also fixes #790 and edits the same branch of
precise_diff. It still requiresd1.day == days_in_last_month, so #402 is still wrong with it applied (I checked:d1.diff(d1.add(months=6)).monthsis still5for 2019-08-30). If you would rather merge #1043 first, I'm happy to rebase this on top of it.Problem
precise_diffcounted a full month whenever the day difference happened to equaldays_in_month - days_in_last_month. That holds for unrelated dates:It also misses real clamped months:
Here
add(months=6)lands on Feb 29 (clamped). The shortcut only matched whend1.dayequalled the length of the month befored2, not whend1.daydoesn't exist ind2's month.Fix
When the day difference is negative, treat it as a full month only if
d2is the last day of its month and the time of day did not borrow a day. This matches howadd(months=...)clamps (Jan 31 + 1 month = Feb 28). Otherwise, use the existing borrow (d_diff += max(d1.day, days_in_last_month)). Both the Python and the Rust implementations are changed in the same way.Tests
tests/test_helpers.pycover:diff_for_humanstests intests/date/test_diff.pycalledtravel_towith UTC midnight. Under the suite's America/Toronto local timezone,today()was then the previous day (Jan 30 / Feb 27), and those asserts passed only because of this bug. They now usependulum.local(...), so they test the dates they intend to.PENDULUM_EXTENSIONS=0) and the Rust (maturin develop) implementations: 1872 passed, 3 skipped.earlier + components == laterwith calendar month counting: 736 mismatches before this change, 0 after.AI-assisted (Claude): I used it to help read the code and draft the test. I reviewed and ran everything myself.
Pull Request Check List