X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FFormat.pm;fp=src%2FPVE%2FFormat.pm;h=4c48f2f78cbc467e121bb7290e209240c8605bcf;hp=366bc161a0514a5139356c6e0839c3b6c7a7efd5;hb=969c4ffd9e5c5d43298cb113b1e055e185c5cccc;hpb=d3ef19c104207d7c0dd42b5a20c9c86b9172e8e9 diff --git a/src/PVE/Format.pm b/src/PVE/Format.pm index 366bc16..4c48f2f 100644 --- a/src/PVE/Format.pm +++ b/src/PVE/Format.pm @@ -29,7 +29,7 @@ sub render_timestamp_gmt { } sub render_duration { - my ($duration_in_seconds) = @_; + my ($duration_in_seconds, $auto_limit_accuracy) = @_; my $text = ''; my $rest = round($duration_in_seconds // 0); @@ -39,18 +39,20 @@ sub render_duration { my $step = sub { my ($unit, $unitlength) = @_; - if ((my $v = int($rest/$unitlength)) > 0) { + if ((my $v = int($rest / $unitlength)) > 0) { $text .= " " if length($text); $text .= "${v}${unit}"; $rest -= $v * $unitlength; + return 1; } + return undef; }; - $step->('w', 7*24*3600); - $step->('d', 24*3600); + my $weeks = $step->('w', 7 * 24 * 3600); + my $days = $step->('d', 24 * 3600) || $weeks; $step->('h', 3600); - $step->('m', 60); - $step->('s', 1); + $step->('m', 60) if !$auto_limit_accuracy || !$weeks; + $step->('s', 1) if !$auto_limit_accuracy || !$days; return $text; }