dateparser
dateparser copied to clipboard
Unable to parse "the 1st day of March"
Adding "day" in the middle of a date fails parsing:
>>> import dateparser as dp
>>> dp.parse("the 1st day of March, 2025")
>>> dp.parse("the 1st of March, 2025")
datetime.datetime(2025, 3, 1, 0, 0)
Version 1.2.1
Failing test cases (the first two pass, the second two fail):
diff --git a/tests/test_date_parser.py b/tests/test_date_parser.py
index 9be2978..5470ba9 100644
--- a/tests/test_date_parser.py
+++ b/tests/test_date_parser.py
@@ -1321,6 +1321,20 @@ class TestDateParser(BaseTestCase):
self.then_date_was_parsed_by_date_parser()
self.then_date_obj_exactly_is(expected)
+ @parameterized.expand(
+ [
+ param("27th of February 2025", datetime(2025, 2, 27)),
+ param("the 27th of February 2025", datetime(2025, 2, 27)),
+ param("27th day of February 2025", datetime(2025, 2, 27)),
+ param("the 27th day of February 2025", datetime(2025, 2, 27)),
+ ]
+ )
+ def test_dates_with_of_in_them(self, date_string, expected):
+ self.given_parser()
+ self.when_date_is_parsed(date_string)
+ self.then_date_was_parsed_by_date_parser()
+ self.then_date_obj_exactly_is(expected)
+
def given_local_tz_offset(self, offset):
self.add_patch(
patch.object(