Added years and weeks to seconds.

This commit is contained in:
Jeremy Fincher 2004-01-15 17:34:05 +00:00
parent fd294faeee
commit 4cd70bbdd4
2 changed files with 11 additions and 5 deletions

View File

@ -392,10 +392,10 @@ class Misc(callbacks.Privmsg):
'my history of %s messages.' % len(irc.state.history))
def seconds(self, irc, msg, args):
"""[<days>d] [<hours>h] [<minutes>m] [<seconds>s]
"""[<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s]
Returns the number of seconds in the number of <days>, <hours>,
<minutes>, and <seconds> given. An example usage is
Returns the number of seconds in the number of <years>, <weeks>,
<days>, <hours>, <minutes>, and <seconds> 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

View File

@ -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')