From 55d4f716769b192b114eb9c434bea222ee012dc9 Mon Sep 17 00:00:00 2001 From: jakeogh Date: Sat, 17 May 2025 00:06:00 -0700 Subject: [PATCH 1/3] fix: allow 'N {interval} from now' (#502) --- dateparser/data/date_translation_data/en.py | 1 + .../date_translation_data/en.yaml | 2 +- tests/test_freshness_date_parser.py | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dateparser/data/date_translation_data/en.py b/dateparser/data/date_translation_data/en.py index be38a97dc..fb869240e 100644 --- a/dateparser/data/date_translation_data/en.py +++ b/dateparser/data/date_translation_data/en.py @@ -749,6 +749,7 @@ "and", "at", "by", + "from", "just", "m", "nd", diff --git a/dateparser_data/supplementary_language_data/date_translation_data/en.yaml b/dateparser_data/supplementary_language_data/date_translation_data/en.yaml index 38b31297d..bc9001d6b 100644 --- a/dateparser_data/supplementary_language_data/date_translation_data/en.yaml +++ b/dateparser_data/supplementary_language_data/date_translation_data/en.yaml @@ -1,4 +1,4 @@ -skip: ["about", "ad", "and", "at", "by", "just", "m", "nd", "of", "on", "rd", "st", "th", "the"] +skip: ["about", "ad", "and", "at", "by", "from", "just", "m", "nd", "of", "on", "rd", "st", "th", "the"] pertain: ["of"] sentence_splitter_group : 1 diff --git a/tests/test_freshness_date_parser.py b/tests/test_freshness_date_parser.py index 529d60e22..80c3944e4 100644 --- a/tests/test_freshness_date_parser.py +++ b/tests/test_freshness_date_parser.py @@ -122,6 +122,11 @@ def test_relative_past_dates_with_time_as_period(self, date_string, ago, period) period="day", ), param("just now", ago={"seconds": 0}, period="day"), + param('11 hours from now', in_future={'hours': 11}, period='hour'), + param('10 days from now', in_future={'days': 10}, period='day'), + param('9 weeks from now', in_future={'weeks': 9}, period='week'), + param('8 months from now', in_future={'months': 8}, period='month'), + param('7 years from now', in_future={'years': 7}, period='year'), # Fix for #291, work till one to twelve only param("nine hours ago", ago={"hours": 9}, period="day"), param("three week ago", ago={"weeks": 3}, period="week"), From 0178fade961f2b096488f3c56bd36cda53a16c7f Mon Sep 17 00:00:00 2001 From: jakeogh Date: Sat, 18 Oct 2025 13:10:02 -0700 Subject: [PATCH 2/3] tests: move "from now" cases to test_relative_future_dates Fixes test failure by moving "from now" test cases from test_relative_past_dates to test_relative_future_dates. --- tests/test_freshness_date_parser.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/test_freshness_date_parser.py b/tests/test_freshness_date_parser.py index 80c3944e4..7ac99c1f0 100644 --- a/tests/test_freshness_date_parser.py +++ b/tests/test_freshness_date_parser.py @@ -122,11 +122,6 @@ def test_relative_past_dates_with_time_as_period(self, date_string, ago, period) period="day", ), param("just now", ago={"seconds": 0}, period="day"), - param('11 hours from now', in_future={'hours': 11}, period='hour'), - param('10 days from now', in_future={'days': 10}, period='day'), - param('9 weeks from now', in_future={'weeks': 9}, period='week'), - param('8 months from now', in_future={'months': 8}, period='month'), - param('7 years from now', in_future={'years': 7}, period='year'), # Fix for #291, work till one to twelve only param("nine hours ago", ago={"hours": 9}, period="day"), param("three week ago", ago={"weeks": 3}, period="week"), @@ -1819,6 +1814,18 @@ def test_normalized_relative_dates(self, date_string, ago, period): param("3 hours later", in_future={"hours": 3}, period="day"), param("4 minutes later", in_future={"minutes": 4}, period="day"), param("5 seconds later", in_future={"seconds": 5}, period="day"), + # from now + param('7 years from now', in_future={'years': 7}, period='year'), + param('6 months from now', in_future={'months': 6}, period='month'), + param('5 weeks from now', in_future={'weeks': 5}, period='week'), + param('4 days from now', in_future={'days': 4}, period='day'), + param('3 hours from now', in_future={'hours': 3}, period='day'), + param('2 minutes from now', in_future={'minutes': 2}, period='day'), + param('1 second from now', in_future={'seconds': 1}, period='day'), + param('five years from now', in_future={'years': 5}, period='year'), + param('a year from now', in_future={'years': 1}, period='year'), + param('an hour from now', in_future={'hours': 1}, period='day'), + param('1 year 2 months from now', in_future={'years': 1, 'months': 2}, period='month'), # Fractional units param("in 2.5 hours", in_future={"hours": 2.5}, period="day"), param("in 10.75 minutes", in_future={"minutes": 10.75}, period="day"), From a795ec09cb274add186d9297cc9df30320720b3f Mon Sep 17 00:00:00 2001 From: jakeogh Date: Tue, 21 Oct 2025 21:25:00 -0700 Subject: [PATCH 3/3] ruff format --- tests/test_freshness_date_parser.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/test_freshness_date_parser.py b/tests/test_freshness_date_parser.py index 7ac99c1f0..8a68d92ee 100644 --- a/tests/test_freshness_date_parser.py +++ b/tests/test_freshness_date_parser.py @@ -1815,17 +1815,21 @@ def test_normalized_relative_dates(self, date_string, ago, period): param("4 minutes later", in_future={"minutes": 4}, period="day"), param("5 seconds later", in_future={"seconds": 5}, period="day"), # from now - param('7 years from now', in_future={'years': 7}, period='year'), - param('6 months from now', in_future={'months': 6}, period='month'), - param('5 weeks from now', in_future={'weeks': 5}, period='week'), - param('4 days from now', in_future={'days': 4}, period='day'), - param('3 hours from now', in_future={'hours': 3}, period='day'), - param('2 minutes from now', in_future={'minutes': 2}, period='day'), - param('1 second from now', in_future={'seconds': 1}, period='day'), - param('five years from now', in_future={'years': 5}, period='year'), - param('a year from now', in_future={'years': 1}, period='year'), - param('an hour from now', in_future={'hours': 1}, period='day'), - param('1 year 2 months from now', in_future={'years': 1, 'months': 2}, period='month'), + param("7 years from now", in_future={"years": 7}, period="year"), + param("6 months from now", in_future={"months": 6}, period="month"), + param("5 weeks from now", in_future={"weeks": 5}, period="week"), + param("4 days from now", in_future={"days": 4}, period="day"), + param("3 hours from now", in_future={"hours": 3}, period="day"), + param("2 minutes from now", in_future={"minutes": 2}, period="day"), + param("1 second from now", in_future={"seconds": 1}, period="day"), + param("five years from now", in_future={"years": 5}, period="year"), + param("a year from now", in_future={"years": 1}, period="year"), + param("an hour from now", in_future={"hours": 1}, period="day"), + param( + "1 year 2 months from now", + in_future={"years": 1, "months": 2}, + period="month", + ), # Fractional units param("in 2.5 hours", in_future={"hours": 2.5}, period="day"), param("in 10.75 minutes", in_future={"minutes": 10.75}, period="day"),