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):
|
||||
string = str(string).strip()
|
||||
|
||||
date_formats = [
|
||||
'%Y-%m-%dT%H:%M:%S.%fZ',
|
||||
'%Y-%m-%dT%H:%M:%SZ',
|
||||
'%Y-%m-%dT%H:%M:%S.%f%z',
|
||||
'%Y-%m-%dT%H:%M:%S%z',
|
||||
'%Y-%m-%dT%H:%M:%S.%f',
|
||||
'%Y-%m-%dT%H:%M:%S',
|
||||
'%Y-%m-%d %H:%M:%S.%f',
|
||||
'%Y-%m-%d %H:%M:%S',
|
||||
'%Y-%m-%dT%H:%M:%S.%f%z',
|
||||
'%Y-%m-%d'
|
||||
]
|
||||
|
||||
for fmt in date_formats:
|
||||
try:
|
||||
return datetime.strptime(string, '%Y-%m-%dT%H:%M:%S.%fZ').date()
|
||||
except ValueError:
|
||||
try:
|
||||
return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ').date() # Added format without milliseconds
|
||||
except ValueError:
|
||||
try:
|
||||
return datetime.strptime(string, '%Y-%m-%d').date()
|
||||
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