Support timedelta as datetimes

This commit is contained in:
Lonami Exo 2018-07-09 13:36:52 +02:00
parent 1437b69829
commit 4328663c78

View File

@ -1,5 +1,5 @@
import struct
from datetime import datetime, date
from datetime import datetime, date, timedelta
class TLObject:
@ -125,6 +125,9 @@ class TLObject:
dt = int(datetime(dt.year, dt.month, dt.day).timestamp())
elif isinstance(dt, float):
dt = int(dt)
elif isinstance(dt, timedelta):
# Timezones are tricky. datetime.now() + ... timestamp() works
dt = int((datetime.now() + dt).timestamp())
if isinstance(dt, int):
return struct.pack('<I', dt)