diff --git a/telethon/extensions/binaryreader.py b/telethon/extensions/binaryreader.py index a138c255..5382caaf 100644 --- a/telethon/extensions/binaryreader.py +++ b/telethon/extensions/binaryreader.py @@ -2,7 +2,7 @@ This module contains the BinaryReader utility class. """ import os -from datetime import datetime +from datetime import datetime, timezone from io import BufferedReader, BytesIO from struct import unpack @@ -120,7 +120,10 @@ class BinaryReader: into a Python datetime object. """ value = self.read_int() - return None if value == 0 else datetime.utcfromtimestamp(value) + if value == 0: + return None + else: + return datetime.fromtimestamp(value, tz=timezone.utc) def tgread_object(self): """Reads a Telegram object.""" diff --git a/telethon/tl/tlobject.py b/telethon/tl/tlobject.py index 3561f18f..52b86b71 100644 --- a/telethon/tl/tlobject.py +++ b/telethon/tl/tlobject.py @@ -24,10 +24,6 @@ class TLObject: return '[{}]'.format( ', '.join(TLObject.pretty_format(x) for x in obj) ) - elif isinstance(obj, datetime): - return 'datetime.utcfromtimestamp({})'.format( - int(obj.timestamp()) - ) else: return repr(obj) else: