Merge branch 'development' of https://github.com/MNPC-IR/Rasaddam_Backend into development

This commit is contained in:
2025-12-07 10:44:36 +03:30

View File

@@ -302,16 +302,31 @@ def to_locale_str(a):
return "{:,}".format(int(a))
def convert_str_to_date(string):
def convert_str_to_date(string,with_datetime=None):
string = str(string).strip()
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()
except ValueError:
return None
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:
if with_datetime:
date = datetime.strptime(string, fmt)
else:
date = datetime.strptime(string, fmt).date()
return date
except ValueError:
continue
return None