diff --git a/telethon/tl/tlobject.py b/telethon/tl/tlobject.py index 489765e2..0ed7b015 100644 --- a/telethon/tl/tlobject.py +++ b/telethon/tl/tlobject.py @@ -1,4 +1,5 @@ -from datetime import datetime +import struct +from datetime import datetime, date from threading import Event @@ -125,6 +126,23 @@ class TLObject: r.append(bytes(padding)) return b''.join(r) + @staticmethod + def serialize_datetime(dt): + if not dt: + return b'\0\0\0\0' + + if isinstance(dt, datetime): + dt = int(dt.timestamp()) + elif isinstance(dt, date): + dt = int(datetime(dt.year, dt.month, dt.day, dt).timestamp()) + elif isinstance(dt, float): + dt = int(dt) + + if isinstance(dt, int): + return struct.pack('