mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-29 04:29:41 +00:00
Merge pull request #1885 from dtreskunov/dtreskunov/sun-and-moon
add sun/moon rise/set times
This commit is contained in:
commit
7b3a59455d
@ -13,8 +13,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- cleanup installers folder, remove externalized scripts
|
- cleanup installers folder, remove externalized scripts
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Finish translation for "PRECIP", "UPDATE_INFO_MULTIPLE" and "UPDATE_INFO_SINGLE".
|
- Finnish translation for "PRECIP", "UPDATE_INFO_MULTIPLE" and "UPDATE_INFO_SINGLE".
|
||||||
- Added the ability to hide the temp label and weather icon in the `currentweather` module to allow showing only information such as wind and sunset/rise.
|
- Added the ability to hide the temp label and weather icon in the `currentweather` module to allow showing only information such as wind and sunset/rise.
|
||||||
|
- Sun and Moon data to the `clock` module.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Force declaration of public ip adress in config file (ISSUE #1852)
|
- Force declaration of public ip adress in config file (ISSUE #1852)
|
||||||
|
@ -26,10 +26,15 @@ Module.register("clock",{
|
|||||||
analogShowDate: "top", // options: false, 'top', or 'bottom'
|
analogShowDate: "top", // options: false, 'top', or 'bottom'
|
||||||
secondsColor: "#888888",
|
secondsColor: "#888888",
|
||||||
timezone: null,
|
timezone: null,
|
||||||
|
|
||||||
|
showSunTimes: false,
|
||||||
|
showMoonTimes: false,
|
||||||
|
lat: 47.630539,
|
||||||
|
lon: -122.344147,
|
||||||
},
|
},
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ["moment.js", "moment-timezone.js"];
|
return ["moment.js", "moment-timezone.js", "suncalc.js"];
|
||||||
},
|
},
|
||||||
// Define styles.
|
// Define styles.
|
||||||
getStyles: function() {
|
getStyles: function() {
|
||||||
@ -93,11 +98,15 @@ Module.register("clock",{
|
|||||||
var timeWrapper = document.createElement("div");
|
var timeWrapper = document.createElement("div");
|
||||||
var secondsWrapper = document.createElement("sup");
|
var secondsWrapper = document.createElement("sup");
|
||||||
var periodWrapper = document.createElement("span");
|
var periodWrapper = document.createElement("span");
|
||||||
|
var sunWrapper = document.createElement("div");
|
||||||
|
var moonWrapper = document.createElement("div");
|
||||||
var weekWrapper = document.createElement("div");
|
var weekWrapper = document.createElement("div");
|
||||||
// Style Wrappers
|
// Style Wrappers
|
||||||
dateWrapper.className = "date normal medium";
|
dateWrapper.className = "date normal medium";
|
||||||
timeWrapper.className = "time bright large light";
|
timeWrapper.className = "time bright large light";
|
||||||
secondsWrapper.className = "dimmed";
|
secondsWrapper.className = "dimmed";
|
||||||
|
sunWrapper.className = "sun dimmed small";
|
||||||
|
moonWrapper.className = "moon dimmed small";
|
||||||
weekWrapper.className = "week dimmed medium";
|
weekWrapper.className = "week dimmed medium";
|
||||||
|
|
||||||
// Set content of wrappers.
|
// Set content of wrappers.
|
||||||
@ -142,6 +151,41 @@ Module.register("clock",{
|
|||||||
timeWrapper.appendChild(periodWrapper);
|
timeWrapper.appendChild(periodWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTime(config, time) {
|
||||||
|
var formatString = hourSymbol + ':mm';
|
||||||
|
if (config.showPeriod && config.timeFormat !== 24) {
|
||||||
|
formatString += config.showPeriodUpper ? 'A' : 'a';
|
||||||
|
}
|
||||||
|
return moment(time).format(formatString);
|
||||||
|
}
|
||||||
|
if (this.config.showSunTimes) {
|
||||||
|
const sunTimes = SunCalc.getTimes(now, this.config.lat, this.config.lon);
|
||||||
|
const isVisible = now.isBetween(sunTimes.sunrise, sunTimes.sunset);
|
||||||
|
var nextEvent;
|
||||||
|
if (now.isBefore(sunTimes.sunrise)) {
|
||||||
|
nextEvent = sunTimes.sunrise;
|
||||||
|
} else if (now.isBefore(sunTimes.sunset)) {
|
||||||
|
nextEvent = sunTimes.sunset;
|
||||||
|
} else {
|
||||||
|
const tomorrowSunTimes = SunCalc.getTimes(now.add(1, 'day'), this.config.lat, this.config.lon);
|
||||||
|
nextEvent = tomorrowSunTimes.sunrise;
|
||||||
|
}
|
||||||
|
const untilNextEvent = moment.duration(moment(nextEvent).diff(now));
|
||||||
|
const untilNextEventString = untilNextEvent.hours() + 'h ' + untilNextEvent.minutes() + 'm';
|
||||||
|
sunWrapper.innerHTML = '<span class="' + (isVisible ? 'bright' : '') + '"><i class="fa fa-sun-o" aria-hidden="true"></i> ' + untilNextEventString + '</span>' +
|
||||||
|
'<span><i class="fa fa-arrow-up" aria-hidden="true"></i>' + formatTime(this.config, sunTimes.sunrise) + '</span>' +
|
||||||
|
'<span><i class="fa fa-arrow-down" aria-hidden="true"></i>' + formatTime(this.config, sunTimes.sunset) + '</span>';
|
||||||
|
}
|
||||||
|
if (this.config.showMoonTimes) {
|
||||||
|
const moonIllumination = SunCalc.getMoonIllumination(now.toDate());
|
||||||
|
const moonTimes = SunCalc.getMoonTimes(now, this.config.lat, this.config.lon);
|
||||||
|
const isVisible = now.isBetween(moonTimes.rise, moonTimes.set);
|
||||||
|
const illuminatedFractionString = moonIllumination.fraction.toLocaleString(undefined, {style: 'percent'});
|
||||||
|
moonWrapper.innerHTML = '<span class="' + (isVisible ? 'bright' : '') + '"><i class="fa fa-moon-o" aria-hidden="true"></i> ' + illuminatedFractionString + '</span>' +
|
||||||
|
'<span><i class="fa fa-arrow-up" aria-hidden="true"></i> ' + formatTime(this.config, moonTimes.rise) + '</span>'+
|
||||||
|
'<span><i class="fa fa-arrow-down" aria-hidden="true"></i> ' + formatTime(this.config, moonTimes.set) + '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Create wrappers for ANALOG clock, only if specified in config
|
* Create wrappers for ANALOG clock, only if specified in config
|
||||||
*/
|
*/
|
||||||
@ -210,6 +254,8 @@ Module.register("clock",{
|
|||||||
// Display only a digital clock
|
// Display only a digital clock
|
||||||
wrapper.appendChild(dateWrapper);
|
wrapper.appendChild(dateWrapper);
|
||||||
wrapper.appendChild(timeWrapper);
|
wrapper.appendChild(timeWrapper);
|
||||||
|
wrapper.appendChild(sunWrapper);
|
||||||
|
wrapper.appendChild(moonWrapper);
|
||||||
wrapper.appendChild(weekWrapper);
|
wrapper.appendChild(weekWrapper);
|
||||||
} else if (this.config.displayType === "analog") {
|
} else if (this.config.displayType === "analog") {
|
||||||
// Display only an analog clock
|
// Display only an analog clock
|
||||||
@ -244,6 +290,8 @@ Module.register("clock",{
|
|||||||
digitalWrapper.style.cssFloat = "none";
|
digitalWrapper.style.cssFloat = "none";
|
||||||
digitalWrapper.appendChild(dateWrapper);
|
digitalWrapper.appendChild(dateWrapper);
|
||||||
digitalWrapper.appendChild(timeWrapper);
|
digitalWrapper.appendChild(timeWrapper);
|
||||||
|
digitalWrapper.appendChild(sunWrapper);
|
||||||
|
digitalWrapper.appendChild(moonWrapper);
|
||||||
digitalWrapper.appendChild(weekWrapper);
|
digitalWrapper.appendChild(weekWrapper);
|
||||||
|
|
||||||
var appendClocks = function(condition, pos1, pos2) {
|
var appendClocks = function(condition, pos1, pos2) {
|
||||||
|
@ -66,3 +66,13 @@
|
|||||||
-ms-transform-origin: 50% 100%;
|
-ms-transform-origin: 50% 100%;
|
||||||
transform-origin: 50% 100%;
|
transform-origin: 50% 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.module.clock .sun,
|
||||||
|
.module.clock .moon {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.module.clock .sun > *,
|
||||||
|
.module.clock .moon > * {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user