]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
Utils: add duration format/render
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 28 May 2020 11:02:50 +0000 (13:02 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 28 May 2020 11:31:24 +0000 (13:31 +0200)
from pve-manager

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Utils.js

index 56b1c9a6aeb91d093a2958f752898c5e99fc2ffe..328164d1d71103fd76bf7fda1f048ea0d0cbf1aa 100644 (file)
--- 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');