Skip to content

Parse English ordinal dates containing day of - #1383

Closed
Shy7777 wants to merge 2 commits into
scrapinghub:masterfrom
Shy7777:fix/1256-english-day-of-month
Closed

Shy7777 wants to merge 2 commits into
scrapinghub:masterfrom
Shy7777:fix/1256-english-day-of-month

Conversation

@Shy7777

@Shy7777 Shy7777 commented Sep 10, 2026 •

Copy link
Copy Markdown

Dates like the 1st day of March, 2025 currently return None, even though the same date without day parses correctly. This adds a small English rule that treats 1st day of like 1st of, so the existing date parser can handle it.

The change updates the English language data and its generated file, with four regression cases covering st, nd, rd, and th.

The full suite passes on Python 3.12: 24,363 passed, 3 skipped, and 1 expected failure. Generated-data consistency, lint, and formatting checks pass too.

Fixes #1171, fixes #1256.

Copilot AI lite review requested due to automatic review settings September 10, 2026 10:30

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.

🟢 Approval recommended

The change is a narrowly scoped English-only simplification with strong regression/control test coverage and consistent regenerated data updates.

Pull request overview

This PR fixes English parsing for ordinal dates that include the phrase “day of” (e.g., the 1st day of March, 2025) by adding an English translation simplification that rewrites "<ordinal> day of" into the already-supported "<ordinal> of" form, while ensuring “day” continues to work as a relative-time unit.

Changes:

  • Add an English simplification rule to convert (\d{1,2}(st|nd|rd|th)) day of → \1 of in supplementary YAML and regenerated en.py data.
  • Add parameterized tests covering ordinal suffixes, casing/whitespace/time, and controls to ensure existing interpretations and relative-day parsing remain unchanged.
  • Update README with the newly supported example.
File summaries
File Description
tests/test_date_parser.py Adds regression + control tests for “ day of …” parsing and ensures relative-day behavior remains intact.
README.rst Documents the new supported input example for the public API.
dateparser/data/date_translation_data/en.py Regenerated English translation data including the new simplification rule.
dateparser_data/supplementary_language_data/date_translation_data/en.yaml Source YAML change introducing the new simplification rule.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@AdrianAtZyte AdrianAtZyte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks! Two optional nits: I would drop the README example, since the list there is for broad features and this is a fairly niche phrasing, and I think the new tests could be trimmed to three or four cases, since relative days are already covered elsewhere and the whitespace/case variants exercise the simplification machinery rather than this change.

@codecov

codecov Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.18%. Comparing base (6114c90) to head (7fa0190).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1383   +/-   ##
=======================================
  Coverage   97.18%   97.18%           
=======================================
  Files         236      236           
  Lines        3057     3057           
=======================================
  Hits         2971     2971           
  Misses         86       86           

☔ View full report in Codecov by Harness.
📢 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.

@codspeed

codspeed Bot commented Sep 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing Shy7777:fix/1256-english-day-of-month (7fa0190) with master (6114c90)

Open in CodSpeed

@Shy7777

Shy7777 commented Sep 10, 2026

Copy link
Copy Markdown
Author

Thanks, that makes sense. I've removed the README example and trimmed the new tests to four cases, one for each ordinal suffix. The full test suite still passes.

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.

As the library suggest human readable dates, it must support following... Unable to parse "the 1st day of March"

3 participants