summaryrefslogtreecommitdiff
path: root/lib/rbot/utils.rb
diff options
context:
space:
mode:
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)