Fix (de)serialization of negative timestamps (#1241)

This commit is contained in:
binares
2019-08-01 19:47:38 +03:00
committed by Lonami
parent 2ace4fde41
commit 2b277dd558
2 changed files with 27 additions and 12 deletions

View File

@@ -2,14 +2,18 @@
This module contains the BinaryReader utility class.
"""
import os
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
from io import BufferedReader, BytesIO
from struct import unpack
import time
from ..errors import TypeNotFoundError
from ..tl.alltlobjects import tlobjects
from ..tl.core import core_objects
_EPOCH_NAIVE = datetime(*time.gmtime(0)[:6])
_EPOCH = _EPOCH_NAIVE.replace(tzinfo=timezone.utc)
class BinaryReader:
"""
@@ -120,10 +124,7 @@ class BinaryReader:
into a Python datetime object.
"""
value = self.read_int()
if value == 0:
return None
else:
return datetime.fromtimestamp(value, tz=timezone.utc)
return _EPOCH + timedelta(seconds=value)
def tgread_object(self):
"""Reads a Telegram object."""