2016-03-24 17:19:32 +01:00
|
|
|
/* global Log, Module, moment, config */
|
|
|
|
|
|
|
|
/* Magic Mirror
|
|
|
|
* Module: Clock
|
|
|
|
*
|
|
|
|
* By Michael Teeuw http://michaelteeuw.nl
|
|
|
|
* MIT Licensed.
|
|
|
|
*/
|
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
Module.register("clock",{
|
2016-03-24 17:19:32 +01:00
|
|
|
|
|
|
|
// Module config defaults.
|
|
|
|
defaults: {
|
2016-03-29 13:28:15 +02:00
|
|
|
timeFormat: config.timeFormat,
|
2016-03-24 17:19:32 +01:00
|
|
|
displaySeconds: true,
|
2016-04-18 19:52:40 -04:00
|
|
|
showPeriod: true,
|
|
|
|
showPeriodUpper: false,
|
2016-03-24 17:19:32 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Define required scripts.
|
|
|
|
getScripts: function() {
|
2016-04-05 14:35:11 -04:00
|
|
|
return ["moment.js"];
|
2016-03-24 17:19:32 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Define start sequence.
|
|
|
|
start: function() {
|
2016-04-05 14:35:11 -04:00
|
|
|
Log.info("Starting module: " + this.name);
|
2016-03-24 17:19:32 +01:00
|
|
|
|
|
|
|
// Schedule update interval.
|
|
|
|
var self = this;
|
|
|
|
setInterval(function() {
|
|
|
|
self.updateDom();
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
// Set locale.
|
|
|
|
moment.locale(config.language);
|
|
|
|
},
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-03-24 17:19:32 +01:00
|
|
|
// Override dom generator.
|
|
|
|
getDom: function() {
|
|
|
|
// Create wrappers.
|
|
|
|
var wrapper = document.createElement("div");
|
|
|
|
var dateWrapper = document.createElement("div");
|
|
|
|
var timeWrapper = document.createElement("div");
|
|
|
|
var secondsWrapper = document.createElement("sup");
|
2016-04-20 11:42:01 +02:00
|
|
|
var periodWrapper = document.createElement("span");
|
2016-03-24 17:19:32 +01:00
|
|
|
|
|
|
|
// Style Wrappers
|
|
|
|
dateWrapper.className = "date normal medium";
|
|
|
|
timeWrapper.className = "time bright large light";
|
|
|
|
secondsWrapper.className = "dimmed";
|
|
|
|
|
|
|
|
// Set content of wrappers.
|
2016-04-18 19:12:24 +02:00
|
|
|
// 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 = moment().format('HH:mm');
|
|
|
|
if (this.config.timeFormat !== 24) {
|
|
|
|
var now = new Date();
|
|
|
|
var hours = now.getHours() % 12 || 12;
|
2016-04-20 11:42:01 +02:00
|
|
|
timeString = hours + moment().format(':mm');
|
2016-04-18 19:12:24 +02:00
|
|
|
}
|
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
dateWrapper.innerHTML = moment().format("dddd, LL");
|
2016-04-18 19:12:24 +02:00
|
|
|
timeWrapper.innerHTML = timeString;
|
2016-04-05 14:35:11 -04:00
|
|
|
secondsWrapper.innerHTML = moment().format("ss");
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-20 11:42:01 +02:00
|
|
|
|
|
|
|
if (this.config.showPeriodUpper) {
|
|
|
|
periodWrapper.innerHTML = moment().format('A');
|
|
|
|
} else {
|
|
|
|
periodWrapper.innerHTML = moment().format('a');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-24 17:19:32 +01:00
|
|
|
// Combine wrappers.
|
|
|
|
wrapper.appendChild(dateWrapper);
|
|
|
|
wrapper.appendChild(timeWrapper);
|
|
|
|
if (this.config.displaySeconds) {
|
|
|
|
timeWrapper.appendChild(secondsWrapper);
|
|
|
|
}
|
2016-04-20 11:42:01 +02:00
|
|
|
if (this.config.showPeriod) {
|
|
|
|
timeWrapper.appendChild(periodWrapper);
|
|
|
|
}
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-03-24 17:19:32 +01:00
|
|
|
// Return the wrapper to the dom.
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
});
|