XEP-0203: Prevent naïve datetime from being passed
The specification says “The format MUST adhere to the dateTime format specified in XEP-0082 and MUST be expressed in UTC.” We now respect this requirement, by rejecting naïve datetimes with a ValueError exception, and converting the passed datetime to UTC. Fixes #3471.
This commit is contained in:
parent
5e5a741994
commit
65d70fe417
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user