Use _EPOCH instead of datetime.fromtimestamp(0)

Also BinaryReader.tgread_date will not return None any more on 0 valued int, as the client is not expected to receive "empty" timestamps.
#1241
This commit is contained in:
binares 2019-07-28 20:09:56 +03:00 committed by GitHub
parent 03bd3aa8dc
commit 612516c1e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,11 +5,15 @@ import os
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(0, tz=timezone.utc) + timedelta(seconds=value)
return _EPOCH + timedelta(seconds=value)
def tgread_object(self):
"""Reads a Telegram object."""