Commit a6ffc468 authored by mathieui's avatar mathieui

Fix common.py for OLD python3 versions

parent 09254dab
......@@ -9,8 +9,10 @@
Various useful functions.
"""
from sys import version_info
from datetime import datetime, timedelta
from sleekxmpp import JID, InvalidJID
import base64
import os
import mimetypes
......@@ -20,6 +22,11 @@ import time
import string
import poezio_shlex as shlex
# Needed to avoid datetime.datetime.timestamp()
# on python < 3.3. Older versions do not get good dst detection.
OLD_PYTHON = (version_info.major + version_info.minor/10) < 3.3
ROOM_STATE_NONE = 11
ROOM_STATE_CURRENT = 10
ROOM_STATE_PRIVATE = 15
......@@ -234,7 +241,10 @@ def get_utc_time(local_time=None):
local_time = datetime.now()
isdst = time.localtime().tm_isdst
else:
isdst = time.localtime(int(local_time.timestamp())).tm_isdst
if OLD_PYTHON:
isdst = time.localtime().tm_isdst
else:
isdst = time.localtime(int(local_time.timestamp())).tm_isdst
if time.daylight and isdst:
tz = timedelta(seconds=time.altzone)
......@@ -255,7 +265,10 @@ def get_local_time(utc_time):
>>> get_local_time(d) == d - delta
True
"""
isdst = time.localtime(int(utc_time.timestamp())).tm_isdst
if OLD_PYTHON:
isdst = time.localtime().tm_isdst
else:
isdst = time.localtime(int(utc_time.timestamp())).tm_isdst
if time.daylight and isdst:
tz = timedelta(seconds=time.altzone)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment