diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/shows.js | 4 | ||||
-rw-r--r-- | js/utils.js | 29 |
2 files changed, 26 insertions, 7 deletions
diff --git a/js/shows.js b/js/shows.js index 6da6345..cbf4d73 100644 --- a/js/shows.js +++ b/js/shows.js @@ -167,7 +167,7 @@ function shows_newCartEntry(elem) { return $('<tr>').append($('<td rowspan=2>').text(elem)) .append($('<td>').text(cart.title)) - .append($('<td>').text(cart.length)) + .append($('<td>').text(msToTimeString(cart.length))) .append($('<td>').text(cart.imported)) .append($('<td>').text(cart.playcnt)) .append($('<td>').text(cart.lastplayed)) @@ -190,7 +190,7 @@ function shows_updateGroupCartList(data, status, req) { number = $(this).find('number').text(), cart = { title: $(this).find('title').text(), - length: $(cut).find('length').text(), + length: Number($(cut).find('length').text()), imported: new Date($(cut).find('originDatetime').text()), playcnt: $(cut).find('playCounter').text(), lastplayed: new Date($(cut).find('lastPlayDatetime').text()), diff --git a/js/utils.js b/js/utils.js index cdc06dd..0237594 100644 --- a/js/utils.js +++ b/js/utils.js @@ -9,6 +9,12 @@ alertbox.info = function (dest, heading, message) { $('#' + dest + ' .alertbox').html('<div class="alert alert-info"><a class="close" data-dismiss="alert" href="#">×</a><h4 class="alert-heading">' + heading + '</h4>' + message + '</div>'); } +Number.prototype.pad = function(size) { + var s = String(this); + while (s.length < (size || 2)) {s = "0" + s;} + return s; +} + var weekday = new Array(7); weekday[0] = "Sonntag"; weekday[1] = "Montag"; @@ -22,17 +28,30 @@ function format_datetime(d) { if(Object.prototype.toString.call(d) === "[object Date]") { var daynames = new Array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'); var datetimestr = daynames[d.getDay()]; - datetimestr += ' ' + d.getDate(); - datetimestr += '.' + (d.getMonth() + 1); + datetimestr += ' ' + Number(d.getDate()).pad(2); + datetimestr += '.' + Number(d.getMonth() + 1).pad(2); datetimestr += '.' + d.getFullYear(); - datetimestr += (d.getHours() > 9 ? ' ' : ' 0') + d.getHours(); - datetimestr += (d.getMinutes() > 9 ? ':' : ':0') + d.getMinutes(); - datetimestr += (d.getSeconds() > 9 ? ':' : ':0') + d.getSeconds(); + datetimestr += ' ' + Number(d.getHours()).pad(2); + datetimestr += ':' + Number(d.getMinutes()).pad(2); + datetimestr += ':' + Number(d.getSeconds()).pad(2); return datetimestr; } return d; } +function msToTimeString(time) { + if(time == '-') return time; + + var h = Number(Math.floor(time / 3600000)); + time %= 3600000; + var m = Number(Math.floor(time / 60000)); + time %= 60000; + var s = Number(Math.floor(time / 1000)); + var hs = Number(Math.floor((time % 1000)/100)); + + return h + ':' + m.pad(2) + ':' + s.pad(2) + '.' + hs; +} + function get_rd_week() { // // This computes the current Rivendell Week based on the number |