Preserve tzinfo when parsing datetime for API v2 models
authorHarmon <Harmon758@gmail.com>
Thu, 26 Aug 2021 08:49:30 +0000 (03:49 -0500)
committerHarmon <Harmon758@gmail.com>
Thu, 26 Aug 2021 08:49:30 +0000 (03:49 -0500)
Poll.end_datetime, Tweet.created_at, and User.created_at are now aware, rather than naive, datetime objects.
Resolves #1634

tweepy/poll.py
tweepy/tweet.py
tweepy/user.py

index 8c7958f9a6dd4b1e23e492d1001471654e0776b7..77137dba79606277fcc6c5b42e9cb2b9877ec976 100644 (file)
@@ -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")
index 3ec23d398cfa24f9d5d26d02ae782348413698a1..d4aa568fdc05329d17f0f830cbe1c0556716482e 100644 (file)
@@ -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")
index 844a901cf5d45ac4563eefdc539ecd916d5d6cb7..9d80cff8fd948e55c60a2cb4f98c84c27111090c 100644 (file)
@@ -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")