aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-07-09 04:20:45 -0400
committerRapptz <[email protected]>2021-07-09 04:20:45 -0400
commit8fb998b599bda792219e793ae7a48ba92263e44c (patch)
tree61e7a028005547b9dfe56fded02f72ea5747a726
parentChange WEBHOOK_UPDATE to use guild information from gateway (diff)
downloaddiscord.py-8fb998b599bda792219e793ae7a48ba92263e44c.tar.xz
discord.py-8fb998b599bda792219e793ae7a48ba92263e44c.zip
Refactor utcfromtimestamp to use fromtimestamp(..., tz=utc)
-rw-r--r--discord/activity.py16
-rw-r--r--discord/state.py3
-rw-r--r--discord/utils.py2
3 files changed, 10 insertions, 11 deletions
diff --git a/discord/activity.py b/discord/activity.py
index cbe1552f..3f89c477 100644
--- a/discord/activity.py
+++ b/discord/activity.py
@@ -131,7 +131,7 @@ class BaseActivity:
.. versionadded:: 1.3
"""
if self._created_at is not None:
- return datetime.datetime.utcfromtimestamp(self._created_at / 1000).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(self._created_at / 1000, tz=datetime.timezone.utc)
def to_dict(self) -> ActivityPayload:
raise NotImplementedError
@@ -276,7 +276,7 @@ class Activity(BaseActivity):
except KeyError:
return None
else:
- return datetime.datetime.utcfromtimestamp(timestamp).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
@property
def end(self) -> Optional[datetime.datetime]:
@@ -286,7 +286,7 @@ class Activity(BaseActivity):
except KeyError:
return None
else:
- return datetime.datetime.utcfromtimestamp(timestamp).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
@property
def large_image_url(self) -> Optional[str]:
@@ -386,14 +386,14 @@ class Game(BaseActivity):
def start(self) -> Optional[datetime.datetime]:
"""Optional[:class:`datetime.datetime`]: When the user started playing this game in UTC, if applicable."""
if self._start:
- return datetime.datetime.utcfromtimestamp(self._start / 1000).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(self._start / 1000, tz=datetime.timezone.utc)
return None
@property
def end(self) -> Optional[datetime.datetime]:
"""Optional[:class:`datetime.datetime`]: When the user will stop playing this game in UTC, if applicable."""
if self._end:
- return datetime.datetime.utcfromtimestamp(self._end / 1000).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(self._end / 1000, tz=datetime.timezone.utc)
return None
def __str__(self) -> str:
@@ -586,7 +586,7 @@ class Spotify:
.. versionadded:: 1.3
"""
if self._created_at is not None:
- return datetime.datetime.utcfromtimestamp(self._created_at / 1000).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(self._created_at / 1000, tz=datetime.timezone.utc)
@property
def colour(self) -> Colour:
@@ -689,12 +689,12 @@ class Spotify:
@property
def start(self) -> datetime.datetime:
""":class:`datetime.datetime`: When the user started playing this song in UTC."""
- return datetime.datetime.utcfromtimestamp(self._timestamps['start'] / 1000).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(self._timestamps['start'] / 1000, tz=datetime.timezone.utc)
@property
def end(self) -> datetime.datetime:
""":class:`datetime.datetime`: When the user will stop playing this song in UTC."""
- return datetime.datetime.utcfromtimestamp(self._timestamps['end'] / 1000).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(self._timestamps['end'] / 1000, tz=datetime.timezone.utc)
@property
def duration(self) -> datetime.timedelta:
diff --git a/discord/state.py b/discord/state.py
index 4965e531..b98a0a8e 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -1234,8 +1234,7 @@ class ConnectionState:
member = utils.find(lambda x: x.id == user_id, channel.recipients)
if member is not None:
- timestamp = datetime.datetime.utcfromtimestamp(data.get('timestamp'))
- timestamp = timestamp.replace(tzinfo=datetime.timezone.utc)
+ timestamp = datetime.datetime.fromtimestamp(data.get('timestamp'), tz=datetime.timezone.utc)
self.dispatch('typing', channel, member, timestamp)
def _get_reaction_user(self, channel, user_id):
diff --git a/discord/utils.py b/discord/utils.py
index b5563a67..9fda2cab 100644
--- a/discord/utils.py
+++ b/discord/utils.py
@@ -323,7 +323,7 @@ def snowflake_time(id: int) -> datetime.datetime:
An aware datetime in UTC representing the creation time of the snowflake.
"""
timestamp = ((id >> 22) + DISCORD_EPOCH) / 1000
- return datetime.datetime.utcfromtimestamp(timestamp).replace(tzinfo=datetime.timezone.utc)
+ return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
def time_snowflake(dt: datetime.datetime, high: bool = False) -> int: