mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 19:34:05 +01:00
[astro] Update real-time Moon Phase Age (#18203)
Instead of returning a constant value of the moon phase age relative to the start of the day, return the real-time calculation of the moon phase age on each channel update Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
parent
8e8bb061fb
commit
e7d44c9632
@ -118,9 +118,9 @@ public class MoonCalc {
|
|||||||
*/
|
*/
|
||||||
private void setMoonPhase(Calendar calendar, Moon moon) {
|
private void setMoonPhase(Calendar calendar, Moon moon) {
|
||||||
MoonPhase phase = moon.getPhase();
|
MoonPhase phase = moon.getPhase();
|
||||||
double julianDateEndOfDay = DateTimeUtils.endOfDayDateToJulianDate(calendar);
|
double julianDate = DateTimeUtils.dateToJulianDate(calendar);
|
||||||
double parentNewMoon = getPreviousPhase(calendar, julianDateEndOfDay, NEW_MOON);
|
double parentNewMoon = getPreviousPhase(calendar, julianDate, NEW_MOON);
|
||||||
double age = Math.abs(parentNewMoon - julianDateEndOfDay);
|
double age = Math.abs(parentNewMoon - julianDate);
|
||||||
phase.setAge(age);
|
phase.setAge(age);
|
||||||
|
|
||||||
long parentNewMoonMillis = DateTimeUtils.toCalendar(parentNewMoon).getTimeInMillis();
|
long parentNewMoonMillis = DateTimeUtils.toCalendar(parentNewMoon).getTimeInMillis();
|
||||||
@ -129,7 +129,7 @@ public class MoonCalc {
|
|||||||
double agePercent = ageRangeTimeMillis != 0 ? ageCurrentMillis * 100.0 / ageRangeTimeMillis : 0;
|
double agePercent = ageRangeTimeMillis != 0 ? ageCurrentMillis * 100.0 / ageRangeTimeMillis : 0;
|
||||||
phase.setAgePercent(agePercent);
|
phase.setAgePercent(agePercent);
|
||||||
phase.setAgeDegree(3.6 * agePercent);
|
phase.setAgeDegree(3.6 * agePercent);
|
||||||
double illumination = getIllumination(DateTimeUtils.dateToJulianDate(calendar));
|
double illumination = getIllumination(julianDate);
|
||||||
phase.setIllumination(illumination);
|
phase.setIllumination(illumination);
|
||||||
boolean isWaxing = age < (29.530588853 / 2);
|
boolean isWaxing = age < (29.530588853 / 2);
|
||||||
if (DateTimeUtils.isSameDay(calendar, phase.getNew())) {
|
if (DateTimeUtils.isSameDay(calendar, phase.getNew())) {
|
||||||
|
@ -129,13 +129,6 @@ public class DateTimeUtils {
|
|||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the end of day julian date from the calendar object.
|
|
||||||
*/
|
|
||||||
public static double endOfDayDateToJulianDate(Calendar calendar) {
|
|
||||||
return dateToJulianDate(endOfDayDate(calendar));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the year of the calendar object as a decimal value.
|
* Returns the year of the calendar object as a decimal value.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user