diff --git a/lib/infobox/node.js b/lib/infobox/node.js index 9c8a17a..b54829e 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -52,7 +52,7 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'], return undefined; } - return moment.duration(d.uptime, 'seconds').humanize(); + return moment.utc(d.uptime).local().fromNow(true); } function showFirstseen(d) { diff --git a/lib/nodelist.js b/lib/nodelist.js index 392324a..4064425 100644 --- a/lib/nodelist.js +++ b/lib/nodelist.js @@ -2,28 +2,18 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) { 'use strict'; V = V.default; - function getUptime(now, d) { - if (d.is_online && 'uptime' in d) { - return Math.round(d.uptime); - } else if (!d.is_online && 'lastseen' in d) { - return Math.round(-(now.unix() - d.lastseen.unix())); - } - return 0; - } - function showUptime(uptime) { - var s = ''; - uptime /= 3600; - - if (uptime !== undefined) { - if (Math.abs(uptime) >= 24) { - s = Math.round(uptime / 24) + 'd'; - } else { - s = Math.round(uptime) + 'h'; - } + // 1000ms are 1 second and 60 second are 1min: 60 * 1000 = 60000 + var s = uptime / 60000; + if (Math.abs(s) < 60) { + return Math.round(s) + ' m'; } - - return s; + s /= 60; + if (Math.abs(s) < 24) { + return Math.round(s) + ' h'; + } + s /= 24; + return Math.round(s) + ' d'; } var headings = [{ @@ -101,7 +91,11 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) { this.setData = function setData(d) { var data = d.nodes.all.map(function (e) { var n = Object.create(e); - n.uptime = getUptime(d.now, e); + if (e.is_online) { + n.uptime = d.now - new Date(e.uptime).getTime(); + } else { + n.uptime = e.lastseen - d.now; + } n.neighbours = e.neighbours; return n; });