Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions dateparser/languages/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ def _count_words_present_in_the_dictionary(self, words, settings=None):
dict_cnt = 0
skip_cnt = 0
for word in set(words):
if word in dictionary:
# Some locales map bare numbers to months, e.g. "11" from the
# Vietnamese "tháng 11", which is no evidence of the language.
if word.isdigit():
skip_cnt += 1
elif word in dictionary:
if dictionary[word]:
dict_cnt += 1
else:
skip_cnt += 1
elif word.isdigit():
skip_cnt += 1
return [dict_cnt, skip_cnt]

@staticmethod
Expand Down
10 changes: 10 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,16 @@ def test_search_dates_returning_detected_languages_if_requested(
result = search_dates(text, add_detected_language=add_detected_language)
self.assertEqual(result, expected)

@parameterized.expand(
[
param(text="11 sent 12-Dec-2014"),
param(text="09 sent 12-Dec-2014"),
]
)
def test_search_dates_with_numbers_that_are_months_in_other_languages(self, text):
result = search_dates(text)
self.assertEqual(result, [("12-Dec-2014", datetime.datetime(2014, 12, 12))])

@parameterized.expand(
[
param(text="19 марта 2001", languages="wrong type: str instead of list"),
Expand Down
Loading