Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion dateparser/data/date_translation_data/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
"month": [
"mo",
"month",
"months"
"months",
"mon",
Copy link
Copy Markdown
Contributor

@AdrianAtZyte AdrianAtZyte May 12, 2026

Choose a reason for hiding this comment

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

This is also my main concern with this change.

I wonder if you can use AI to expand the tests with inputs that would become problematic after this change and inputs that were problematic before it, and decide which ones is best to leave broken, keeping them as expected failures.

"mons"
],
"week": [
"week",
Expand Down Expand Up @@ -800,6 +802,9 @@
"after"
],
"simplifications": [
{
"(\\d+)\\s*mons?\\b": "\\1 month"
},
{
"an": "1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ year:
- years
month:
- months
- mon
- mons
week:
- weeks
day:
Expand Down Expand Up @@ -82,6 +84,7 @@ relative-type-regex:
- (\d+[.,]?\d*) decades? ago

simplifications:
- (\d+)\s*mons?\b: \1 month
- an: '1'
- a: '1'
- (?:12\s+)?noon: '12:00'
Expand Down
20 changes: 20 additions & 0 deletions dateparser_scripts/write_complete_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@
RELATIVE_PATTERN = re.compile(r"\{0\}")


def _to_plain_types(obj):
"""Recursively convert ruamel.yaml CommentedMap/CommentedSeq to plain
OrderedDict/list so that json.dumps produces stable output across all
Python versions.

Python 3.14 changed the json C encoder to bypass the Python-level
``__iter__``/``items()`` of dict subclasses and access the underlying C
dict directly. ruamel.yaml's CommentedMap relies on its Python-level
iteration for correct key ordering, so the C shortcut produces a
different (non-deterministic) key order on 3.14. Converting to plain
types before serialisation avoids the issue entirely.
"""
if isinstance(obj, dict):
return OrderedDict((k, _to_plain_types(v)) for k, v in obj.items())
elif isinstance(obj, list):
return [_to_plain_types(v) for v in obj]
return obj


def _modify_relative_data(relative_data):
modified_relative_data = OrderedDict()
for key, value in relative_data.items():
Expand Down Expand Up @@ -95,6 +114,7 @@ def write_complete_data(in_memory=False):
for language in all_languages:
date_translation_data = _get_complete_date_translation_data(language)
date_translation_data = combine_dicts(date_translation_data, base_data)
date_translation_data = _to_plain_types(date_translation_data)
_modify_data(date_translation_data)
translation_data = json.dumps(
date_translation_data, indent=4, separators=(",", ": "), ensure_ascii=False
Expand Down
10 changes: 7 additions & 3 deletions tests/test_freshness_date_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2364,15 +2364,19 @@ def test_dates_not_supported_by_date_time(self, date_string):

@parameterized.expand(
[
param("1mon ago"), # 1116
param("1mon ago", ago={"months": 1}, period="month"), # 1123
param("2mon ago", ago={"months": 2}, period="month"), # 1123
param("3mons ago", ago={"months": 3}, period="month"), # 1123
]
)
def test_known_issues(self, date_string):
def test_known_issues(self, date_string, ago, period):
self.given_parser()
self.given_date_string(date_string)
self.when_date_is_parsed()
self.then_error_was_not_raised()
self.assertEqual(None, self.result["date_obj"])
self.then_date_was_parsed_by_freshness_parser()
self.then_date_obj_is_exactly_this_time_ago(ago)
self.then_period_is(period)
Comment on lines 2365 to +2379

@parameterized.expand(
[
Expand Down
Loading