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:
binares 2019-07-26 02:08:06 +03:00 committed by GitHub
parent 14b1226066
commit c1123e1eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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."""