From c2eccc498ad7cc5514f456066806648318b4904e Mon Sep 17 00:00:00 2001 From: Arjan van Bentem Date: Fri, 1 Jun 2018 15:16:56 +0200 Subject: [PATCH] feat: using local timezone for notifications --- CHANGELOG.md | 2 ++ package.json | 1 + reporter.js | 4 +++- watchdog.js | 6 ++++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1cee9c..0bcb4f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Support to count specific messages during a configurable interval, to report basic statistics (and to implicitly ensure the monitor itself is still operational). +- Displaying times in Slack and Telegram notifications in the local timezone rather than UTC. + - The log file's directory name can either be specified in `filename`, or in `dirname` (default: current folder). ### Breaking changes diff --git a/package.json b/package.json index 72e0db4..83faf7b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "url": "git://github.com/avbentem/raspi-uart-monitor.git" }, "dependencies": { + "moment": "2.22.2", "raspi": "5.0.2", "raspi-serial": "5.0.0", "slack-winston": "0.0.9", diff --git a/reporter.js b/reporter.js index e6c62e8..933e15b 100644 --- a/reporter.js +++ b/reporter.js @@ -5,6 +5,8 @@ 'use strict'; +const moment = require('moment'); + class Reporter { constructor(reports, schedule, logger) { @@ -77,7 +79,7 @@ class Reporter { * @private */ _report() { - const msg = this.schedule.name + ' since ' + (new Date(this.lastRun)).toISOString() + const msg = this.schedule.name + ' since ' + moment(this.lastRun).format('YYYY-MM-DD HH:mm') + ':\n' + this.reports.map(report => '\u2022 ' + report.name + ": " + (this.counts[report.name] || 0)).join('\n'); diff --git a/watchdog.js b/watchdog.js index 0c17703..97d87f8 100644 --- a/watchdog.js +++ b/watchdog.js @@ -6,6 +6,8 @@ 'use strict'; +const moment = require('moment'); + class Watchdog { constructor(config, logger) { @@ -60,7 +62,7 @@ class Watchdog { // Don't flood the logs with the same error return; } - this.logger.error('No ' + this.config.name + ' since ' + (new Date(this.lastHeartbeat)).toISOString()); + this.logger.error('No ' + this.config.name + ' since ' + moment(this.lastHeartbeat).format('YYYY-MM-DD HH:mm')); if (!this.firstWatchdogError) { this.firstWatchdogError = this.lastHeartbeat; } @@ -70,7 +72,7 @@ class Watchdog { // All fine (again) if (this.firstWatchdogError) { - this.logger.warn('First ' + this.config.name + ' since ' + (new Date(this.firstWatchdogError)).toISOString()); + this.logger.warn('First ' + this.config.name + ' since ' + moment(this.firstWatchdogError).format('YYYY-MM-DD HH:mm')); this.firstWatchdogError = this.lastWatchdogError = null; } }