Skip to content

Parse "the Nth of the month" as a day of the current month - #1418

Open
AdrianAtZyte wants to merge 4 commits into
scrapinghub:masterfrom
AdrianAtZyte:first-of-the-month-standalone
Open

AdrianAtZyte wants to merge 4 commits into
scrapinghub:masterfrom
AdrianAtZyte:first-of-the-month-standalone

Conversation

@AdrianAtZyte

@AdrianAtZyte AdrianAtZyte commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1265.

@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing AdrianAtZyte:first-of-the-month-standalone (bb4c05a) with master (9073f25)

Open in CodSpeed

@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.94%. Comparing base (9073f25) to head (bb4c05a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1418   +/-   ##
=======================================
  Coverage   98.94%   98.94%           
=======================================
  Files         239      239           
  Lines        3521     3521           
=======================================
  Hits         3484     3484           
  Misses         37       37           

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

@AdrianAtZyte
AdrianAtZyte marked this pull request as ready for review September 23, 2026 11:31

@serhii73 serhii73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! the 15th of the month now gives the 15th instead of 15 months ago. The simplification
of the month → of this month applies to any English text, though, so in search_dates every
"X of the month" phrase becomes a relative date for today, and it can cost a real date:

from datetime import datetime
from dateparser.search import search_dates

S = {"RELATIVE_BASE": datetime(2026, 9, 30, 13, 15)}
print(search_dates("Photo of the month, 12 March 1999", settings=S))
print(search_dates("He was named player of the month for March 2021.", settings=S))
print(search_dates("Employee of the month", settings=S, languages=["en"]))
input master this branch
Photo of the month, 12 March 1999 12 March 1999 → 1999-03-12 March → 2026-03-30, 1999 → 1999-09-30
He was named player of the month for March 2021. March 2021 of the month → 2026-09-30 13:15, March 2021
Employee of the month (en) None of the month → 2026-09-30 13:15

The same goes for "Deal of the month", "Book of the month club", "the rest of the month" and so on, and
parse("of the month") returns today.

Anchoring the simplification to the day number seems enough, e.g. (\d+(?:st|nd|rd|th)?) of the month
→ \1 of this month. With that, the new tests still pass, the "Nth of the month" results are the
same, and the examples above give the same results as master.

This branch has not been deployed

No deployments
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.

2 participants