From d7795f99ed3fb52564fa6d2340d928ae9b191e5b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 8 Oct 2014 02:55:05 +0000 Subject: pretty cart length 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 $('').append($('').text(elem)) .append($('').text(cart.title)) - .append($('').text(cart.length)) + .append($('').text(msToTimeString(cart.length))) .append($('').text(cart.imported)) .append($('').text(cart.playcnt)) .append($('').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('
×

' + heading + '

' + message + '
'); } +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 -- cgit v0.10.2