Skip to content

Instantly share code, notes, and snippets.

@sugar84
Created June 24, 2011 11:31
Show Gist options
  • Save sugar84/1044608 to your computer and use it in GitHub Desktop.
Save sugar84/1044608 to your computer and use it in GitHub Desktop.
format elapsed time
sub format_time {
my $time = shift;
use integer;
my $formatted;
for my $unit (["д", 60*60*24], ["ч", 60*60], ["м", 60], ["с", 1]) {
my $res = $time / $unit->[1];
if ($res > 0) {
$formatted .= $res . $unit->[0] . " ";
$time = $time % $unit->[1];
}
}
return defined $formatted ? $formatted : "неизвестно";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment