mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-26 09:14:31 +03:00
Set timezone info when reading datetimes
This commit is contained in:
parent
8b4c8d30e7
commit
38c65adf35
|
@ -2,7 +2,7 @@
|
||||||
This module contains the BinaryReader utility class.
|
This module contains the BinaryReader utility class.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from io import BufferedReader, BytesIO
|
from io import BufferedReader, BytesIO
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
|
@ -120,7 +120,10 @@ class BinaryReader:
|
||||||
into a Python datetime object.
|
into a Python datetime object.
|
||||||
"""
|
"""
|
||||||
value = self.read_int()
|
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):
|
def tgread_object(self):
|
||||||
"""Reads a Telegram object."""
|
"""Reads a Telegram object."""
|
||||||
|
|
|
@ -24,10 +24,6 @@ class TLObject:
|
||||||
return '[{}]'.format(
|
return '[{}]'.format(
|
||||||
', '.join(TLObject.pretty_format(x) for x in obj)
|
', '.join(TLObject.pretty_format(x) for x in obj)
|
||||||
)
|
)
|
||||||
elif isinstance(obj, datetime):
|
|
||||||
return 'datetime.utcfromtimestamp({})'.format(
|
|
||||||
int(obj.timestamp())
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return repr(obj)
|
return repr(obj)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user