]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Format.pm
format: handle undef, 0, and decimals in render_duration
[pve-common.git] / src / PVE / Format.pm
index 7c3c0622e1309f954561c7cd14786d2066080c5a..b345129478f06743b42e2ee4a61be4fa5b6c79c5 100644 (file)
@@ -3,7 +3,7 @@ package PVE::Format;
 use strict;
 use warnings;
 
-use POSIX qw(strftime);
+use POSIX qw(strftime round);
 use PVE::JSONSchema;
 
 use base 'Exporter';
@@ -33,7 +33,9 @@ sub render_duration {
     my ($duration_in_seconds) = @_;
 
     my $text = '';
-    my $rest = $duration_in_seconds;
+    my $rest = round($duration_in_seconds // 0);
+
+    return "0s" if !$rest;
 
     my $step = sub {
        my ($unit, $unitlength) = @_;