update convert_str_to_date
This commit is contained in:
@@ -304,14 +304,29 @@ def to_locale_str(a):
|
|||||||
|
|
||||||
def convert_str_to_date(string):
|
def convert_str_to_date(string):
|
||||||
string = str(string).strip()
|
string = str(string).strip()
|
||||||
try:
|
|
||||||
return datetime.strptime(string, '%Y-%m-%dT%H:%M:%S.%fZ').date()
|
date_formats = [
|
||||||
except ValueError:
|
'%Y-%m-%dT%H:%M:%S.%fZ',
|
||||||
try:
|
'%Y-%m-%dT%H:%M:%SZ',
|
||||||
return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ').date() # Added format without milliseconds
|
'%Y-%m-%dT%H:%M:%S.%f%z',
|
||||||
except ValueError:
|
'%Y-%m-%dT%H:%M:%S%z',
|
||||||
try:
|
'%Y-%m-%dT%H:%M:%S.%f',
|
||||||
return datetime.strptime(string, '%Y-%m-%d').date()
|
'%Y-%m-%dT%H:%M:%S',
|
||||||
except ValueError:
|
'%Y-%m-%d %H:%M:%S.%f',
|
||||||
return None
|
'%Y-%m-%d %H:%M:%S',
|
||||||
|
'%Y-%m-%dT%H:%M:%S.%f%z',
|
||||||
|
'%Y-%m-%d'
|
||||||
|
]
|
||||||
|
|
||||||
|
for fmt in date_formats:
|
||||||
|
try:
|
||||||
|
if with_datetime:
|
||||||
|
date = datetime.strptime(string, fmt)
|
||||||
|
else:
|
||||||
|
date = datetime.strptime(string, fmt).date()
|
||||||
|
return date
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user