diff --git a/.jshintrc b/.jshintrc index b7e2f6a3..43449b52 100755 --- a/.jshintrc +++ b/.jshintrc @@ -11,6 +11,7 @@ "prototypejs": false, "mootools": false, "dojo": false, + "esversion": 5, "devel": true, @@ -50,4 +51,4 @@ "trailing": true, "white": false, "indent": 2 -} \ No newline at end of file +} diff --git a/lib/forever.js b/lib/forever.js index a44aa03b..26201081 100755 --- a/lib/forever.js +++ b/lib/forever.js @@ -14,7 +14,6 @@ var fs = require('fs'), cliff = require('cliff'), nconf = require('nconf'), nssocket = require('nssocket'), - timespan = require('timespan'), utile = require('utile'), winston = require('winston'), mkdirp = utile.mkdirp, @@ -1037,7 +1036,20 @@ forever.columns = { uptime: { color: 'yellow', get: function (proc) { - return proc.running ? timespan.fromDates(new Date(proc.ctime), new Date()).toString().yellow : "STOPPED".red; + if (!proc.running) { + return "STOPPED".red; + } + + var delta = (new Date().getTime() - proc.ctime) / 1000; + var days = Math.floor(delta / 86400); + delta -= days * 86400; + var hours = Math.floor(delta / 3600) % 24; + delta -= hours * 3600; + var minutes = Math.floor(delta / 60) % 60; + delta -= minutes * 60; + var seconds = delta % 60; + + return (days+':'+hours+':'+minutes+':'+seconds).yellow; } } }; diff --git a/package.json b/package.json index 1db6c649..a221bf05 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,13 @@ "path-is-absolute": "~1.0.0", "prettyjson": "^1.1.2", "shush": "^1.0.0", - "timespan": "~2.3.0", "utile": "~0.2.1", "winston": "~0.8.1" }, "devDependencies": { "broadway": "~0.3.6", "eventemitter2": "0.4.x", + "moment": "^2.23.0", "request": "2.x.x", "vows": "0.7.x" }, diff --git a/test/core/uptime-test.js b/test/core/uptime-test.js new file mode 100644 index 00000000..25aebb64 --- /dev/null +++ b/test/core/uptime-test.js @@ -0,0 +1,28 @@ +var assert = require('assert'), + vows = require('vows'), + moment = require('moment'), + forever = require('../../lib/forever'); + +vows.describe('forever/core/uptime').addBatch({ + "When using forever" : { + "calculates uptime" : { + "for not running process correctly": function (err, procs) { + assert.equal(forever.columns.uptime.get({}), 'STOPPED'.red); + }, + "for running process correctly": function (err, procs) { + var launchTime = moment.utc() + .subtract(4000, 'days') + .subtract(6, 'hours') + .subtract(8, 'minutes') + .subtract(25, 'seconds'); + + var timeWithoutMsecs = forever.columns.uptime.get({ + running: true, + ctime: launchTime.toDate().getTime() + }).strip.split('.')[0]; + + assert.equal(timeWithoutMsecs, '4000:6:8:25'); + } + } + } +}).export(module);