diff --git a/CHANGELOG.md b/CHANGELOG.md index f82de5f0..f0c55e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ planned for 2025-07-01 - [config] Allow to change module order for final renderer (or dynamically with CSS): Feature `order` in config (#3762) - [clock] Added option 'disableNextEvent' to hide next sun event (#3769) +- [clock] Implement short syntax for clock week (#3775) ### Changed diff --git a/modules/default/clock/clock.js b/modules/default/clock/clock.js index f5c7411d..d013cd25 100644 --- a/modules/default/clock/clock.js +++ b/modules/default/clock/clock.js @@ -14,7 +14,7 @@ Module.register("clock", { clockBold: false, showDate: true, showTime: true, - showWeek: false, + showWeek: false, // options: true, false, 'short' dateFormat: "dddd, LL", sendNotifications: false, @@ -224,7 +224,12 @@ Module.register("clock", { } if (this.config.showWeek) { - weekWrapper.innerHTML = this.translate("WEEK", { weekNumber: now.week() }); + if (this.config.showWeek === "short") { + weekWrapper.innerHTML = this.translate("WEEK_SHORT", { weekNumber: now.week() }); + } else { + weekWrapper.innerHTML = this.translate("WEEK", { weekNumber: now.week() }); + } + digitalWrapper.appendChild(weekWrapper); } diff --git a/tests/configs/modules/clock/clock_showWeek_short.js b/tests/configs/modules/clock/clock_showWeek_short.js new file mode 100644 index 00000000..6728d01f --- /dev/null +++ b/tests/configs/modules/clock/clock_showWeek_short.js @@ -0,0 +1,20 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + timeFormat: 12, + + modules: [ + { + module: "clock", + position: "middle_center", + config: { + showWeek: "short" + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/configs/modules/clock/de/clock_showWeek.js b/tests/configs/modules/clock/de/clock_showWeek.js new file mode 100644 index 00000000..3adf2655 --- /dev/null +++ b/tests/configs/modules/clock/de/clock_showWeek.js @@ -0,0 +1,21 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + language: "de", + timeFormat: 12, + + modules: [ + { + module: "clock", + position: "middle_center", + config: { + showWeek: true + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/configs/modules/clock/de/clock_showWeek_short.js b/tests/configs/modules/clock/de/clock_showWeek_short.js new file mode 100644 index 00000000..bdbdca72 --- /dev/null +++ b/tests/configs/modules/clock/de/clock_showWeek_short.js @@ -0,0 +1,21 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + language: "de", + timeFormat: 12, + + modules: [ + { + module: "clock", + position: "middle_center", + config: { + showWeek: "short" + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/configs/modules/clock/es/clock_showWeek_short.js b/tests/configs/modules/clock/es/clock_showWeek_short.js new file mode 100644 index 00000000..2581a2d4 --- /dev/null +++ b/tests/configs/modules/clock/es/clock_showWeek_short.js @@ -0,0 +1,21 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + language: "es", + timeFormat: 12, + + modules: [ + { + module: "clock", + position: "middle_center", + config: { + showWeek: "short" + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/e2e/modules/clock_de_spec.js b/tests/e2e/modules/clock_de_spec.js new file mode 100644 index 00000000..e46b37ab --- /dev/null +++ b/tests/e2e/modules/clock_de_spec.js @@ -0,0 +1,31 @@ +const helpers = require("../helpers/global-setup"); + +describe("Clock set to german language module", () => { + afterAll(async () => { + await helpers.stopApplication(); + }); + + describe("with showWeek config enabled", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/clock/de/clock_showWeek.js"); + await helpers.getDocument(); + }); + + it("shows week with correct format", async () => { + const weekRegex = /^[0-9]{1,2}. Kalenderwoche$/; + await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true); + }); + }); + + describe("with showWeek short config enabled", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/clock/de/clock_showWeek_short.js"); + await helpers.getDocument(); + }); + + it("shows week with correct format", async () => { + const weekRegex = /^[0-9]{1,2}KW$/; + await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true); + }); + }); +}); diff --git a/tests/e2e/modules/clock_es_spec.js b/tests/e2e/modules/clock_es_spec.js index 134c795b..38b997a5 100644 --- a/tests/e2e/modules/clock_es_spec.js +++ b/tests/e2e/modules/clock_es_spec.js @@ -62,4 +62,16 @@ describe("Clock set to spanish language module", () => { await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true); }); }); + + describe("with showWeek short config enabled", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek_short.js"); + await helpers.getDocument(); + }); + + it("shows week with correct format", async () => { + const weekRegex = /^S[0-9]{1,2}$/; + await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true); + }); + }); }); diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index 9d9680e1..71470fec 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -138,6 +138,26 @@ describe("Clock module", () => { }); }); + describe("with showWeek short config enabled", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/clock/clock_showWeek_short.js"); + await helpers.getDocument(); + }); + + it("should show the week in the correct format", async () => { + const weekRegex = /^W[0-9]{1,2}$/; + await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true); + }); + + it("should show the week with the correct number of week of year", async () => { + const currentWeekNumber = moment().week(); + const weekToShow = `W${currentWeekNumber}`; + const elem = await helpers.waitForElement(".clock .week"); + expect(elem).not.toBeNull(); + expect(elem.textContent).toBe(weekToShow); + }); + }); + describe("with analog clock face enabled", () => { beforeAll(async () => { await helpers.startApplication("tests/configs/modules/clock/clock_analog.js"); diff --git a/translations/de.json b/translations/de.json index d0f5eed7..86597b16 100644 --- a/translations/de.json +++ b/translations/de.json @@ -9,6 +9,7 @@ "RUNNING": "noch", "EMPTY": "Keine Termine.", "WEEK": "{weekNumber}. Kalenderwoche", + "WEEK_SHORT": "{weekNumber}KW", "N": "N", "NNE": "NNO", diff --git a/translations/en.json b/translations/en.json index e10801e5..c4a2f196 100644 --- a/translations/en.json +++ b/translations/en.json @@ -7,6 +7,7 @@ "RUNNING": "Ends in", "EMPTY": "No upcoming events.", "WEEK": "Week {weekNumber}", + "WEEK_SHORT": "W{weekNumber}", "N": "N", "NNE": "NNE", diff --git a/translations/es.json b/translations/es.json index 454dcf40..67be6ab9 100644 --- a/translations/es.json +++ b/translations/es.json @@ -9,6 +9,7 @@ "RUNNING": "Termina en", "EMPTY": "No hay eventos programados.", "WEEK": "Semana {weekNumber}", + "WEEK_SHORT": "S{weekNumber}", "N": "N", "NNE": "NNE", diff --git a/translations/fr.json b/translations/fr.json index b7f9d027..226f454f 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -9,6 +9,7 @@ "RUNNING": "Se termine dans", "EMPTY": "Aucun RDV à venir.", "WEEK": "Semaine {weekNumber}", + "WEEK_SHORT": "S{weekNumber}", "N": "N", "NNE": "NNE",