diff --git a/modules/default/clock/clock.js b/modules/default/clock/clock.js index 6e3d7090..fbab09a0 100644 --- a/modules/default/clock/clock.js +++ b/modules/default/clock/clock.js @@ -46,62 +46,61 @@ Module.register("clock", { Log.info("Starting module: " + this.name); // Schedule update interval. - var self = this; - self.second = moment().second(); - self.minute = moment().minute(); + this.second = moment().second(); + this.minute = moment().minute(); - //Calculate how many ms should pass until next update depending on if seconds is displayed or not - var delayCalculator = function (reducedSeconds) { - var EXTRA_DELAY = 50; //Deliberate imperceptable delay to prevent off-by-one timekeeping errors + // Calculate how many ms should pass until next update depending on if seconds is displayed or not + const delayCalculator = (reducedSeconds) => { + const EXTRA_DELAY = 50; // Deliberate imperceptible delay to prevent off-by-one timekeeping errors - if (self.config.displaySeconds) { + if (this.config.displaySeconds) { return 1000 - moment().milliseconds() + EXTRA_DELAY; } else { return (60 - reducedSeconds) * 1000 - moment().milliseconds() + EXTRA_DELAY; } }; - //A recursive timeout function instead of interval to avoid drifting - var notificationTimer = function () { - self.updateDom(); + // A recursive timeout function instead of interval to avoid drifting + const notificationTimer = () => { + this.updateDom(); - //If seconds is displayed CLOCK_SECOND-notification should be sent (but not when CLOCK_MINUTE-notification is sent) - if (self.config.displaySeconds) { - self.second = moment().second(); - if (self.second !== 0) { - self.sendNotification("CLOCK_SECOND", self.second); + // If seconds is displayed CLOCK_SECOND-notification should be sent (but not when CLOCK_MINUTE-notification is sent) + if (this.config.displaySeconds) { + this.second = moment().second(); + if (this.second !== 0) { + this.sendNotification("CLOCK_SECOND", this.second); setTimeout(notificationTimer, delayCalculator(0)); return; } } - //If minute changed or seconds isn't displayed send CLOCK_MINUTE-notification - self.minute = moment().minute(); - self.sendNotification("CLOCK_MINUTE", self.minute); + // If minute changed or seconds isn't displayed send CLOCK_MINUTE-notification + this.minute = moment().minute(); + this.sendNotification("CLOCK_MINUTE", this.minute); setTimeout(notificationTimer, delayCalculator(0)); }; - //Set the initial timeout with the amount of seconds elapsed as reducedSeconds so it will trigger when the minute changes - setTimeout(notificationTimer, delayCalculator(self.second)); + // Set the initial timeout with the amount of seconds elapsed as reducedSeconds so it will trigger when the minute changes + setTimeout(notificationTimer, delayCalculator(this.second)); // Set locale. moment.locale(config.language); }, // Override dom generator. getDom: function () { - var wrapper = document.createElement("div"); + const wrapper = document.createElement("div"); /************************************ * Create wrappers for DIGITAL clock */ - var dateWrapper = document.createElement("div"); - var timeWrapper = document.createElement("div"); - var secondsWrapper = document.createElement("sup"); - var periodWrapper = document.createElement("span"); - var sunWrapper = document.createElement("div"); - var moonWrapper = document.createElement("div"); - var weekWrapper = document.createElement("div"); + const dateWrapper = document.createElement("div"); + const timeWrapper = document.createElement("div"); + const secondsWrapper = document.createElement("sup"); + const periodWrapper = document.createElement("span"); + const sunWrapper = document.createElement("div"); + const moonWrapper = document.createElement("div"); + const weekWrapper = document.createElement("div"); // Style Wrappers dateWrapper.className = "date normal medium"; timeWrapper.className = "time bright large light"; @@ -114,14 +113,13 @@ Module.register("clock", { // The moment().format("h") method has a bug on the Raspberry Pi. // So we need to generate the timestring manually. // See issue: https://github.com/MichMich/MagicMirror/issues/181 - var timeString; - var now = moment(); - this.lastDisplayedMinute = now.minute(); + let timeString; + const now = moment(); if (this.config.timezone) { now.tz(this.config.timezone); } - var hourSymbol = "HH"; + let hourSymbol = "HH"; if (this.config.timeFormat !== 24) { hourSymbol = "h"; } @@ -160,7 +158,7 @@ Module.register("clock", { * @returns {string} The formatted time string */ function formatTime(config, time) { - var formatString = hourSymbol + ":mm"; + let formatString = hourSymbol + ":mm"; if (config.showPeriod && config.timeFormat !== 24) { formatString += config.showPeriodUpper ? "A" : "a"; } @@ -170,7 +168,7 @@ Module.register("clock", { if (this.config.showSunTimes) { const sunTimes = SunCalc.getTimes(now, this.config.lat, this.config.lon); const isVisible = now.isBetween(sunTimes.sunrise, sunTimes.sunset); - var nextEvent; + let nextEvent; if (now.isBefore(sunTimes.sunrise)) { nextEvent = sunTimes.sunrise; } else if (now.isBefore(sunTimes.sunset)) { @@ -198,7 +196,7 @@ Module.register("clock", { const moonIllumination = SunCalc.getMoonIllumination(now.toDate()); const moonTimes = SunCalc.getMoonTimes(now, this.config.lat, this.config.lon); const moonRise = moonTimes.rise; - var moonSet; + let moonSet; if (moment(moonTimes.set).isAfter(moonTimes.rise)) { moonSet = moonTimes.set; } else { @@ -224,6 +222,7 @@ Module.register("clock", { /**************************************************************** * Create wrappers for ANALOG clock, only if specified in config */ + const clockCircle = document.createElement("div"); if (this.config.displayType !== "digital") { // If it isn't 'digital', then an 'analog' clock was also requested @@ -232,12 +231,11 @@ Module.register("clock", { if (this.config.timezone) { now.tz(this.config.timezone); } - var second = now.seconds() * 6, + const second = now.seconds() * 6, minute = now.minute() * 6 + second / 60, hour = ((now.hours() % 12) / 12) * 360 + 90 + minute / 12; // Create wrappers - var clockCircle = document.createElement("div"); clockCircle.className = "clockCircle"; clockCircle.style.width = this.config.analogSize; clockCircle.style.height = this.config.analogSize; @@ -252,14 +250,14 @@ Module.register("clock", { } else if (this.config.analogFace !== "none") { clockCircle.style.border = "2px solid white"; } - var clockFace = document.createElement("div"); + const clockFace = document.createElement("div"); clockFace.className = "clockFace"; - var clockHour = document.createElement("div"); + const clockHour = document.createElement("div"); clockHour.id = "clockHour"; clockHour.style.transform = "rotate(" + hour + "deg)"; clockHour.className = "clockHour"; - var clockMinute = document.createElement("div"); + const clockMinute = document.createElement("div"); clockMinute.id = "clockMinute"; clockMinute.style.transform = "rotate(" + minute + "deg)"; clockMinute.className = "clockMinute"; @@ -269,7 +267,7 @@ Module.register("clock", { clockFace.appendChild(clockMinute); if (this.config.displaySeconds) { - var clockSecond = document.createElement("div"); + const clockSecond = document.createElement("div"); clockSecond.id = "clockSecond"; clockSecond.style.transform = "rotate(" + second + "deg)"; clockSecond.className = "clockSecond"; @@ -312,14 +310,14 @@ Module.register("clock", { } } else { // Both clocks have been configured, check position - var placement = this.config.analogPlacement; + const placement = this.config.analogPlacement; - var analogWrapper = document.createElement("div"); + const analogWrapper = document.createElement("div"); analogWrapper.id = "analog"; analogWrapper.style.cssFloat = "none"; analogWrapper.appendChild(clockCircle); - var digitalWrapper = document.createElement("div"); + const digitalWrapper = document.createElement("div"); digitalWrapper.id = "digital"; digitalWrapper.style.cssFloat = "none"; digitalWrapper.appendChild(dateWrapper); @@ -328,8 +326,8 @@ Module.register("clock", { digitalWrapper.appendChild(moonWrapper); digitalWrapper.appendChild(weekWrapper); - var appendClocks = function (condition, pos1, pos2) { - var padding = [0, 0, 0, 0]; + const appendClocks = (condition, pos1, pos2) => { + const padding = [0, 0, 0, 0]; padding[placement === condition ? pos1 : pos2] = "20px"; analogWrapper.style.padding = padding.join(" "); if (placement === condition) { diff --git a/modules/default/clock/clock_styles.css b/modules/default/clock/clock_styles.css index e8436acc..0e74fd7a 100644 --- a/modules/default/clock/clock_styles.css +++ b/modules/default/clock/clock_styles.css @@ -29,7 +29,7 @@ position: absolute; top: 50%; left: 50%; - margin: -2px 0 -2px -25%; /* numbers much match negative length & thickness */ + margin: -2px 0 -2px -25%; /* numbers must match negative length & thickness */ padding: 2px 0 2px 25%; /* indicator length & thickness */ background: var(--color-text-bright); transform-origin: 100% 50%; diff --git a/tests/configs/modules/clock/clock_12hr.js b/tests/configs/modules/clock/clock_12hr.js index c4ab07fc..bf3cedff 100644 --- a/tests/configs/modules/clock/clock_12hr.js +++ b/tests/configs/modules/clock/clock_12hr.js @@ -3,8 +3,7 @@ * By Sergey Morozov * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/clock_24hr.js b/tests/configs/modules/clock/clock_24hr.js index 57c29010..7813a10d 100644 --- a/tests/configs/modules/clock/clock_24hr.js +++ b/tests/configs/modules/clock/clock_24hr.js @@ -3,8 +3,7 @@ * By Sergey Morozov * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/clock_displaySeconds_false.js b/tests/configs/modules/clock/clock_displaySeconds_false.js index 5031ab82..292a8283 100644 --- a/tests/configs/modules/clock/clock_displaySeconds_false.js +++ b/tests/configs/modules/clock/clock_displaySeconds_false.js @@ -3,8 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/clock_showPeriodUpper.js b/tests/configs/modules/clock/clock_showPeriodUpper.js index 6fe1840f..5dd30222 100644 --- a/tests/configs/modules/clock/clock_showPeriodUpper.js +++ b/tests/configs/modules/clock/clock_showPeriodUpper.js @@ -3,8 +3,7 @@ * By Sergey Morozov * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/clock_showWeek.js b/tests/configs/modules/clock/clock_showWeek.js index 02b4acf4..ca9d4384 100644 --- a/tests/configs/modules/clock/clock_showWeek.js +++ b/tests/configs/modules/clock/clock_showWeek.js @@ -3,8 +3,7 @@ * By Johan Hammar * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/es/clock_12hr.js b/tests/configs/modules/clock/es/clock_12hr.js index b753a550..82f5bfdb 100644 --- a/tests/configs/modules/clock/es/clock_12hr.js +++ b/tests/configs/modules/clock/es/clock_12hr.js @@ -3,8 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/es/clock_24hr.js b/tests/configs/modules/clock/es/clock_24hr.js index feb55770..8db5aae2 100644 --- a/tests/configs/modules/clock/es/clock_24hr.js +++ b/tests/configs/modules/clock/es/clock_24hr.js @@ -3,8 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/es/clock_showPeriodUpper.js b/tests/configs/modules/clock/es/clock_showPeriodUpper.js index 208d9394..1d24a58a 100644 --- a/tests/configs/modules/clock/es/clock_showPeriodUpper.js +++ b/tests/configs/modules/clock/es/clock_showPeriodUpper.js @@ -3,8 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/configs/modules/clock/es/clock_showWeek.js b/tests/configs/modules/clock/es/clock_showWeek.js index 2a6661e9..1e6843b1 100644 --- a/tests/configs/modules/clock/es/clock_showWeek.js +++ b/tests/configs/modules/clock/es/clock_showWeek.js @@ -6,8 +6,7 @@ * * MIT Licensed. */ - -var config = { +let config = { port: 8080, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], diff --git a/tests/e2e/modules/clock_es_spec.js b/tests/e2e/modules/clock_es_spec.js index 46d74e8d..5ef491a3 100644 --- a/tests/e2e/modules/clock_es_spec.js +++ b/tests/e2e/modules/clock_es_spec.js @@ -8,7 +8,7 @@ const afterEach = global.afterEach; describe("Clock set to spanish language module", function () { helpers.setupTimeout(this); - var app = null; + let app = null; beforeEach(function () { return helpers diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index 0f9e3878..27536dc2 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -10,7 +10,7 @@ const afterEach = global.afterEach; describe("Clock module", function () { helpers.setupTimeout(this); - var app = null; + let app = null; beforeEach(function () { return helpers