Repository navigation
Find a date written next to a relative one without a comma (#695) - #1385
Merged
Merged
Conversation
- Add month locative/dative forms (lednu, ΓΊnoru, bΕeznu, dubnu, kvΔtnu, Δervnu, Δervenci, srpnu, ΕΓjnu, prosinci) for dates like "v lednu 2023" - Add July abbreviation "Δrv" - Fix "za mΔsΓc/tΓ½den/rok" not parsing: add accusative simplification patterns (previous patterns only matched instrumental -em forms) - Add tests covering the new expressions Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
search_dates('Today 13 Feb 2020') found no dates at all, while
'Today, 13 Feb 2020' found both. A chunk that does not parse as one date
is split by looking for a separator that the translation and the text it
was translated from hold the same number of times, and "today" is
translated into "0 day ago": the translation gains two spaces the text
never had, so the whitespace splitter is refused and the whole chunk is
dropped. The comma form works because the comma survives the translation
one for one.
Cut such a chunk where the relative expression ends instead. The cut is
taken only when the expression sits at one end of the chunk, when the
rest of the translation keeps one word per remaining original word, when
the word at that end really is the one the expression was translated
from -- which the locale is asked to confirm by translating it on its
own -- and when what is left of the chunk is a date. A chunk that fails
any of these is left alone rather than cut at a guess, which is why
'Today 13 Feb 2020 and 14 Mar 2021', whose "and" the translation drops,
still finds nothing.
The cut is only looked for when no separator lined up, so a chunk that
splits today keeps splitting exactly the way it does now.
Fixes #695
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1385 +/- ##
==========================================
+ Coverage 97.18% 97.20% +0.02%
==========================================
Files 236 236
Lines 3057 3081 +24
==========================================
+ Hits 2971 2995 +24
Misses 86 86 β View full report in Codecov by Harness. π New features to boost your workflow:
|
AdrianAtZyte
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #695.
Why the comma mattered
A chunk that does not parse as one date is split by
split_if_not_parsed, which looks for aseparator that the translation and the text it was translated from hold the same number of times.
"today"is translated into"0 day ago", so the translation gains two spaces the text never had:No splitter lines up, so the chunk is dropped and nothing is returned. The comma form works
because the comma survives the translation one for one.
The fix
Cut the chunk where the relative expression ends instead.
split_by_relative_expressionlooks fora translated expression (
TRANSLATED_RELATIVE_REG, built fromfreshness_date_parser._UNITSso itmatches the units the translation actually emits and nothing else) and takes the cut only when all
four of these hold:
to confirm it by translating that word on its own;
A chunk that fails any of them is left alone rather than cut at a guess. That is why
'Today 13 Feb 2020 and 14 Mar 2021'still finds nothing: the translation drops the"and", so(2) fails and there is no honest boundary.
The cut is only looked for when no separator lined up, so a chunk that splits today keeps
splitting exactly the way it does now.
Evidence
24236 passed, 19 skipped, 1 xfailed;ruffandruff-formatclean; every new line and branch iscovered, leaving
dateparser/search/search.pyat the same 97% and the same four missed statementsas master.
Differential run against master over 17,648 inputs (relative expressions Γ dates Γ connectors Γ
filler words in 24 locales in both orders, multi-word and numeric relative phrases, two relative
tokens in one chunk, multi-language calls, two-sentence chaining, plus every string mined from
tests/):None)Deliberately not fixed
'April and May 2019') and Dates not getting recognised or wrongly recognised if there are some numbers in the textΒ #787 ("At 30 September 2018 E'000") returnNoneonthis branch exactly as on master. The mirror bug β a skip word translated to nothing β needs
real token alignment plumbed out of
Locale.translate_search, which is a much larger change.'Today 27 Feb 2020 at 5pm'and'Today 13 Feb 2020 and 14 Mar 2021'stayNone: thetranslation drops the
"at"/"and", so the chunk cannot be cut honestly.search_datesalready returns for thesame text written with a comma β including cases where that answer is itself imperfect. Making
the no-separator form behave like the separator form is the point of the issue.
π€ Generated with Claude Code