Skip to content

Conversation

@serhii73
Copy link
Collaborator

Close #1299

@serhii73 serhii73 self-assigned this Jan 23, 2026
@serhii73 serhii73 changed the title Add tests for relative date time offset parsing WIP Jan 23, 2026
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.62%. Comparing base (920d725) to head (be2857e).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1303      +/-   ##
==========================================
+ Coverage   96.60%   96.62%   +0.01%     
==========================================
  Files         235      235              
  Lines        2889     2905      +16     
==========================================
+ Hits         2791     2807      +16     
  Misses         98       98              

☔ 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes parsing of relative date expressions containing explicit +/- time offsets (e.g., "yesterday +1h"), addressing issue #1299.

Changes:

  • Updated FreshnessDateDataParser to recognize signed numeric quantities (e.g., +1 hour, -30 minutes) and apply them correctly.
  • Added regression tests validating "yesterday"/"tomorrow" +/- <offset> parsing behavior via dateparser.parse().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
dateparser/freshness_date_parser.py Extends unit parsing regex to accept +/- and adjusts relativedelta application to respect explicit signs.
tests/test_date_parser.py Adds parameterized coverage for "yesterday"/"tomorrow" +/- offsets plus targeted regression assertions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if "decades" in kwargs:
kwargs["years"] = 10 * kwargs["decades"] + kwargs.get("years", 0)
if "decades" in explicit_signs:
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

When both decades and years are present in the input (e.g., "-1 decade +2 years"), this logic overwrites explicit_signs["years"] with the decades flag, potentially losing whether years had an explicit sign. Consider only propagating the decades sign to years when years wasn't explicitly present, or combining them in a way that preserves an explicit sign on years if provided.

Suggested change
if "decades" in explicit_signs:
if "decades" in explicit_signs and "years" not in explicit_signs:

Copilot uses AI. Check for mistakes.
Comment on lines +1429 to +1445
def test_yesterday_plus_and_minus_not_equal(self):
"""Verify plus and minus time offsets produce different results."""
base_date = datetime(2026, 1, 19, 12, 0, 0)

plus = parse(
"yesterday +1h",
settings={"RELATIVE_BASE": base_date, "RETURN_AS_TIMEZONE_AWARE": False},
)
minus = parse(
"yesterday -1h",
settings={"RELATIVE_BASE": base_date, "RETURN_AS_TIMEZONE_AWARE": False},
)

self.assertIsNotNone(plus)
self.assertIsNotNone(minus)
self.assertNotEqual(plus, minus)

Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

test_yesterday_plus_and_minus_not_equal is redundant with test_relative_date_with_time_offset, which already asserts the exact expected timestamps for both plus and minus offsets (implying they differ). Consider removing this test or folding the not-equal assertion into the parameterized cases to reduce duplicate coverage and runtime.

Suggested change
def test_yesterday_plus_and_minus_not_equal(self):
"""Verify plus and minus time offsets produce different results."""
base_date = datetime(2026, 1, 19, 12, 0, 0)
plus = parse(
"yesterday +1h",
settings={"RELATIVE_BASE": base_date, "RETURN_AS_TIMEZONE_AWARE": False},
)
minus = parse(
"yesterday -1h",
settings={"RELATIVE_BASE": base_date, "RETURN_AS_TIMEZONE_AWARE": False},
)
self.assertIsNotNone(plus)
self.assertIsNotNone(minus)
self.assertNotEqual(plus, minus)

Copilot uses AI. Check for mistakes.
@serhii73 serhii73 changed the title WIP Fix explicit +/- signs in relative date offsets Jan 29, 2026
@serhii73 serhii73 requested review from Gallaecio and wRAR January 29, 2026 13:45
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.

Problem With '+1-1' in parsing

3 participants