From 6d315ebf16ce941d003175a24d2cfb85ecad6da5 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 26 Aug 2021 03:49:30 -0500 Subject: [PATCH] Preserve tzinfo when parsing datetime for API v2 models Poll.end_datetime, Tweet.created_at, and User.created_at are now aware, rather than naive, datetime objects. Resolves #1634 --- tweepy/poll.py | 2 +- tweepy/tweet.py | 2 +- tweepy/user.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tweepy/poll.py b/tweepy/poll.py index 8c7958f..77137db 100644 --- a/tweepy/poll.py +++ b/tweepy/poll.py @@ -24,7 +24,7 @@ class Poll(HashableID, DataMapping): self.end_datetime = data.get("end_datetime") if self.end_datetime is not None: self.end_datetime = datetime.datetime.strptime( - self.end_datetime, "%Y-%m-%dT%H:%M:%S.%fZ" + self.end_datetime, "%Y-%m-%dT%H:%M:%S.%f%z" ) self.voting_status = data.get("voting_status") diff --git a/tweepy/tweet.py b/tweepy/tweet.py index 3ec23d3..d4aa568 100644 --- a/tweepy/tweet.py +++ b/tweepy/tweet.py @@ -38,7 +38,7 @@ class Tweet(HashableID, DataMapping): self.created_at = data.get("created_at") if self.created_at is not None: self.created_at = datetime.datetime.strptime( - self.created_at, "%Y-%m-%dT%H:%M:%S.%fZ" + self.created_at, "%Y-%m-%dT%H:%M:%S.%f%z" ) self.entities = data.get("entities") diff --git a/tweepy/user.py b/tweepy/user.py index 844a901..9d80cff 100644 --- a/tweepy/user.py +++ b/tweepy/user.py @@ -24,7 +24,7 @@ class User(HashableID, DataMapping): self.created_at = data.get("created_at") if self.created_at is not None: self.created_at = datetime.datetime.strptime( - self.created_at, "%Y-%m-%dT%H:%M:%S.%fZ" + self.created_at, "%Y-%m-%dT%H:%M:%S.%f%z" ) self.description = data.get("description") -- 2.25.1