diff --git a/src/log.js b/src/log.js index 3c58b85b..80fae6b0 100644 --- a/src/log.js +++ b/src/log.js @@ -32,7 +32,7 @@ module.exports = { read(options, callback); }, - getHumanDate() { - return moment().format("YYYY-MM-DD HH:mm:ss"); + getHumanDate(ts) { + return moment(ts).format("YYYY-MM-DD HH:mm:ss"); }, }; diff --git a/src/plugins/messageStorage/text.js b/src/plugins/messageStorage/text.js index 97558e79..a90c5287 100644 --- a/src/plugins/messageStorage/text.js +++ b/src/plugins/messageStorage/text.js @@ -41,7 +41,7 @@ class TextFileMessageStorage { return; } - let line = `[${log.getHumanDate()}] `; + let line = `[${log.getHumanDate(msg.time)}] `; // message types from src/models/msg.js switch (msg.type) { diff --git a/test/src/helperTest.js b/test/src/helperTest.js index 93574639..0f1cb0fd 100644 --- a/test/src/helperTest.js +++ b/test/src/helperTest.js @@ -56,6 +56,6 @@ describe("Helper", function() { }); describe("#getHumanDate()", function() { - expect(log.getHumanDate()).to.equal(moment().format("YYYY-MM-DD HH:mm:ss")); + expect(log.getHumanDate(moment(1455090480000).utc())).to.equal("2016-02-10 07:48:00"); }); });