From 8b6f5953a7da9486daca160f8b5699281a1057df Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 Jul 2017 22:20:30 +0100 Subject: 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. --- slixmpp/plugins/xep_0319/idle.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/slixmpp/plugins/xep_0319/idle.py b/slixmpp/plugins/xep_0319/idle.py index 65500706..9d77ed96 100644 --- a/slixmpp/plugins/xep_0319/idle.py +++ b/slixmpp/plugins/xep_0319/idle.py @@ -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) -- cgit v1.2.3