Skip to content

Handle spaces around operators - #1327

Merged
wRAR merged 2 commits into
masterfrom
bug/handle-spacees-with-operator
May 8, 2026
Merged

wRAR merged 2 commits into
masterfrom
bug/handle-spacees-with-operator

Conversation

@gutsytechster

Copy link
Copy Markdown
Collaborator

Fixes #1292

@codecov

codecov Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.10%. Comparing base (373ede9) to head (a578176).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
serhii73 requested a review from wRAR May 7, 2026 10:19
@wRAR
wRAR merged commit 075712f into master May 8, 2026
22 checks passed
@wRAR
wRAR deleted the bug/handle-spacees-with-operator branch May 8, 2026 12:08
@serhii73 serhii73 mentioned this pull request Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"now + 1 hour" returns a time in the past

5 participants