-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMMM-DigClock.js
108 lines (86 loc) · 2.62 KB
/
MMM-DigClock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* MagicMIrror Module - MMM-DigClock
*
* This is a module for the [MagicMirror² By Michael Teeuw http://michaelteeuw.nl]
* (https://github.com/MichMich/MagicMirror/).
*
* The digital only part of the default MM2 clock
* written by Michael Teeuw http://michaelteeuw.nl]
*
* I wanted a way to use both the digital and analog clocks
* on different pages of my MM2. And I wanted to to have it look
* like the "old school" digital clocks!
*
* NOT tested with Raspberry Pi or Linux-Based systems.
* It DOES work with Windows 10!!!
*
* version: 1.0.0
*
* Modified module by Jim Hallock (justjim1220@gmail.com)
*
* Licensed with a crapload of good ole' Southern Sweet Tea
* and a lot of Cheyenne Extreme Menthol cigars!!!
*/
Module.register("MMM-DigClock", {
// Module config defaults.
defaults: {
timeFormat: config.timeFormat,
showDate: true,
showWeek: false,
dateFormat: "ddd, ll",
timezone: "America/Chicago"
},
requiresVersion: "2.1.0",
// Define required scripts.
getScripts: function() {
return ["moment.js", "moment-timezone.js"];
},
// Define styles.
getStyles: function() {
return ["MMM-DigClock.css", "DS-Digital.css"];
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
// Schedule update interval.
var self = this;
setInterval(function() {
self.updateDom();
}, 1000);
"use strict",
// Set locale.
moment.locale(config.language);
},
getDom: function() {
var wrapper = document.createElement("div");
var dateWrapper = document.createElement("div");
var timeWrapper = document.createElement("div");
var weekWrapper = document.createElement("div");
dateWrapper.className = "date";
timeWrapper.className = "time";
weekWrapper.className = "week";
var timeString;
var now = moment();
if (this.config.timezone) {
now.tz(this.config.timezone);
}
var hourSymbol = "HH";
if (this.config.timeFormat !== 24) {
hourSymbol = "h";
}
timeString = now.format(hourSymbol + ":mm" + ":ss");
if(this.config.showDate){
dateWrapper.innerHTML = now.format(this.config.dateFormat);
}
if (this.config.showWeek) {
weekWrapper.innerHTML = this.translate("WEEK", { weekNumber: now.week() });
}
timeWrapper.innerHTML = timeString;
digitalWrapper = document.createElement("div");
digitalWrapper.className = "digital";
digitalWrapper.appendChild(dateWrapper);
digitalWrapper.appendChild(timeWrapper);
digitalWrapper.appendChild(weekWrapper);
wrapper.appendChild(digitalWrapper);
return wrapper;
}
});