Handle aware datetime objects for start_time and end_time parameters
authorHarmon <Harmon758@gmail.com>
Thu, 26 Aug 2021 09:32:37 +0000 (04:32 -0500)
committerHarmon <Harmon758@gmail.com>
Thu, 26 Aug 2021 09:32:37 +0000 (04:32 -0500)
Adjust date and time to UTC rather than ignoring tzinfo

tweepy/client.py

index a8e3ce0beb8a3eaffc675e1771087ab1f6d48daa..1305604c7f7705cbf8243df2f887c08b7006b448 100644 (file)
@@ -131,6 +131,8 @@ class Client:
                 if isinstance(param_value, list):
                     request_params[param_name] = ','.join(map(str, param_value))
                 elif param_name in ("start_time", "end_time") and isinstance(param_value, datetime.datetime):
+                    if param_value.tzinfo is not None:
+                        param_value = param_value.astimezone(datetime.timezone.utc)
                     request_params[param_name] = param_value.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
                     # TODO: Constant datetime format string?
                 else: