diff --git a/brutils/date.py b/brutils/date.py index 98645017..0896249e 100644 --- a/brutils/date.py +++ b/brutils/date.py @@ -1,12 +1,11 @@ import re -from typing import Union from num2words import num2words from brutils.data.enums.months import MonthsEnum -def convert_date_to_text(date: str) -> Union[str, None]: +def convert_date_to_text(date: str) -> str | None: """ Converts a given date in Brazilian format (dd/mm/yyyy) to its textual representation. @@ -24,9 +23,7 @@ def convert_date_to_text(date: str) -> Union[str, None]: """ pattern = re.compile(r"\d{2}/\d{2}/\d{4}") if not re.match(pattern, date): - raise ValueError( - "Date is not a valid date. Please pass a date in the format dd/mm/yyyy." - ) + return None day_str, month_str, year_str = date.split("/") day = int(day_str) diff --git a/tests/test_date.py b/tests/test_date.py index 3691ec76..242f6944 100644 --- a/tests/test_date.py +++ b/tests/test_date.py @@ -45,10 +45,10 @@ def test_convert_date_to_text(self): self.assertIsNone(convert_date_to_text("29/02/2019"), None) # Invalid date pattern. - self.assertRaises(ValueError, convert_date_to_text, "Invalid") - self.assertRaises(ValueError, convert_date_to_text, "25/1/2020") - self.assertRaises(ValueError, convert_date_to_text, "1924/08/20") - self.assertRaises(ValueError, convert_date_to_text, "5/09/2020") + self.assertIsNone(convert_date_to_text("Invalid")) + self.assertIsNone(convert_date_to_text("25/1/2020")) + self.assertIsNone(convert_date_to_text("1924/08/20")) + self.assertIsNone(convert_date_to_text("5/09/2020")) self.assertEqual( convert_date_to_text("29/02/2020"),