Merge pull request #2669 from MaxLeiter/humandate-refactor

refactor getHumanDate() to accept a timestamp; avoids possible test failure; more accurate log times
This commit is contained in:
Pavel Djundik 2018-07-22 11:39:11 +03:00 committed by GitHub
commit e8c02d5ad2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 4 deletions

View File

@ -32,7 +32,7 @@ module.exports = {
read(options, callback); read(options, callback);
}, },
getHumanDate() { getHumanDate(ts) {
return moment().format("YYYY-MM-DD HH:mm:ss"); return moment(ts).format("YYYY-MM-DD HH:mm:ss");
}, },
}; };

View File

@ -41,7 +41,7 @@ class TextFileMessageStorage {
return; return;
} }
let line = `[${log.getHumanDate()}] `; let line = `[${log.getHumanDate(msg.time)}] `;
// message types from src/models/msg.js // message types from src/models/msg.js
switch (msg.type) { switch (msg.type) {

View File

@ -56,6 +56,6 @@ describe("Helper", function() {
}); });
describe("#getHumanDate()", 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");
}); });
}); });