Skip to content

Commit f4bdff0

Browse files
committed
implement short syntax for week
1 parent 2831ae9 commit f4bdff0

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ planned for 2025-07-01
1515

1616
- [config] Allow to change module order for final renderer (or dynamicaly with CSS): Feature `order` in config. (#3762)
1717
- [clock] Added option 'disableNextEvent' to hide next sun event (#3769)
18+
- [clock] Implement short syntax for clock week (#3775)
1819

1920
### Changed
2021

modules/default/clock/clock.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Module.register("clock", {
1414
clockBold: false,
1515
showDate: true,
1616
showTime: true,
17-
showWeek: false,
17+
showWeek: false, // options: true, false, 'short'
1818
dateFormat: "dddd, LL",
1919
sendNotifications: false,
2020

@@ -224,7 +224,18 @@ Module.register("clock", {
224224
}
225225

226226
if (this.config.showWeek) {
227-
weekWrapper.innerHTML = this.translate("WEEK", { weekNumber: now.week() });
227+
const weekTranslated = this.translate("WEEK", { weekNumber: now.week() });
228+
229+
if (this.config.showWeek === "short") {
230+
const weekTextArr = weekTranslated.split(" ");
231+
const weekTextShort = weekTextArr[0][0];
232+
const weekValue = weekTextArr[weekTextArr.length - 1];
233+
234+
weekWrapper.innerHTML = weekTextShort + weekValue;
235+
} else {
236+
weekWrapper.innerHTML = weekTranslated;
237+
}
238+
228239
digitalWrapper.appendChild(weekWrapper);
229240
}
230241

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
let config = {
2+
address: "0.0.0.0",
3+
ipWhitelist: [],
4+
timeFormat: 12,
5+
6+
modules: [
7+
{
8+
module: "clock",
9+
position: "middle_center",
10+
config: {
11+
showWeek: "short"
12+
}
13+
}
14+
]
15+
};
16+
17+
/*************** DO NOT EDIT THE LINE BELOW ***************/
18+
if (typeof module !== "undefined") {
19+
module.exports = config;
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
let config = {
2+
address: "0.0.0.0",
3+
ipWhitelist: [],
4+
language: "es",
5+
timeFormat: 12,
6+
7+
modules: [
8+
{
9+
module: "clock",
10+
position: "middle_center",
11+
config: {
12+
showWeek: "short"
13+
}
14+
}
15+
]
16+
};
17+
18+
/*************** DO NOT EDIT THE LINE BELOW ***************/
19+
if (typeof module !== "undefined") {
20+
module.exports = config;
21+
}

tests/e2e/modules/clock_es_spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,16 @@ describe("Clock set to spanish language module", () => {
6262
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
6363
});
6464
});
65+
66+
describe("with showWeek short config enabled", () => {
67+
beforeAll(async () => {
68+
await helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek_short.js");
69+
await helpers.getDocument();
70+
});
71+
72+
it("shows week with correct format", async () => {
73+
const weekRegex = /^S[0-9]{1,2}$/;
74+
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
75+
});
76+
});
6577
});

tests/e2e/modules/clock_spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ describe("Clock module", () => {
138138
});
139139
});
140140

141+
describe("with showWeek short config enabled", () => {
142+
beforeAll(async () => {
143+
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek_short.js");
144+
await helpers.getDocument();
145+
});
146+
147+
it("should show the week in the correct format", async () => {
148+
const weekRegex = /^W[0-9]{1,2}$/;
149+
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
150+
});
151+
152+
it("should show the week with the correct number of week of year", async () => {
153+
const currentWeekNumber = moment().week();
154+
const weekToShow = `W${currentWeekNumber}`;
155+
const elem = await helpers.waitForElement(".clock .week");
156+
expect(elem).not.toBeNull();
157+
expect(elem.textContent).toBe(weekToShow);
158+
});
159+
});
160+
141161
describe("with analog clock face enabled", () => {
142162
beforeAll(async () => {
143163
await helpers.startApplication("tests/configs/modules/clock/clock_analog.js");

0 commit comments

Comments
 (0)