From 4cd70bbdd4045f7743093c12b8f7e698df632272 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 15 Jan 2004 17:34:05 +0000 Subject: [PATCH] Added years and weeks to seconds. --- src/Misc.py | 14 +++++++++----- test/test_Misc.py | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Misc.py b/src/Misc.py index 54fc39382..6ddc97563 100755 --- a/src/Misc.py +++ b/src/Misc.py @@ -392,10 +392,10 @@ class Misc(callbacks.Privmsg): 'my history of %s messages.' % len(irc.state.history)) def seconds(self, irc, msg, args): - """[d] [h] [m] [s] + """[y] [w] [d] [h] [m] [s] - Returns the number of seconds in the number of , , - , and given. An example usage is + Returns the number of seconds in the number of , , + , , , and given. An example usage is "seconds 2h 30m", which would return 9000, which is 3600*2 + 30*60. Useful for scheduling events at a given number of seconds in the future. @@ -404,7 +404,7 @@ class Misc(callbacks.Privmsg): raise callbacks.ArgumentError seconds = 0 for arg in args: - if not arg or arg[-1] not in 'dhms': + if not arg or arg[-1] not in 'ywdhms': raise callbacks.ArgumentError (s, kind) = arg[:-1], arg[-1] try: @@ -412,7 +412,11 @@ class Misc(callbacks.Privmsg): except ValueError: irc.error('Invalid argument: %s' % arg) return - if kind == 'd': + if kind == 'y': + seconds += i*31536000 + elif kind == 'w': + seconds += i*604800 + elif kind == 'd': seconds += i*86400 elif kind == 'h': seconds += i*3600 diff --git a/test/test_Misc.py b/test/test_Misc.py index fb9fa7a8b..a623fdcc4 100644 --- a/test/test_Misc.py +++ b/test/test_Misc.py @@ -204,6 +204,8 @@ class MiscTestCase(ChannelPluginTestCase, PluginDocumentation): self.assertResponse('seconds 2m', '120') self.assertResponse('seconds 2d 2h 2m 2s', '180122') self.assertResponse('seconds 1s', '1') + self.assertResponse('seconds 1y 1s', '31536001') + self.assertResponse('seconds 1w 1s', '604801')