Repository navigation
Handle spaces around operators - #1327
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1327 +/- ##
=======================================
Coverage 97.10% 97.10%
=======================================
Files 235 235
Lines 2904 2904
=======================================
Hits 2820 2820
Misses 84 84 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
AdrianAtZyte
approved these changes
Apr 29, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #1292 by improving relative-time parsing for expressions like now + 1 hour / now - 1 hour, specifically when whitespace appears between the +/- operator and the numeric value.
Changes:
- Updated the freshness parsing regex to accept whitespace between an explicit
+/-sign and the number. - Adjusted numeric parsing to tolerate the newly-allowed whitespace in the captured number token.
- Added regression tests covering
now +/- <offset>forms with spaces around the operator.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
dateparser/freshness_date_parser.py |
Allows whitespace between sign and digits in relative-offset parsing and normalizes the captured numeric token. |
tests/test_freshness_date_parser.py |
Adds test cases for now + ... and now - ... with spaced operators to prevent regressions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| has_explicit_sign = num.startswith("+") or num.startswith("-") | ||
| explicit_signs[unit + "s"] = has_explicit_sign | ||
| kwargs[unit + "s"] = float(num.replace(",", ".")) | ||
| kwargs[unit + "s"] = float(num.replace(",", ".").replace(" ", "")) |
serhii73
approved these changes
May 7, 2026
wRAR
approved these changes
May 8, 2026
Merged
This was referenced Sep 28, 2026
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 #1292