summaryrefslogtreecommitdiffstats
path: root/module/web/static/js/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'module/web/static/js/helpers')
-rw-r--r--module/web/static/js/helpers/formatSize.js2
-rw-r--r--module/web/static/js/helpers/formatTime.js40
2 files changed, 41 insertions, 1 deletions
diff --git a/module/web/static/js/helpers/formatSize.js b/module/web/static/js/helpers/formatSize.js
index a792392b7..a50588bc6 100644
--- a/module/web/static/js/helpers/formatSize.js
+++ b/module/web/static/js/helpers/formatSize.js
@@ -2,7 +2,7 @@
define('helpers/formatSize', ['handlebars'], function(Handlebars) {
var sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
function formatSize(bytes, options) {
- if (bytes === 0) return '0 B';
+ if (!bytes || bytes === 0) return '0 B';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
// round to two digits
return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
diff --git a/module/web/static/js/helpers/formatTime.js b/module/web/static/js/helpers/formatTime.js
new file mode 100644
index 000000000..cb635ede9
--- /dev/null
+++ b/module/web/static/js/helpers/formatTime.js
@@ -0,0 +1,40 @@
+// Format bytes in human readable format
+define('helpers/formatTime', ['handlebars'], function(Handlebars) {
+
+ // TODO: seconds are language dependant
+ // time could be better formatted
+ function seconds2time (seconds) {
+ var hours = Math.floor(seconds / 3600);
+ var minutes = Math.floor((seconds - (hours * 3600)) / 60);
+ seconds = seconds - (hours * 3600) - (minutes * 60);
+ var time = "";
+
+ if (hours != 0) {
+ time = hours+":";
+ }
+ if (minutes != 0 || time !== "") {
+ minutes = (minutes < 10 && time !== "") ? "0"+minutes : String(minutes);
+ time += minutes+":";
+ }
+ if (time === "") {
+ time = seconds+"s";
+ }
+ else {
+ time += (seconds < 10) ? "0"+seconds : String(seconds);
+ }
+ return time;
+ }
+
+
+ function formatTime(seconds, options) {
+ if (seconds === Infinity)
+ return '∞';
+ else if (!seconds || seconds <= 0)
+ return "-";
+
+ return seconds2time(seconds);
+ }
+
+ Handlebars.registerHelper('formatTime', formatTime);
+ return formatTime;
+}); \ No newline at end of file