@@ -45,11 +45,9 @@ def parse_datestring(str):
4545 return parsed_value .strftime ("%Y-%m-%dT%H:%M:%S.%fZ" )
4646
4747
48- def convert_datetime (obj ):
49- """
50- Recursively converts date strings in ISO 8601 format with timezone offsets into \
51- date strings with 'Z' timezone indicator. The input can be either a dictionary or a list, \
52- possibly nested, containing date strings.
48+ def convert_obj_datetimes (obj ):
49+ """Recursively explores dictionaries and lists, attempting to parse strings as datestrings \
50+ into a specific format.
5351
5452 Args:
5553 obj (dict or list): The dictionary or list containing date strings to convert.
@@ -60,7 +58,7 @@ def convert_datetime(obj):
6058 if isinstance (obj , dict ):
6159 for key , value in obj .items ():
6260 if isinstance (value , dict ) or isinstance (value , list ):
63- obj [key ] = convert_datetime (value )
61+ obj [key ] = convert_obj_datetimes (value )
6462 elif isinstance (value , str ):
6563 try :
6664 obj [key ] = parse_datestring (value )
@@ -76,5 +74,5 @@ def convert_datetime(obj):
7674 except ValueError :
7775 pass # If parsing fails, retain the original value
7876 elif isinstance (value , list ):
79- obj [i ] = convert_datetime (value ) # Recursively handle nested lists
77+ obj [i ] = convert_obj_datetimes (value ) # Recursively handle nested lists
8078 return obj
0 commit comments