It's a hell of a wheel to reinvent, doing this properly. The thing that makes me mad about celestial calculations is the number of exceptions, specials cases, redefinitions - just yuck. Not to mention pretty much all of the models are wrong except Kepler's. Anything that comes down from Ptolemy or those other wiseguys - is more confusing than helpful.
My approach, honestly, is to look at a working implementation of this stuff, and then borrow that code. I'm sure you found this while searching around:
https://stellafane.org/misc/equinox.htmlWhen I view source on that page, I see some of the cleanest javascript I could ever expect to handle this. It seems like whoever made this probably accounted for lots of things that would take me a month to even realize were necessary. Somewhere around line 100 is this chunk:
//-----Calculate and Display a single event for a single year (Either a Equiniox or Solstice)
// Meeus Astronmical Algorithms Chapter 27
function calcEquiSol( i, year ) {
var k = i - 1;
var str;
var JDE0 = calcInitial( k, year); // Initial estimate of date of event
var T = ( JDE0 - 2451545.0) / 36525;
var W = 35999.373*T - 2.47;
var dL = 1 + 0.0334*COS(W) + 0.0007*COS(2*W);
var S = periodic24( T );
var JDE = JDE0 + ( (0.00001*S) / dL ); // This is the answer in Julian Emphemeris Days
var TDT = fromJDtoUTC( JDE ); // Convert Julian Days to TDT in a Date Object
var UTC = fromTDTtoUTC( TDT ); // Correct TDT to UTC, both as Date Objects
switch ( getTZ() ) {
case "LCL": str = UTC.toString() + "\n"; break; //Convert to Local time string
case "UTC": str = UTC.toUTCString() + "\n"; break; //Convert to UTC time string
case "DYN": str = TDT.toUTCString() + "\n"; //Convert to Dynamical Time String
str = str.replace( /UTC/g, "TDT" ); break; // Change UTC to TDT in this output string
}
writeN( i, str ); // Output date & time of event in Local Time
} // End calcEquiSol
Yeah - big project...
There is another take on this, too - maybe don't bother calculating this stuff outright. Might be best to bite the bullet and import a table, eh?