Browse Source

Refactor utcfromtimestamp to use fromtimestamp(..., tz=utc)

pull/7192/head
Rapptz 4 years ago
parent
commit
8fb998b599
  1. 16
      discord/activity.py
  2. 3
      discord/state.py
  3. 2
      discord/utils.py

16
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:

3
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):

2
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:

Loading…
Cancel
Save