From da2cec32eb493ac3196a5de59e23b8daf4e4b3ec Mon Sep 17 00:00:00 2001 From: nyuszika7h Date: Mon, 24 Nov 2014 18:53:32 +0100 Subject: [PATCH] Time.time: Work around a Python bug There is a bug [1] in older versions of Python (reproduced up to 2.7.5 and 3.2.3) where time.strftime('%z') would always give '+0000' if it's given an argument. It's closed as "not a bug", but appears to be fixed in recent versions. To work around this, datetime and dateutil is used now when available. [1] http://bugs.python.org/issue1493676 --- plugins/Time/plugin.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/Time/plugin.py b/plugins/Time/plugin.py index 2c325f0c2..e3c0b3df2 100644 --- a/plugins/Time/plugin.py +++ b/plugins/Time/plugin.py @@ -58,6 +58,11 @@ try: except ImportError: parse = None +try: + from dateutil.tz import tzlocal +except ImportError: + tzlocal = None + class Time(callbacks.Plugin): @internationalizeDocstring def seconds(self, irc, msg, args): @@ -160,7 +165,13 @@ class Time(callbacks.Plugin): format = self.registryValue('format', channel) else: format = self.registryValue('format') - irc.reply(time.strftime(format, time.localtime(seconds))) + if tzlocal: + irc.reply(datetime.fromtimestamp(seconds, tzlocal()).strftime(format)) + else: + # NOTE: This has erroneous behavior on some older Python versions, + # including at least up to 2.7.5 and 3.2.3. Install dateutil if you + # can't upgrade Python. + irc.reply(time.strftime(format, time.localtime(seconds))) time = wrap(time, [optional('channel'), optional('nonInt'), additional('float', TIME.time)])