XEP-0319: Use the correct timezone.

This fixes a specification violation, XEP-0082 says that a date MUST
have a timezone, but we were sending the *local* time without any
timezone information.
This commit is contained in:
Emmanuel Gil Peyrot 2017-07-17 22:20:30 +01:00
parent 2d2a80c73d
commit 8b6f5953a7

View file

@ -6,7 +6,7 @@
See the file LICENSE for copying permission.
"""
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from slixmpp.stanza import Presence
from slixmpp.plugins import BasePlugin
@ -16,6 +16,10 @@ from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.plugins.xep_0319 import stanza
def get_local_timezone():
return datetime.now(timezone.utc).astimezone().tzinfo
class XEP_0319(BasePlugin):
name = 'xep_0319'
description = 'XEP-0319: Last User Interaction in Presence'
@ -47,10 +51,11 @@ class XEP_0319(BasePlugin):
def idle(self, jid=None, since=None):
seconds = None
timezone = get_local_timezone()
if since is None:
since = datetime.now()
since = datetime.now(timezone)
else:
seconds = datetime.now() - since
seconds = datetime.now(timezone) - since
self.api['set_idle'](jid, None, None, since)
self.xmpp['xep_0012'].set_last_activity(jid=jid, seconds=seconds)