From 4e9bb2c24168ef9b0af1d4c7ef8db242585fa43c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 11 Aug 2013 12:22:12 +0200 Subject: [PATCH] Later: Use builtin support for '%s ago'. --- plugins/Later/plugin.py | 4 ++-- plugins/Later/test.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/Later/plugin.py b/plugins/Later/plugin.py index b617e39a1..8bd00687b 100644 --- a/plugins/Later/plugin.py +++ b/plugins/Later/plugin.py @@ -79,9 +79,9 @@ class Later(callbacks.Plugin): def _timestamp(self, when): #format = conf.supybot.reply.format.time() - diff = time.time() - when + diff = when - time.time() try: - return _('%s ago') % utils.timeElapsed(diff, seconds=False) + return utils.timeElapsed(diff, seconds=False) except ValueError: return _('just now') diff --git a/plugins/Later/test.py b/plugins/Later/test.py index 0481d4dc7..980918f9d 100644 --- a/plugins/Later/test.py +++ b/plugins/Later/test.py @@ -78,9 +78,21 @@ class LaterTestCase(ChannelPluginTestCase): self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'something', prefix=testPrefix)) m = self.getMsg(' ') - self.failUnless(str(m).startswith('PRIVMSG foo :Sent just now: stuff')) + self.assertEqual(str(m).strip(), + 'PRIVMSG foo :Sent just now: stuff') self.assertNotRegexp('later notes', 'foo') 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: more stuff') + time.time = real_time # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: