add portal age, in days/hours/etc to tooltip along with existing capture timestamp in portal info panel

This commit is contained in:
Jon Atkins 2013-11-10 21:39:57 +00:00
parent fddf28bc51
commit df3a8adcb2
2 changed files with 13 additions and 8 deletions

View File

@ -31,7 +31,8 @@ window.renderPortalDetails = function(guid) {
var playerText = player ? ['owner', player] : null;
var time = d.captured
? '<span title="' + unixTimeToDateTimeString(d.captured.capturedTime, false) + '">'
? '<span title="' + unixTimeToDateTimeString(d.captured.capturedTime, false) + '\n'
+ formatInterval(Math.floor((Date.now()-d.captured.capturedTime)/1000), 2) + ' ago">'
+ unixTimeToString(d.captured.capturedTime) + '</span>'
: null;
var sinceText = time ? ['since', time] : null;

View File

@ -208,18 +208,22 @@ window.unixTimeToHHmm = function(time) {
return h + ':' + s;
}
window.formatInterval = function(seconds) {
window.formatInterval = function(seconds,maxTerms) {
var h = Math.floor(seconds / 3600);
var d = Math.floor(seconds / 86400);
var h = Math.floor((seconds % 86400) / 3600);
var m = Math.floor((seconds % 3600) / 60);
var s = seconds % 60;
var text = '';
if (h > 0) text += h+'h';
if (m > 0) text += m+'m';
if (s > 0 || text == '') text += s+'s';
var terms = [];
if (d > 0) terms.push(d+'d');
if (h > 0) terms.push(h+'h');
if (m > 0) terms.push(m+'m');
if (s > 0 || terms.length==0) terms.push(s+'s');
return text;
if (maxTerms) terms = terms.slice(0,maxTerms);
return terms.join(' ');
}