@@ -137,29 +137,30 @@ def _parse_date(self, param):
137137 except ValueError :
138138 continue
139139 return None
140-
140+
141141 def _parse_datetime (self , param ):
142142 """
143- Attempt to parse a string as a datetime, datetime2, timestamp, or smalldatetime.
144- Handles both naive and timezone-aware datetime strings.
143+ Attempt to parse a string as a datetime, smalldatetime, datetime2, timestamp.
144+
145+ Args:
146+ param: The string to parse.
147+
148+ Returns:
149+ A datetime.datetime object if parsing is successful, else None.
145150 """
146151 formats = [
147- "%Y-%m-%dT%H:%M:%S.%f%z" , # ISO 8601 with fractional seconds + timezone
148- "%Y-%m-%dT%H:%M:%S%z" , # ISO 8601 with timezone
149- "%Y-%m-%d %H:%M:%S.%f%z" , # Space-separated with fractional seconds + timezone
150- "%Y-%m-%d %H:%M:%S%z" , # Space-separated with timezone
151- "%Y-%m-%dT%H:%M:%S.%f" , # ISO 8601 without timezone
152- "%Y-%m-%dT%H:%M:%S" , # ISO 8601 without timezone
153- "%Y-%m-%d %H:%M:%S.%f" , # Space-separated without timezone
154- "%Y-%m-%d %H:%M:%S" , # Space-separated without timezone
152+ "%Y-%m-%dT%H:%M:%S.%f" , # ISO 8601 datetime with fractional seconds
153+ "%Y-%m-%dT%H:%M:%S" , # ISO 8601 datetime
154+ "%Y-%m-%d %H:%M:%S.%f" , # Datetime with fractional seconds
155+ "%Y-%m-%d %H:%M:%S" , # Datetime without fractional seconds
155156 ]
156157 for fmt in formats :
157158 try :
158- dt = datetime .datetime .strptime (param , fmt )
159- return dt
159+ return datetime .datetime .strptime (param , fmt ) # Valid datetime
160160 except ValueError :
161- continue
162- return None # parsing failed
161+ continue # Try next format
162+
163+ return None # If all formats fail, return None
163164
164165 def _parse_time (self , param ):
165166 """
0 commit comments