-
Notifications
You must be signed in to change notification settings - Fork 74
Open

Description
Hello
this little snippet of code was implemented from, if i remember, wikipedia.
It assumes longitude/latitude is stored in lon/lat variables.
The results are not "exact" to the minute, but approximately so. Better than the moshier calculations tho.
datesr = {
year: 2000,
month: 1,
day: 1),
hours: 12,
minutes: 0,
seconds: 0.0
};
nj = datesr.julian - 2451545.0;
Jst = nj - (lon/360.0);
Mas = (357.5291 + (0.98560028*Jst)) % 360.0;
Cen = 1.9148*Math.sin(Mas*$const.DTR) + 0.02*Math.sin(2*Mas*$const.DTR) + 0.0003*Math.sin(3*Mas*$const.DTR);
lamda = (Mas + Cen + 180 + 102.9372) % 360.0;
Jtra = 2451545.0 + Jst + 0.0053*Math.sin(Mas*$const.DTR) - 0.0069*Math.sin(2*lamda*$const.DTR);
sindelta = Math.sin(lamda*$const.DTR) * Math.sin(23.44*$const.DTR);
deltainv = Math.asin(sindelta);
elevel = -1.15*Math.sqrt(60)/60;
cosw = ((Math.sin((elevel-0.83)*$const.DTR) - Math.sin(lat*$const.DTR)*sindelta)/(Math.cos(lat*$const.DTR)*Math.cos(deltainv)));
wo = Math.acos(cosw)*$const.RTD;
Jsunrise = Jtra - wo/360;
Jsunset = Jtra + wo/360;
sunr = { year:0, month:0, day:0, hours:0, minutes:0, seconds:0 };
suns = { year:0, month:0, day:0, hours:0, minutes:0, seconds:0 };
$copy(sunr , d);
$copy(suns , d);
sunr.universalDate = $moshier.julian.toGregorian ({ julian: Jsunrise + ((tz*3600.0)/86400.0) });
suns.universalDate = $moshier.julian.toGregorian ({ julian: Jsunset + ((tz*3600.0)/86400.0)});
sunriset = (sunr.universalDate.hours % 12) + ":" + ("00"+sunr.universalDate.minutes).substr(-2) + " AM";
sunsett = (suns.universalDate.hours % 12) + ":" + ("00"+suns.universalDate.minutes).substr(-2) + " PM";