Set timezone info when reading datetimes

This commit is contained in:
Lonami Exo 2018-07-12 00:30:57 +02:00
parent 8b4c8d30e7
commit 38c65adf35
2 changed files with 5 additions and 6 deletions

View File

@ -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."""

View File

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