[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:
jimtng 2025-02-02 23:36:16 +10:00 committed by GitHub
parent 8e8bb061fb
commit e7d44c9632
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 11 deletions

View File

@ -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())) {

View File

@ -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.
*/ */