fix: Check if input is str is_invalid_date_string

This is sort of a breaking change? Because if an int/dict/list/tuple was
passed instead of a str, object doesnt have .startswith (AttributeError)
would be raised instead of just returning None.
This commit is contained in:
Gavin D'souza 2021-08-31 13:07:22 +05:30
parent 8622142d7d
commit 176d6d2d06

View file

@ -18,10 +18,10 @@ DATETIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT
def is_invalid_date_string(date_string):
# dateutil parser does not agree with dates like "0001-01-01" or "0000-00-00"
return (not date_string) or (date_string or "").startswith(("0001-01-01", "0000-00-00"))
return not isinstance(date_string, str) or ((not date_string) or (date_string or "").startswith(("0001-01-01", "0000-00-00")))
# datetime functions
def getdate(string_date=None):
def getdate(string_date: str = None):
"""
Converts string date (yyyy-mm-dd) to datetime.date object.
If no input is provided, current date is returned.