mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
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
This commit is contained in:
parent
283cdb3b1d
commit
da2cec32eb
@ -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)])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user