sunriseSunset function
Approximate times of sunrise, solar noon, and sunset.
jd is the Julian Day at 0h UT for the desired date.
lat is observer latitude (radians).
lon is observer longitude (radians, positive west).
Returns JD values for (sunrise, noon, sunset), or null components if the Sun never rises or sets at that location/date.
Implementation
({double? rise, double noon, double? set}) sunriseSunset(
double jd, double lat, double lon) {
// Solar noon approximation
final eq = solar.apparentEquatorial(jd);
// Approximate transit
final noon = jd + lon / (2 * math.pi);
final h = _hourAngle(eq.dec, lat);
if (h == null) {
return (rise: null, noon: noon, set: null);
}
final hDays = h / (2 * math.pi); // hour angle as fraction of day
return (
rise: noon - hDays,
noon: noon,
set: noon + hDays,
);
}