mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 19:20:09 +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.
|
||||
"""
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from io import BufferedReader, BytesIO
|
||||
from struct import unpack
|
||||
|
||||
|
@ -120,10 +120,10 @@ class BinaryReader:
|
|||
into a Python datetime object.
|
||||
"""
|
||||
value = self.read_int()
|
||||
if value <= 0:
|
||||
if value == 0:
|
||||
return None
|
||||
else:
|
||||
return datetime.fromtimestamp(value, tz=timezone.utc)
|
||||
return datetime.fromtimestamp(0, tz=timezone.utc) + timedelta(seconds=value)
|
||||
|
||||
def tgread_object(self):
|
||||
"""Reads a Telegram object."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user