From 16a208cbdd9a01704ed182086b812fb2d6abb7bd Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 26 Aug 2021 04:32:37 -0500 Subject: [PATCH] Handle aware datetime objects for start_time and end_time parameters Adjust date and time to UTC rather than ignoring tzinfo --- tweepy/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tweepy/client.py b/tweepy/client.py index a8e3ce0..1305604 100644 --- a/tweepy/client.py +++ b/tweepy/client.py @@ -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: -- 2.25.1