diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-11 19:49:20 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-11 19:50:54 +0100 |
commit | 763b142db70ce77952cb46cfccf84d9800f15651 (patch) | |
tree | d2636e48766d365bd8a9d079de603b127ab88744 /module/web/static/js/helpers/formatTime.js | |
parent | Merge pull request #33 from stickell/patch-3 (diff) | |
download | pyload-763b142db70ce77952cb46cfccf84d9800f15651.tar.xz |
websocket login via session, websocket pushes server status, webui renders server status
Diffstat (limited to 'module/web/static/js/helpers/formatTime.js')
-rw-r--r-- | module/web/static/js/helpers/formatTime.js | 40 |
1 files changed, 40 insertions, 0 deletions
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 |