Skip to content

[WIP] Fix word-number phrases parsing (e.g., "two days later", "two days from now") - #1317

Merged
serhii73 merged 3 commits into
fix/word-number-phrases-parsingfrom
copilot/improve-documentation-examples
Feb 27, 2026
Merged

serhii73 merged 3 commits into
fix/word-number-phrases-parsingfrom
copilot/improve-documentation-examples

Conversation

Copilot AI commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

Phrases like "two days later" and "two days from now" returned None due to two bugs in the English simplification pipeline.

Root Causes

  • later pattern — regex required \d+, but word-to-number substitutions ("two" → "2") run after it, so the pattern never matched word numbers.
  • from now simplification — (?<=from\s+)now → in used a lookbehind that replaced only now, leaving from in the string (e.g., "two days from in"), which is unparseable regardless of ordering.

Changes

  • en.yaml / en.py — later pattern: Extended the capture group to match word numbers alongside digits:

    (\d+[.,]?\d*|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)
      (decade|year|month|week|day|hour|minute|second)s? later  →  in \1 \2
    
  • en.yaml / en.py — from now simplification: Replaced broken lookbehind with a full-phrase match:

    - (?<=from\s+)now: in
    + from\s+now: in
  • Tests: Added test_word_numbers_with_later_and_from_now covering both patterns with word numbers, numeric values, and singular/plural variants. Calendar-based units (months, years) assert only result > base_date since they aren't fixed-length deltas.

Before / After

base = datetime(2025, 6, 15, 12, 0, 0)
settings = {"RELATIVE_BASE": base}

dateparser.parse("two days later",    settings=settings)  # None  →  2025-06-17
dateparser.parse("three weeks later", settings=settings)  # None  →  2025-07-06
dateparser.parse("two days from now", settings=settings)  # None  →  2025-06-17
dateparser.parse("2 days later",      settings=settings)  # 2025-06-17 (unchanged)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update documentation with additional examples Fix word-number phrases parsing (e.g., "two days later", "two days from now") Feb 26, 2026
@serhii73
serhii73 changed the base branch from master to fix/word-number-phrases-parsing February 26, 2026 15:08
@serhii73
serhii73 requested a review from Copilot February 26, 2026 15:09
@serhii73 serhii73 changed the title Fix word-number phrases parsing (e.g., "two days later", "two days from now") [WIP] Fix word-number phrases parsing (e.g., "two days later", "two days from now") Feb 26, 2026
@codecov

codecov Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.63%. Comparing base (8cdcf80) to head (3f4c729).
⚠️ Report is 1 commits behind head on fix/word-number-phrases-parsing.

Additional details and impacted files
@@                       Coverage Diff                        @@
##           fix/word-number-phrases-parsing    #1317   +/-   ##
================================================================
  Coverage                            96.63%   96.63%           
================================================================
  Files                                  235      235           
  Lines                                 2915     2915           
================================================================
  Hits                                  2817     2817           
  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.

@serhii73
serhii73 marked this pull request as ready for review February 26, 2026 15:10

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

Fixes English relative phrase parsing for expressions like “two days later” / “two days from now” by adjusting the English simplification rules so word-number quantities are recognized and “from now” is simplified correctly before parsing.

Changes:

  • Update English simplifications to match word numbers in the … later pattern.
  • Replace the broken from now lookbehind simplification with a full-phrase match.
  • Add parameterized tests covering word numbers, numeric values, and pluralization variants for both “later” and “from now”.

Reviewed changes

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

File Description
tests/test_date_parser.py Adds regression tests for word-number + “later/from now” relative parsing.
dateparser_data/supplementary_language_data/date_translation_data/en.yaml Updates English simplification regexes for “from now” and “later”.
dateparser/data/date_translation_data/en.py Mirrors the English simplification updates in the Python translation data.

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

Comment on lines +90 to +92
- from\s+now: in
- less than 1 minute ago: 45 second ago
- (\d+[.,]?\d*) (decade|year|month|week|day|hour|minute|second)s? later: in \1 \2
- (\d+[.,]?\d*|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve) (decade|year|month|week|day|hour|minute|second)s? later: in \1 \2

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

The later simplification now hardcodes the supported word-number list (one…twelve) even though the same word→digit mappings are defined immediately below. This duplication is easy to desync if more number words get added later. Consider keeping the later regex numeric-only and moving it after the word→digit simplifications (or otherwise centralizing the number-word pattern) so future additions don’t require editing multiple rules.

Copilot uses AI. Check for mistakes.
Comment on lines 821 to 823
{
"(\\d+[.,]?\\d*) (decade|year|month|week|day|hour|minute|second)s? later": "in \\1 \\2"
"(\\d+[.,]?\\d*|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve) (decade|year|month|week|day|hour|minute|second)s? later": "in \\1 \\2"
},

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

The later simplification regex now embeds a word-number alternation (one…twelve) while separate simplifications below already convert those words to digits. This duplicates the source of truth and can drift if more number words are added later. Consider reordering so word→digit conversions run before the later rule (keeping the later pattern numeric-only), or otherwise centralizing the number-word pattern.

Copilot uses AI. Check for mistakes.

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

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


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

Comment thread tests/test_date_parser.py
result,
f"{description}: Expected {expected}, got {result}",
)

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

There’s trailing whitespace on this blank line; please remove it to keep the file clean (and avoid potential lint/pre-commit failures).

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread tests/test_date_parser.py
Comment on lines +1563 to +1564
def test_word_numbers_advanced(self, date_string, expected_delta, description):
"""Test number parsing with word numbers (1-12) in 'from now' phrases."""

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

The PR description says a test named test_word_numbers_with_later_and_from_now was added, but the new test here is named test_word_numbers_advanced. Please either rename the test to match its scope (e.g., explicitly mention from now) or update the PR description so they stay in sync.

Copilot uses AI. Check for mistakes.
@serhii73
serhii73 merged commit cb15eae into fix/word-number-phrases-parsing Feb 27, 2026
6 checks passed
@serhii73
serhii73 deleted the copilot/improve-documentation-examples branch February 27, 2026 12:03
serhii73 added a commit that referenced this pull request Mar 2, 2026
* Fix word-number phrases parsing (e.g., 'two days later')

Close #1314

* Fix word-number phrases parsing (e.g., "two days later", "two days from now") (#1317)

* Initial plan

* Fix word-number phrases parsing for 'later' and 'from now' patterns

Co-authored-by: serhii73 <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: serhii73 <[email protected]>
Co-authored-by: Serhii A <[email protected]>

* Update tests/test_date_parser.py

Co-authored-by: Copilot <[email protected]>

* Apply pre-commit

* Fix approximate day counts in word number tests

- Update 'four months later' from 120 to 122 days (June 15 to Oct 15, 2025)
- Update 'six years later' from 2190 to 2191 days (accounts for leap year in 2028)
- These values now match the actual calendar arithmetic performed by the parser

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: serhii73 <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.

3 participants