mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-29 21:54:22 +01:00
Changed utils.timeElapsed to use just a seconds instead of a now/then argument.
This commit is contained in:
parent
345f819e7a
commit
09340376cb
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user