Repository: thelounge/thelounge
Pull request #2506 (2018-06-03 17:37:36)

Remove ability to change date format and timezone
Timezones were discussed in #1486. Removing it from config means the timezone of the server will be used.

Being able to change date format in logs makes little sence when you can't format anything else in the log.

astorije: Add a test before merging? 🙏

Patch:
diff --git a/defaults/config.js b/defaults/config.js
index 0a06b7d4..c8d86bff 100644
--- a/defaults/config.js
+++ b/defaults/config.js
@@ -161,33 +161,6 @@ module.exports = {
 	//
 	messageStorage: ["sqlite", "text"],
 
-	//
-	// Log settings
-	//
-	// Logging has to be enabled per user. If enabled, logs will be stored in
-	// the 'logs/<user>/<network>/' folder.
-	//
-	// @type     object
-	// @default  {}
-	//
-	logs: {
-		//
-		// Timestamp format
-		//
-		// @type     string
-		// @default  "YYYY-MM-DD HH:mm:ss"
-		//
-		format: "YYYY-MM-DD HH:mm:ss",
-
-		//
-		// Timezone
-		//
-		// @type     string
-		// @default  "UTC+00:00"
-		//
-		timezone: "UTC+00:00",
-	},
-
 	//
 	// Maximum number of history lines per channel
 	//
diff --git a/src/helper.js b/src/helper.js
index a06267a4..388763ea 100644
--- a/src/helper.js
+++ b/src/helper.js
@@ -8,6 +8,7 @@ const fs = require("fs");
 const net = require("net");
 const bcrypt = require("bcryptjs");
 const colors = require("chalk");
+const moment = require("moment");
 
 let homePath;
 let configPath;
@@ -30,6 +31,7 @@ const Helper = {
 	setHome,
 	getVersion,
 	getGitCommit,
+	getHumanDate,
 	ip2hex,
 	mergeConfig,
 	getDefaultNick,
@@ -205,6 +207,10 @@ function passwordCompare(password, expected) {
 	return bcrypt.compare(password, expected);
 }
 
+function getHumanDate() {
+	return moment().format("YYYY-MM-DD HH:mm:ss");
+}
+
 function getDefaultNick() {
 	if (!this.config.defaults.nick) {
 		return "thelounge";
diff --git a/src/log.js b/src/log.js
index b627c874..9011623d 100644
--- a/src/log.js
+++ b/src/log.js
@@ -1,16 +1,11 @@
 "use strict";
 
 const colors = require("chalk");
-const moment = require("moment");
 const read = require("read");
 const Helper = require("./helper");
 
 function timestamp() {
-	const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
-	const tz = Helper.config.logs.timezone || "UTC+00:00";
-	const time = moment().utcOffset(tz).format(format);
-
-	return colors.dim(time);
+	return colors.dim(Helper.getHumanDate());
 }
 
 module.exports = {
diff --git a/src/plugins/messageStorage/text.js b/src/plugins/messageStorage/text.js
index 0b7d436b..d979e5cb 100644
--- a/src/plugins/messageStorage/text.js
+++ b/src/plugins/messageStorage/text.js
@@ -3,7 +3,6 @@
 const fs = require("fs");
 const fsextra = require("fs-extra");
 const path = require("path");
-const moment = require("moment");
 const filenamify = require("filenamify");
 const Helper = require("../../helper");
 
@@ -40,11 +39,7 @@ class TextFileMessageStorage {
 			return;
 		}
 
-		const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
-		const tz = Helper.config.logs.timezone || "UTC+00:00";
-
-		const time = moment(msg.time).utcOffset(tz).format(format);
-		let line = `[${time}] `;
+		let line = `[${Helper.getHumanDate()}] `;
 
 		if (msg.type === "message") {
 			// Format:


Test patch:
diff --git a/test/src/helperTest.js b/test/src/helperTest.js
index e7cd33c1..54ae3264 100644
--- a/test/src/helperTest.js
+++ b/test/src/helperTest.js
@@ -2,6 +2,7 @@
 
 const expect = require("chai").expect;
 const os = require("os");
+const moment = require("moment");
 const Helper = require("../../src/helper");
 
 describe("Helper", function() {
@@ -52,4 +53,8 @@ describe("Helper", function() {
 			expect(version).to.match(/v[0-9]+\.[0-9]+\.[0-9]+/);
 		});
 	});
+
+	describe("#getHumanDate()", function() {
+		expect(Helper.getHumanDate()).to.equal(moment().format("YYYY-MM-DD HH:mm:ss"));
+	});
 });