mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Added years and weeks to seconds.
This commit is contained in:
parent
fd294faeee
commit
4cd70bbdd4
14
src/Misc.py
14
src/Misc.py
@ -392,10 +392,10 @@ class Misc(callbacks.Privmsg):
|
|||||||
'my history of %s messages.' % len(irc.state.history))
|
'my history of %s messages.' % len(irc.state.history))
|
||||||
|
|
||||||
def seconds(self, irc, msg, args):
|
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>,
|
Returns the number of seconds in the number of <years>, <weeks>,
|
||||||
<minutes>, and <seconds> given. An example usage is
|
<days>, <hours>, <minutes>, and <seconds> given. An example usage is
|
||||||
"seconds 2h 30m", which would return 9000, which is 3600*2 + 30*60.
|
"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
|
Useful for scheduling events at a given number of seconds in the
|
||||||
future.
|
future.
|
||||||
@ -404,7 +404,7 @@ class Misc(callbacks.Privmsg):
|
|||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
seconds = 0
|
seconds = 0
|
||||||
for arg in args:
|
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
|
raise callbacks.ArgumentError
|
||||||
(s, kind) = arg[:-1], arg[-1]
|
(s, kind) = arg[:-1], arg[-1]
|
||||||
try:
|
try:
|
||||||
@ -412,7 +412,11 @@ class Misc(callbacks.Privmsg):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
irc.error('Invalid argument: %s' % arg)
|
irc.error('Invalid argument: %s' % arg)
|
||||||
return
|
return
|
||||||
if kind == 'd':
|
if kind == 'y':
|
||||||
|
seconds += i*31536000
|
||||||
|
elif kind == 'w':
|
||||||
|
seconds += i*604800
|
||||||
|
elif kind == 'd':
|
||||||
seconds += i*86400
|
seconds += i*86400
|
||||||
elif kind == 'h':
|
elif kind == 'h':
|
||||||
seconds += i*3600
|
seconds += i*3600
|
||||||
|
@ -204,6 +204,8 @@ class MiscTestCase(ChannelPluginTestCase, PluginDocumentation):
|
|||||||
self.assertResponse('seconds 2m', '120')
|
self.assertResponse('seconds 2m', '120')
|
||||||
self.assertResponse('seconds 2d 2h 2m 2s', '180122')
|
self.assertResponse('seconds 2d 2h 2m 2s', '180122')
|
||||||
self.assertResponse('seconds 1s', '1')
|
self.assertResponse('seconds 1s', '1')
|
||||||
|
self.assertResponse('seconds 1y 1s', '31536001')
|
||||||
|
self.assertResponse('seconds 1w 1s', '604801')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user