mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Merge pull request #1925 from dtreskunov/dtreskunov/fix-clock-module-moon-widget
fix bugs in showMoonTimes in clock module
This commit is contained in:
commit
d7295948fd
@ -179,11 +179,19 @@ Module.register("clock",{
|
|||||||
if (this.config.showMoonTimes) {
|
if (this.config.showMoonTimes) {
|
||||||
const moonIllumination = SunCalc.getMoonIllumination(now.toDate());
|
const moonIllumination = SunCalc.getMoonIllumination(now.toDate());
|
||||||
const moonTimes = SunCalc.getMoonTimes(now, this.config.lat, this.config.lon);
|
const moonTimes = SunCalc.getMoonTimes(now, this.config.lat, this.config.lon);
|
||||||
const isVisible = now.isBetween(moonTimes.rise, moonTimes.set);
|
const moonRise = moonTimes.rise;
|
||||||
const illuminatedFractionString = moonIllumination.fraction.toLocaleString(undefined, {style: 'percent'});
|
var moonSet;
|
||||||
|
if (moment(moonTimes.set).isAfter(moonTimes.rise)) {
|
||||||
|
moonSet = moonTimes.set;
|
||||||
|
} else {
|
||||||
|
const nextMoonTimes = SunCalc.getMoonTimes(now.clone().add(1, 'day'), this.config.lat, this.config.lon);
|
||||||
|
moonSet = nextMoonTimes.set;
|
||||||
|
}
|
||||||
|
const isVisible = now.isBetween(moonRise, moonSet) || moonTimes.alwaysUp === true;
|
||||||
|
const illuminatedFractionString = moonIllumination.fraction.toFixed(2) * 100 + '%';
|
||||||
moonWrapper.innerHTML = '<span class="' + (isVisible ? 'bright' : '') + '"><i class="fa fa-moon-o" aria-hidden="true"></i> ' + illuminatedFractionString + '</span>' +
|
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-up" aria-hidden="true"></i> ' + (moonRise ? formatTime(this.config, moonRise) : '...') + '</span>'+
|
||||||
'<span><i class="fa fa-arrow-down" aria-hidden="true"></i> ' + formatTime(this.config, moonTimes.set) + '</span>';
|
'<span><i class="fa fa-arrow-down" aria-hidden="true"></i> ' + (moonSet ? formatTime(this.config, moonSet) : '...') + '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user