diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index 2ce69998f..c51c94093 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -342,7 +342,7 @@ class FunCommands(callbacks.Privmsg): def uptime(self, irc, msg, args): "takes no arguments" response = 'I have been running for %s.' % \ - utils.timeElapsed(time.time(), world.startedAt) + utils.timeElapsed(time.time() - world.startedAt) irc.reply(msg, response) diff --git a/plugins/Notes.py b/plugins/Notes.py index 7256bba8e..12e4d87a6 100644 --- a/plugins/Notes.py +++ b/plugins/Notes.py @@ -197,7 +197,7 @@ class Notes(callbacks.Privmsg): irc.error(msg, 'You are not the recipient of note %s.' % noteid) return public = int(public) - elapsed = utils.timeElapsed(time.time(), int(added_at)) + elapsed = utils.timeElapsed(time.time() - int(added_at)) newnote = "%s (Sent by %s %s ago)" % (note, author, elapsed) if public: irc.reply(msg, newnote) diff --git a/plugins/RSS.py b/plugins/RSS.py index d145f8a61..94501956e 100644 --- a/plugins/RSS.py +++ b/plugins/RSS.py @@ -141,7 +141,7 @@ class RSS(callbacks.Privmsg): # check the 'modified' key, if it's there, convert it here first if 'modified' in feed: seconds = time.mktime(feed['modified']) - when = utils.timeElapsed(time.time(), seconds) + ' ago' + when = utils.timeElapsed(time.time() - seconds) + ' ago' else: when = "time unavailable" # The rest of the entries are all available in the channel key diff --git a/src/utils.py b/src/utils.py index 18c347649..0024678aa 100755 --- a/src/utils.py +++ b/src/utils.py @@ -89,10 +89,10 @@ def abbrev(strings): del d[key] return d -def timeElapsed(now, then, leadingZeroes=False, years=True, weeks=True, +def timeElapsed(elapsed, leadingZeroes=False, years=True, weeks=True, days=True, hours=True, minutes=True, seconds=True): - assert days or hours or minutes or seconds, 'One flag must be True' - elapsed = int(now - then) + assert years or weeks or days or \ + hours or minutes or seconds, 'One flag must be True' ret = [] if years: yrs, elapsed = elapsed // 31536000, elapsed % 31536000 diff --git a/test/test_utils.py b/test/test_utils.py index d074694fa..64fe48a5b 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -47,7 +47,7 @@ class UtilsTest(unittest.TestCase): (122, '2 minutes and 2 seconds'), (3722, '1 hour, 2 minutes and 2 seconds'), (7322, '2 hours, 2 minutes and 2 seconds')]: - self.assertEqual(utils.timeElapsed(now, then), expected) + self.assertEqual(utils.timeElapsed(now - then), expected) def testEachSubstring(self): s = 'foobar'