summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-07-17 22:20:30 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-07-17 22:20:30 +0100
commit8b6f5953a7da9486daca160f8b5699281a1057df (patch)
tree8a62864b724175c1cd00f32abfa7fc7907312eab
parent2d2a80c73da0c2da3346ceb55679beb63bb602d0 (diff)
downloadslixmpp-8b6f5953a7da9486daca160f8b5699281a1057df.tar.gz
slixmpp-8b6f5953a7da9486daca160f8b5699281a1057df.tar.bz2
slixmpp-8b6f5953a7da9486daca160f8b5699281a1057df.tar.xz
slixmpp-8b6f5953a7da9486daca160f8b5699281a1057df.zip
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.
-rw-r--r--slixmpp/plugins/xep_0319/idle.py11
1 files 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)