diff options
author | mathieui <mathieui@mathieui.net> | 2014-04-01 23:25:21 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2014-04-01 23:25:21 +0200 |
commit | a6ffc46827b784a75068a8975ac707c4b81e26d3 (patch) | |
tree | 4bbe4d0e69b03a0300ea93bb9adef2f798f64cf5 | |
parent | 09254dabc7b1736380ab09119aca9833c0ce9683 (diff) | |
download | poezio-a6ffc46827b784a75068a8975ac707c4b81e26d3.tar.gz poezio-a6ffc46827b784a75068a8975ac707c4b81e26d3.tar.bz2 poezio-a6ffc46827b784a75068a8975ac707c4b81e26d3.tar.xz poezio-a6ffc46827b784a75068a8975ac707c4b81e26d3.zip |
Fix common.py for OLD python3 versions
-rw-r--r-- | src/common.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/common.py b/src/common.py index 5467c985..62216b5e 100644 --- a/src/common.py +++ b/src/common.py @@ -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: |