Merge branch 'development' of https://github.com/MNPC-IR/Rasaddam_Backend into development
This commit is contained in:
@@ -302,16 +302,31 @@ def to_locale_str(a):
|
|||||||
return "{:,}".format(int(a))
|
return "{:,}".format(int(a))
|
||||||
|
|
||||||
|
|
||||||
def convert_str_to_date(string):
|
def convert_str_to_date(string,with_datetime=None):
|
||||||
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