mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-09-20 10:52:39 +03:00
Safe way of parsing timestamps.
I left the `if value == 0: return None`, because I assume `0` denotes a "missing" timestamp?
This commit is contained in:
parent
14b1226066
commit
c1123e1eb3
|
@ -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, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
from io import BufferedReader, BytesIO
|
from io import BufferedReader, BytesIO
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
|
@ -120,10 +120,10 @@ class BinaryReader:
|
||||||
into a Python datetime object.
|
into a Python datetime object.
|
||||||
"""
|
"""
|
||||||
value = self.read_int()
|
value = self.read_int()
|
||||||
if value <= 0:
|
if value == 0:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return datetime.fromtimestamp(value, tz=timezone.utc)
|
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