Later: Use builtin support for '%s ago'.

This commit is contained in:
Valentin Lorentz 2013-08-11 12:22:12 +02:00
parent 1e050d7fa8
commit 4e9bb2c241
2 changed files with 15 additions and 3 deletions

View File

@ -79,9 +79,9 @@ class Later(callbacks.Plugin):
def _timestamp(self, when): def _timestamp(self, when):
#format = conf.supybot.reply.format.time() #format = conf.supybot.reply.format.time()
diff = time.time() - when diff = when - time.time()
try: try:
return _('%s ago') % utils.timeElapsed(diff, seconds=False) return utils.timeElapsed(diff, seconds=False)
except ValueError: except ValueError:
return _('just now') return _('just now')

View File

@ -78,9 +78,21 @@ class LaterTestCase(ChannelPluginTestCase):
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'something', self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'something',
prefix=testPrefix)) prefix=testPrefix))
m = self.getMsg(' ') m = self.getMsg(' ')
self.failUnless(str(m).startswith('PRIVMSG foo :Sent just now: <test> stuff')) self.assertEqual(str(m).strip(),
'PRIVMSG foo :Sent just now: <test> stuff')
self.assertNotRegexp('later notes', 'foo') self.assertNotRegexp('later notes', 'foo')
self.assertRegexp('later notes', 'bar') self.assertRegexp('later notes', 'bar')
real_time = time.time
def fake_time():
return real_time() + 62
time.time = fake_time
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'something',
prefix='bar!baz@qux'))
m = self.getMsg(' ')
self.assertEqual(str(m).strip(),
'PRIVMSG bar :Sent 1 minute ago: <test> more stuff')
time.time = real_time
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: