1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #3748: Add prettyDuration helper

This commit is contained in:
Daniel Molina 2015-06-09 18:13:19 +02:00
parent 775afc760a
commit 2b350794f9

View File

@ -15,6 +15,7 @@ define(function(require) {
'sizeFromB': _sizeFromB,
'sizeFromKB': _sizeFromKB,
'sizeFromMB': _sizeFromMB,
'prettyDuration': _prettyDuration,
'prettyTime': _prettyTime,
'prettyTimeAxis': _prettyTimeAxis,
'prettyPrintJSON': _prettyPrintJSON,
@ -82,6 +83,25 @@ define(function(require) {
return st;
}
function _prettyDuration(duration) {
var days = Math.floor(duration / 86400);
duration -= days * 86400;
var hours = Math.floor(duration / 3600) % 24;
duration -= hours * 3600;
var minutes = Math.floor(duration / 60) % 60;
duration -= minutes * 60;
var seconds = duration % 60;
var str = "";
if (days > 0) { str += days + 'd '};
if (hours > 0) { str += hours + 'h '};
str += minutes + 'm ';
return str;
}
//introduces 0s before a number until in reaches 'length'.
function _pad(number, length) {
var str = '' + number;