From e7d44c963254f00e6c6ee920affb9c6e2afa0394 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Sun, 2 Feb 2025 23:36:16 +1000 Subject: [PATCH] [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 --- .../org/openhab/binding/astro/internal/calc/MoonCalc.java | 8 ++++---- .../binding/astro/internal/util/DateTimeUtils.java | 7 ------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java index 9f5ba80a486..e1f3c8d1cf7 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java @@ -118,9 +118,9 @@ public class MoonCalc { */ private void setMoonPhase(Calendar calendar, Moon moon) { MoonPhase phase = moon.getPhase(); - double julianDateEndOfDay = DateTimeUtils.endOfDayDateToJulianDate(calendar); - double parentNewMoon = getPreviousPhase(calendar, julianDateEndOfDay, NEW_MOON); - double age = Math.abs(parentNewMoon - julianDateEndOfDay); + double julianDate = DateTimeUtils.dateToJulianDate(calendar); + double parentNewMoon = getPreviousPhase(calendar, julianDate, NEW_MOON); + double age = Math.abs(parentNewMoon - julianDate); phase.setAge(age); long parentNewMoonMillis = DateTimeUtils.toCalendar(parentNewMoon).getTimeInMillis(); @@ -129,7 +129,7 @@ public class MoonCalc { double agePercent = ageRangeTimeMillis != 0 ? ageCurrentMillis * 100.0 / ageRangeTimeMillis : 0; phase.setAgePercent(agePercent); phase.setAgeDegree(3.6 * agePercent); - double illumination = getIllumination(DateTimeUtils.dateToJulianDate(calendar)); + double illumination = getIllumination(julianDate); phase.setIllumination(illumination); boolean isWaxing = age < (29.530588853 / 2); if (DateTimeUtils.isSameDay(calendar, phase.getNew())) { diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/DateTimeUtils.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/DateTimeUtils.java index 5d8f763d2d5..9e19adaa25f 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/DateTimeUtils.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/DateTimeUtils.java @@ -129,13 +129,6 @@ public class DateTimeUtils { 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. */