Merge pull request #914 from nyuszika7h/time-workaround-python-bug

Time.time: Work around a Python bug
This commit is contained in:
Valentin Lorentz 2014-11-26 08:19:07 +01:00
commit 175a646500

View File

@ -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,6 +165,12 @@ class Time(callbacks.Plugin):
format = self.registryValue('format', channel)
else:
format = self.registryValue('format')
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)])