From 92e4062b788ec872755f977911dab5c5bd1602f8 Mon Sep 17 00:00:00 2001 From: Andreas Scherbaum Date: Sun, 22 Jan 2012 13:25:13 +0100 Subject: [PATCH] - add first time format function --- docbot.pl | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/docbot.pl b/docbot.pl index a04ac8c..4df50ad 100755 --- 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 -- 2.39.5