Fix serialize_datetime (edits)

Add checks to prevent `struct.pack()` from failing and for users to not use dates outside the ranges of 1970 to 2038.
This commit is contained in:
ChoiHwaa 2022-06-14 22:59:11 +01:00 committed by GitHub
parent be6bb94e00
commit 730a8ed380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -135,7 +135,11 @@ class TLObject:
dt = int(dt.total_seconds())
except OSError:
dt = 0
# 2145916800 is the date 2038, 1, 1.
if dt > 2145916800:
raise ValueError("Date is outside the range of valid values.")
if isinstance(dt, int):
return struct.pack('<i', dt)