From: Stefan Reiter <s.reiter@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 common 2/6] format: handle undef, 0, and decimals in render_duration
Date: Mon, 8 Feb 2021 12:15:08 +0100 [thread overview]
Message-ID: <20210208111512.27281-2-s.reiter@proxmox.com> (raw)
In-Reply-To: <20210208111512.27281-1-s.reiter@proxmox.com>
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
This might be a "breaking" change for some situations, but I believe this should
be more correct in the long run... If this is not wanted, we must do a ceil() or
similar on the value passed in from patch 4/6, otherwise it will not print a
time value for the first iteration.
src/PVE/Format.pm | 6 ++++--
test/format_test.pl | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/PVE/Format.pm b/src/PVE/Format.pm
index 7c3c062..b345129 100644
--- a/src/PVE/Format.pm
+++ b/src/PVE/Format.pm
@@ -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) = @_;
diff --git a/test/format_test.pl b/test/format_test.pl
index b6688ab..32c00f1 100755
--- a/test/format_test.pl
+++ b/test/format_test.pl
@@ -31,9 +31,11 @@ my $render_data = [
["timestamp", 1612776831, undef, "2021-02-08 10:33:51"],
["timestamp_gmt", 0, undef, "1970-01-01 00:00:00"],
["timestamp_gmt", 1612776831, undef, "2021-02-08 09:33:51"],
- ["duration", 0, undef, ""],
+ ["duration", undef, undef, "0s"],
+ ["duration", 0.3, undef, "0s"],
+ ["duration", 0, undef, "0s"],
["duration", 40, undef, "40s"],
- ["duration", 60, undef, "1m"],
+ ["duration", 59.64432, undef, "1m"],
["duration", 110, undef, "1m 50s"],
["duration", 7*24*3829*2, undef, "2w 21h 22m 24s"],
["fraction_as_percentage", 0.412, undef, "41.20%"],
--
2.20.1
next prev parent reply other threads:[~2021-02-08 11:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-08 11:15 [pve-devel] [PATCH v2 common 1/6] extract PVE::Format from PVE::CLIFormatter for reuse Stefan Reiter
2021-02-08 11:15 ` Stefan Reiter [this message]
2021-02-08 14:04 ` [pve-devel] applied: [PATCH v2 common 2/6] format: handle undef, 0, and decimals in render_duration Thomas Lamprecht
2021-02-08 11:15 ` [pve-devel] [PATCH v2 qemu-server 3/6] vzdump: use renderers from Tools instead of duplicating code Stefan Reiter
2021-02-11 16:17 ` [pve-devel] applied: " Thomas Lamprecht
2021-02-08 11:15 ` [pve-devel] [PATCH v2 qemu-server 4/6] savevm: periodically print progress Stefan Reiter
2021-02-11 16:19 ` [pve-devel] applied: " Thomas Lamprecht
2021-02-08 11:15 ` [pve-devel] [PATCH v2 qemu-server 5/6] savevm: show information about drives during snapshot Stefan Reiter
2021-02-11 16:19 ` [pve-devel] applied: " Thomas Lamprecht
2021-02-08 11:15 ` [pve-devel] [PATCH v2 manager 6/6] ui: snapshot: show task viewer for progress log Stefan Reiter
2021-02-11 17:19 ` [pve-devel] applied: " Thomas Lamprecht
2021-02-08 14:03 ` [pve-devel] applied: [PATCH v2 common 1/6] extract PVE::Format from PVE::CLIFormatter for reuse Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210208111512.27281-2-s.reiter@proxmox.com \
--to=s.reiter@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox