- add first time format function
authorAndreas Scherbaum <andreas@scherbaum.biz>
Sun, 22 Jan 2012 12:25:13 +0000 (13:25 +0100)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Sun, 22 Jan 2012 12:25:13 +0000 (13:25 +0100)
docbot.pl

index a04ac8c51d068b420f5583eb288be2339848d89c..4df50ad82f15877d058f51f8442b5ba3a82a0f5b 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -1270,6 +1270,54 @@ sub is_nick_allowed_operator_command {
 }
 
 
+# format_time_short_exact()
+#
+# format a time in seconds into a human readable short output
+#
+# parameter:
+#  - time in seconds
+# return:
+#  - formatted text
+sub format_time_short_exact {
+    my $time = shift;
+
+    my @return = ();
+
+    my $days = int($time / (24 * 60 * 60));
+    $time -= $days * (24 * 60 * 60);
+
+    my $hours = int($time / (60 * 60));
+    $time -= $hours * (60 * 60);
+
+    my $minutes = int($time / 60);
+    $time -= $minutes * 60;
+
+    my $seconds = $time;
+
+    if ($days > 0) {
+        push(@return, $days . 'd');
+    }
+    if ($hours > 0) {
+        push(@return, $hours . 'h');
+    }
+    if ($minutes > 0) {
+        push(@return, $minutes . 'm');
+    }
+    if ($seconds > 0) {
+        push(@return, $seconds . 's');
+    }
+
+    my $return = join(" ", @return);
+    if (length($return) == 0) {
+        $return = '0s';
+    }
+
+    return $return;
+}
+
+
+
+
 # handle_command()
 #
 # wrapper to handle all commands