Skip to content

Commit db3be3d

Browse files
authored
Merge pull request MagicMirrorOrg#801 from johanhammar/clock-week-section
Added a week section to the clock module
2 parents 60c7522 + 77c72d2 commit db3be3d

File tree

8 files changed

+78
-1
lines changed

8 files changed

+78
-1
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5757
- Added multiple calendar icon support.
5858
- Added meta tags to support fullscreen mode on iOS (for server mode)
5959
- Added `ignoreOldItems` and `ignoreOlderThan` options to the News Feed module
60+
- Added a configurable Week section to the clock module.
6061

6162
### Fixed
6263
- Update .gitignore to not ignore default modules folder.

Diff for: modules/default/clock/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The following properties can be configured:
3030
| `showPeriodUpper` | Show the period (AM/PM) with 12 hour format as uppercase. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
3131
| `clockBold` | Remove the colon and bold the minutes to make a more modern look. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
3232
| `showDate` | Turn off or on the Date section. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
33+
| `showWeek` | Turn off or on the Week section. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
3334
| `dateFormat` | Configure the date format as you like. <br><br> **Possible values:** [Docs](http://momentjs.com/docs/#/displaying/format/) <br> **Default value:** `"dddd, LL"`
3435
| `displayType` | Display a digital clock, analog clock, or both together. <br><br> **Possible values:** `digital`, `analog`, or `both` <br> **Default value:** `digital`
3536
| `analogSize` | **Specific to the analog clock.** Defines how large the analog display is. <br><br> **Possible values:** A positive number of pixels` <br> **Default value:** `200px`

Diff for: modules/default/clock/clock.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Module.register("clock",{
1616
showPeriodUpper: false,
1717
clockBold: false,
1818
showDate: true,
19+
showWeek: false,
1920
dateFormat: "dddd, LL",
2021

2122
/* specific to the analog clock */
@@ -61,10 +62,12 @@ Module.register("clock",{
6162
var timeWrapper = document.createElement("div");
6263
var secondsWrapper = document.createElement("sup");
6364
var periodWrapper = document.createElement("span");
65+
var weekWrapper = document.createElement("div")
6466
// Style Wrappers
6567
dateWrapper.className = "date normal medium";
6668
timeWrapper.className = "time bright large light";
6769
secondsWrapper.className = "dimmed";
70+
weekWrapper.className = "week dimmed medium"
6871

6972
// Set content of wrappers.
7073
// The moment().format("h") method has a bug on the Raspberry Pi.
@@ -90,6 +93,9 @@ Module.register("clock",{
9093
if(this.config.showDate){
9194
dateWrapper.innerHTML = now.format(this.config.dateFormat);
9295
}
96+
if (this.config.showWeek) {
97+
weekWrapper.innerHTML = this.translate("WEEK") + " " + now.week();
98+
}
9399
timeWrapper.innerHTML = timeString;
94100
secondsWrapper.innerHTML = now.format("ss");
95101
if (this.config.showPeriodUpper) {
@@ -172,16 +178,25 @@ Module.register("clock",{
172178
// Display only a digital clock
173179
wrapper.appendChild(dateWrapper);
174180
wrapper.appendChild(timeWrapper);
181+
wrapper.appendChild(weekWrapper);
175182
} else if (this.config.displayType === "analog") {
176183
// Display only an analog clock
177184
dateWrapper.style.textAlign = "center";
178-
dateWrapper.style.paddingBottom = "15px";
185+
186+
if (this.config.showWeek) {
187+
weekWrapper.style.paddingBottom = "15px";
188+
} else {
189+
dateWrapper.style.paddingBottom = "15px";
190+
}
191+
179192
if (this.config.analogShowDate === "top") {
180193
wrapper.appendChild(dateWrapper);
194+
wrapper.appendChild(weekWrapper);
181195
wrapper.appendChild(clockCircle);
182196
} else if (this.config.analogShowDate === "bottom") {
183197
wrapper.appendChild(clockCircle);
184198
wrapper.appendChild(dateWrapper);
199+
wrapper.appendChild(weekWrapper);
185200
} else {
186201
wrapper.appendChild(clockCircle);
187202
}
@@ -198,6 +213,7 @@ Module.register("clock",{
198213
digitalWrapper.style.cssFloat = "none";
199214
digitalWrapper.appendChild(dateWrapper);
200215
digitalWrapper.appendChild(timeWrapper);
216+
digitalWrapper.appendChild(weekWrapper);
201217

202218
var appendClocks = function(condition, pos1, pos2) {
203219
var padding = [0,0,0,0];

Diff for: tests/configs/modules/clock/clock_showWeek.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Magic Mirror Test config for default clock module
2+
*
3+
* By Johan Hammar
4+
* MIT Licensed.
5+
*/
6+
7+
var config = {
8+
port: 8080,
9+
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
10+
11+
language: "en",
12+
timeFormat: 12,
13+
units: "metric",
14+
electronOptions: {
15+
webPreferences: {
16+
nodeIntegration: true,
17+
},
18+
},
19+
20+
modules: [
21+
{
22+
module: "clock",
23+
position: "middle_center",
24+
config: {
25+
showWeek: true
26+
}
27+
}
28+
]
29+
};
30+
31+
/*************** DO NOT EDIT THE LINE BELOW ***************/
32+
if (typeof module !== "undefined") {module.exports = config;}

Diff for: tests/e2e/modules/clock_spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,25 @@ describe("Clock module", function () {
100100
});
101101
});
102102

103+
describe("with showWeek config enabled", function() {
104+
before(function() {
105+
// Set config sample for use in test
106+
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showWeek.js";
107+
});
108+
109+
beforeEach(function (done) {
110+
app.start().then(function() { done(); } );
111+
});
112+
113+
afterEach(function (done) {
114+
app.stop().then(function() { done(); });
115+
});
116+
117+
it("shows week with correct format", function() {
118+
const weekRegex = /^Week [0-9]{1,2}$/;
119+
return app.client.waitUntilWindowLoaded()
120+
.getText(".clock .week").should.eventually.match(weekRegex);
121+
});
122+
});
123+
103124
});

Diff for: translations/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"RUNNING": "Ends in",
88
"EMPTY": "No upcoming events.",
99

10+
"WEEK": "Week",
11+
1012
"N": "N",
1113
"NNE": "NNE",
1214
"NE": "NE",

Diff for: translations/es.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"RUNNING": "Termina en",
88
"EMPTY": "No hay eventos programados.",
99

10+
"WEEK": "Semana",
11+
1012
"N": "N",
1113
"NNE": "NNE",
1214
"NE": "NE",

Diff for: translations/sv.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"RUNNING": "Slutar",
88
"EMPTY": "Inga kommande händelser.",
99

10+
"WEEK": "Vecka",
11+
1012
"N": "N",
1113
"NNE": "NNO",
1214
"NE": "NO",

0 commit comments

Comments
 (0)