diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-24 22:58:00 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-24 22:58:00 +0100 |
commit | ab5703bcdf888e0ea9d65ba194eaeea922f72146 (patch) | |
tree | 65413c5355dfc5295fcf650c4ba75e2246fc2bf7 /lib/rbot | |
parent | 78ccfb89403dc2fd2c06d4bbaca2129e2ba4c968 (diff) |
utils: Utils.secs_to_short convert seconds into hour:minute:seconds format etc
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/utils/utils.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb index 529c37bd..7b1ff7f1 100644 --- a/lib/rbot/core/utils/utils.rb +++ b/lib/rbot/core/utils/utils.rb @@ -223,6 +223,22 @@ module ::Irc end end + # Turn a number of seconds into a hours:minutes:seconds e.g. + # 3:18:10 or 5'12" or 7s + # + def Utils.secs_to_short(seconds) + secs = seconds.to_i # make sure it's an integer + mins, secs = secs.divmod 60 + hours, mins = mins.divmod 60 + if hours > 0 + return ("%s:%s:%s" % [hours, mins, secs]) + elsif mins > 0 + return ("%s'%s\"" % [mins, secs]) + else + return ("%ss" % [secs]) + end + end + # Execute an external program, returning a String obtained by redirecting # the program's standards errors and output |