File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import re
2- from typing import Union
32
43from num2words import num2words
54
65from brutils .data .enums .months import MonthsEnum
76
87
9- def convert_date_to_text (date : str ) -> Union [ str , None ] :
8+ def convert_date_to_text (date : str ) -> str | None :
109 """
1110 Converts a given date in Brazilian format (dd/mm/yyyy) to its textual representation.
1211
@@ -24,9 +23,7 @@ def convert_date_to_text(date: str) -> Union[str, None]:
2423 """
2524 pattern = re .compile (r"\d{2}/\d{2}/\d{4}" )
2625 if not re .match (pattern , date ):
27- raise ValueError (
28- "Date is not a valid date. Please pass a date in the format dd/mm/yyyy."
29- )
26+ return None
3027
3128 day_str , month_str , year_str = date .split ("/" )
3229 day = int (day_str )
Original file line number Diff line number Diff line change @@ -45,10 +45,10 @@ def test_convert_date_to_text(self):
4545 self .assertIsNone (convert_date_to_text ("29/02/2019" ), None )
4646
4747 # Invalid date pattern.
48- self .assertRaises ( ValueError , convert_date_to_text , "Invalid" )
49- self .assertRaises ( ValueError , convert_date_to_text , "25/1/2020" )
50- self .assertRaises ( ValueError , convert_date_to_text , "1924/08/20" )
51- self .assertRaises ( ValueError , convert_date_to_text , "5/09/2020" )
48+ self .assertIsNone ( convert_date_to_text ( "Invalid" ) )
49+ self .assertIsNone ( convert_date_to_text ( "25/1/2020" ) )
50+ self .assertIsNone ( convert_date_to_text ( "1924/08/20" ) )
51+ self .assertIsNone ( convert_date_to_text ( "5/09/2020" ) )
5252
5353 self .assertEqual (
5454 convert_date_to_text ("29/02/2020" ),
You can’t perform that action at this time.
0 commit comments