double jastro = getSunsetJulianDate(w3, m, lsun, lw, n);
double jdark = getSunsetJulianDate(w4, m, lsun, lw, n);
double jnau2 = getSunriseJulianDate(jtransit, jastro);
double jastro2 = getSunriseJulianDate(jtransit, jdark);
Sun sun = new Sun();
sun.setAstroDawn(new Range(DateTimeUtils.toCalendar(jastro2), DateTimeUtils.toCalendar(jnau2)));
sun.setAstroDusk(new Range(DateTimeUtils.toCalendar(jastro), DateTimeUtils.toCalendar(jdark)));
if (onlyAstro) {
return sun;
}
sun.setNoon(new Range(DateTimeUtils.toCalendar(jtransit), DateTimeUtils.toCalendar(jtransit
+ JD_ONE_MINUTE_FRACTION)));
sun.setRise(new Range(DateTimeUtils.toCalendar(jrise), DateTimeUtils.toCalendar(jriseend)));
sun.setSet(new Range(DateTimeUtils.toCalendar(jsetstart), DateTimeUtils.toCalendar(jset)));
sun.setCivilDawn(new Range(DateTimeUtils.toCalendar(Jciv2), DateTimeUtils.toCalendar(jrise)));
sun.setCivilDusk(new Range(DateTimeUtils.toCalendar(jset), DateTimeUtils.toCalendar(jnau)));
sun.setNauticDawn(new Range(DateTimeUtils.toCalendar(jnau2), DateTimeUtils.toCalendar(Jciv2)));
sun.setNauticDusk(new Range(DateTimeUtils.toCalendar(jnau), DateTimeUtils.toCalendar(jastro)));
boolean isSunUpAllDay = isSunUpAllDay(calendar, latitude, longitude);
// daylight
Range daylightRange = new Range();
if (sun.getRise().getStart() == null && sun.getRise().getEnd() == null) {
if (isSunUpAllDay) {
daylightRange = new Range(DateTimeUtils.truncateToMidnight(calendar),
DateTimeUtils.truncateToMidnight(addDays(calendar, 1)));
}
} else {
daylightRange = new Range(sun.getRise().getEnd(), sun.getSet().getStart());
}
sun.setDaylight(daylightRange);
// morning night
Sun sunYesterday = getSunInfo(addDays(calendar, -1), latitude, longitude, true);
Range morningNightRange = null;
if (sunYesterday.getAstroDusk().getEnd() != null
&& DateUtils.isSameDay(sunYesterday.getAstroDusk().getEnd(), calendar)) {
morningNightRange = new Range(sunYesterday.getAstroDusk().getEnd(), sun.getAstroDawn().getStart());
} else if (isSunUpAllDay) {
morningNightRange = new Range();
} else {
morningNightRange = new Range(DateTimeUtils.truncateToMidnight(calendar), sun.getAstroDawn().getStart());
}
sun.setMorningNight(morningNightRange);
// evening night
Range eveningNightRange = null;
if (sun.getAstroDusk().getEnd() != null && DateUtils.isSameDay(sun.getAstroDusk().getEnd(), calendar)) {
eveningNightRange = new Range(sun.getAstroDusk().getEnd(), DateTimeUtils.truncateToMidnight(addDays(
calendar, 1)));
} else {
eveningNightRange = new Range();
}
sun.setEveningNight(eveningNightRange);
// night
if (isSunUpAllDay) {
sun.setNight(new Range());
} else {
Sun sunTomorrow = getSunInfo(addDays(calendar, 1), latitude, longitude, true);
sun.setNight(new Range(sun.getAstroDusk().getEnd(), sunTomorrow.getAstroDawn().getStart()));
}
// eclipse
SunEclipse eclipse = sun.getEclipse();
MoonCalc mc = new MoonCalc();