mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-03 03:30:09 +03:00
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:
parent
03bd3aa8dc
commit
612516c1e0
|
@ -5,11 +5,15 @@ import os
|
||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timezone, timedelta
|
||||||
from io import BufferedReader, BytesIO
|
from io import BufferedReader, BytesIO
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
import time
|
||||||
|
|
||||||
from ..errors import TypeNotFoundError
|
from ..errors import TypeNotFoundError
|
||||||
from ..tl.alltlobjects import tlobjects
|
from ..tl.alltlobjects import tlobjects
|
||||||
from ..tl.core import core_objects
|
from ..tl.core import core_objects
|
||||||
|
|
||||||
|
_EPOCH_NAIVE = datetime(*time.gmtime(0)[:6])
|
||||||
|
_EPOCH = _EPOCH_NAIVE.replace(tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
class BinaryReader:
|
class BinaryReader:
|
||||||
"""
|
"""
|
||||||
|
@ -120,10 +124,7 @@ class BinaryReader:
|
||||||
into a Python datetime object.
|
into a Python datetime object.
|
||||||
"""
|
"""
|
||||||
value = self.read_int()
|
value = self.read_int()
|
||||||
if value == 0:
|
return _EPOCH + timedelta(seconds=value)
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return datetime.fromtimestamp(0, tz=timezone.utc) + timedelta(seconds=value)
|
|
||||||
|
|
||||||
def tgread_object(self):
|
def tgread_object(self):
|
||||||
"""Reads a Telegram object."""
|
"""Reads a Telegram object."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user