Skip to content

Commit 7efdd07

Browse files
committed
update date.py
1 parent ddbd38d commit 7efdd07

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/Util/date.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from pandas.errors import ParserError
2+
3+
14
def calendar_days(start: str, end: str):
25
"""
36
This method will create a union of calendar dates for further comparison.
@@ -7,11 +10,11 @@ def calendar_days(start: str, end: str):
710
:return: Union of calendar days. 01/01/2015 to 01/01/2016
811
"""
912
from pandas import to_datetime, date_range
10-
11-
start_date = to_datetime(start) # Defines the start date of data collection
12-
end_date = to_datetime(end) # Defines the end date of data collection
13-
14-
calendar_list = date_range(start_date, end_date)
15-
16-
return calendar_list
17-
13+
try:
14+
start_date = to_datetime(start) # Defines the start date of data collection
15+
end_date = to_datetime(end) # Defines the end date of data collection
16+
calendar_list = date_range(start_date, end_date)
17+
return calendar_list
18+
except (ValueError, ParserError):
19+
print('\033[31m' + 'WARNING! Please, insert a valid date' + '\033[0m')
20+
return None

0 commit comments

Comments
 (0)