Parse "the Nth of the month" as a day of the current month - #1418
AdrianAtZyte wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
serhii73
left a comment
There was a problem hiding this comment.
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.
Part of #1265.