Merge branch 'prevent-naive-datetime' into 'master'

XEP-0203: Prevent naïve datetime from being passed

Closes #3471

See merge request poezio/slixmpp!211
This commit is contained in:
Maxime Buquet 2022-07-12 13:38:52 +02:00
commit 356f16f5af

View file

@ -30,6 +30,10 @@ class Delay(ElementBase):
def set_stamp(self, value): def set_stamp(self, value):
if isinstance(value, dt.datetime): if isinstance(value, dt.datetime):
if value.tzinfo is None:
raise ValueError(f'Datetime provided without timezone information: {value}')
if value.tzinfo != dt.timezone.utc:
value = value.astimezone(dt.timezone.utc)
value = xep_0082.format_datetime(value) value = xep_0082.format_datetime(value)
self._set_attr('stamp', value) self._set_attr('stamp', value)