summaryrefslogtreecommitdiff
path: root/lib/rbot/utils.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-30 21:35:57 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-30 21:35:57 +0000
commitd30940cb5ff75cf7eab81f6a588b3b5297a762ad (patch)
treeb3f0a62c9255b2ecb8a4f2c927bd116e220b0594 /lib/rbot/utils.rb
parent992ef2edbf3eed7cb1d7c4c22f72cd203aff2aa5 (diff)
Sat Jul 30 22:33:36 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Config items are now objects, various types are available. * The config wizard will now use registered config items if :wizard is set to true for those items. It will ask questions in the order they were registered. * The config module now works for doing runtime configuration. * misc refactoring
Diffstat (limited to 'lib/rbot/utils.rb')
-rw-r--r--lib/rbot/utils.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/rbot/utils.rb b/lib/rbot/utils.rb
index 4c474ae4..a1a8c484 100644
--- a/lib/rbot/utils.rb
+++ b/lib/rbot/utils.rb
@@ -6,6 +6,24 @@ module Irc
# miscellaneous useful functions
module Utils
+ # turn a number of seconds into a human readable string, e.g
+ # 2 days, 3 hours, 18 minutes, 10 seconds
+ def Utils.secs_to_string(secs)
+ ret = ""
+ days = (secs / (60 * 60 * 24)).to_i
+ secs = secs % (60 * 60 * 24)
+ hours = (secs / (60 * 60)).to_i
+ secs = (secs % (60 * 60))
+ mins = (secs / 60).to_i
+ secs = (secs % 60).to_i
+ ret += "#{days} days, " if days > 0
+ ret += "#{hours} hours, " if hours > 0 || days > 0
+ ret += "#{mins} minutes and " if mins > 0 || hours > 0 || days > 0
+ ret += "#{secs} seconds"
+ return ret
+ end
+
+
def Utils.safe_exec(command, *args)
IO.popen("-") {|p|
if(p)