fix: apply modifier (ago/before/next) to all numbers in chunk - #297
Open
binggao1230 wants to merge 1 commit into
Open
fix: apply modifier (ago/before/next) to all numbers in chunk#297binggao1230 wants to merge 1 commit into
binggao1230 wants to merge 1 commit into
Conversation
When a modifier like "ago" appears after multiple quantity-unit pairs (e.g. "11 hours 0 min ago"), only the last number was negated. This caused wrong results: "11 hours 0 min ago" would parse as +11 hours instead of -11 hours. Fix by iterating over all numbers in reverse order (to preserve string positions) and applying the modifier to each one.
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.
When a modifier like "ago" appears after multiple quantity-unit pairs
(e.g. "11 hours 0 min ago"), only the last number was being negated.
"11 hours 0 min ago" would incorrectly parse as +11 hours instead of
-11 hours, because the modifier was only applied to the "0" while the
"11" was left unchanged.
Root cause
In
_evalModifier, when the else branch processeschunk1(the textbefore the modifier), it finds all numbers via
CRE_NUMBER.finditerbut only picks
[-1](the last match). For single-unit expressionslike "11 hours ago" this is fine, but for multi-unit expressions like
"11 hours 0 min ago" it misses the "11".
Fix
Iterate over all matched numbers in reverse order (to preserve string
positions) and apply the modifier offset to each quantity.
Tests
Added
testMultipleUnitsAgototests/TestDelta.pycovering:All 85 tests pass (84 existing + 1 new).
This PR was prepared with assistance from an AI coding tool.
This change is