[pve-devel] [pve-common] CLIFormatter - implement renderer for timestamps

Dietmar Maurer dietmar at proxmox.com
Wed Jul 4 13:28:27 CEST 2018


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/CLIFormatter.pm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
index 18e408b..eff6da5 100644
--- a/src/PVE/CLIFormatter.pm
+++ b/src/PVE/CLIFormatter.pm
@@ -3,6 +3,7 @@ package PVE::CLIFormatter;
 use strict;
 use warnings;
 use I18N::Langinfo;
+use POSIX qw(strftime);
 
 use PVE::JSONSchema;
 use PVE::PTY;
@@ -10,6 +11,15 @@ use JSON;
 use utf8;
 use Encode;
 
+sub render_timestamp {
+    my ($epoch) = @_;
+
+    # ISO 8601 date format
+    return strftime("%F %H:%M:%S", localtime($epoch));
+}
+
+PVE::JSONSchema::register_renderer('timestamp', \&render_timestamp);
+
 sub render_duration {
     my ($duration_in_seconds) = @_;
 
-- 
2.11.0




More information about the pve-devel mailing list