Skip to content

Commit e7d44c9

Browse files
authored
[astro] Update real-time Moon Phase Age (openhab#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 <[email protected]>
1 parent 8e8bb06 commit e7d44c9

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ public void setPositionalInfo(Calendar calendar, double latitude, double longitu
118118
*/
119119
private void setMoonPhase(Calendar calendar, Moon moon) {
120120
MoonPhase phase = moon.getPhase();
121-
double julianDateEndOfDay = DateTimeUtils.endOfDayDateToJulianDate(calendar);
122-
double parentNewMoon = getPreviousPhase(calendar, julianDateEndOfDay, NEW_MOON);
123-
double age = Math.abs(parentNewMoon - julianDateEndOfDay);
121+
double julianDate = DateTimeUtils.dateToJulianDate(calendar);
122+
double parentNewMoon = getPreviousPhase(calendar, julianDate, NEW_MOON);
123+
double age = Math.abs(parentNewMoon - julianDate);
124124
phase.setAge(age);
125125

126126
long parentNewMoonMillis = DateTimeUtils.toCalendar(parentNewMoon).getTimeInMillis();
@@ -129,7 +129,7 @@ private void setMoonPhase(Calendar calendar, Moon moon) {
129129
double agePercent = ageRangeTimeMillis != 0 ? ageCurrentMillis * 100.0 / ageRangeTimeMillis : 0;
130130
phase.setAgePercent(agePercent);
131131
phase.setAgeDegree(3.6 * agePercent);
132-
double illumination = getIllumination(DateTimeUtils.dateToJulianDate(calendar));
132+
double illumination = getIllumination(julianDate);
133133
phase.setIllumination(illumination);
134134
boolean isWaxing = age < (29.530588853 / 2);
135135
if (DateTimeUtils.isSameDay(calendar, phase.getNew())) {

bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/DateTimeUtils.java

-7
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,6 @@ public static Calendar endOfDayDate(Calendar calendar) {
129129
return cal;
130130
}
131131

132-
/**
133-
* Returns the end of day julian date from the calendar object.
134-
*/
135-
public static double endOfDayDateToJulianDate(Calendar calendar) {
136-
return dateToJulianDate(endOfDayDate(calendar));
137-
}
138-
139132
/**
140133
* Returns the year of the calendar object as a decimal value.
141134
*/

0 commit comments

Comments
 (0)