From e9fc81fabeac065c6f070e632a8970b3017d267a Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 28 May 2020 13:02:50 +0200 Subject: [PATCH] Utils: add duration format/render from pve-manager Signed-off-by: Dominik Csapak --- Utils.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Utils.js b/Utils.js index 56b1c9a..328164d 100644 --- a/Utils.js +++ b/Utils.js @@ -145,6 +145,26 @@ Ext.define('Proxmox.Utils', { utilities: { return Ext.Date.format(date, "Y-m-d"); }, + format_duration_short: function(ut) { + + if (ut < 60) { + return ut.toFixed(1) + 's'; + } + + if (ut < 3600) { + var mins = ut / 60; + return mins.toFixed(1) + 'm'; + } + + if (ut < 86400) { + var hours = ut / 3600; + return hours.toFixed(1) + 'h'; + } + + var days = ut / 86400; + return days.toFixed(1) + 'd'; + }, + format_duration_long: function(ut) { var days = Math.floor(ut / 86400); @@ -643,6 +663,13 @@ Ext.define('Proxmox.Utils', { utilities: { return task; }, + render_duration: function(value) { + if (value === undefined) { + return '-'; + } + return Proxmox.Utils.format_duration_short(value); + }, + render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) { var servertime = new Date(value * 1000); return Ext.Date.format(servertime, 'Y-m-d H:i:s'); -- 2.39.2