[time-nuts] Sunrise, solar noon, sunset and the Equation of Time
David J Taylor
david-taylor at blueyonder.co.uk
Wed Aug 31 03:11:58 EDT 2016
I recently added code to Lady Heather to precisely calculate the sun
position, sunrise/solar noon/sunset times and the Equation of Time... Egad,
what a deep, dark rabbit hole that leads one down. And woe be unto thee
that trusts any of the online calculators. Results can be over 10 minutes
off and nobody gives times down to the second. Oh, and there's a half dozen
different types of sunrise/sunset to consider.
The gold standard for those calculation is NREL's Solar Position Algorithm.
It's awesome. It's also awesomely complex. Like 1300 lines of code and
several thousand double precision operations and 300+ trig functions per
result. It also has a rather wonky license agreement. (and if your time
zone is not Greenwich is can report the sunrise or sunset time for the
I finally settled on Grena's Algorithm 5 for sun position. It only around
100 lines long uses less than 20 trig function calls to calculate the sun
position and produces results comparable to SPA for the years 2010 .. 2110.
Getting sunrise/sunset/solar noon from solar position is a bit more
complicated. I do binary searches and interpolations to find when the sun
crosses the magic thresholds to within a second... it takes about 300 lines
of code and 60 sun position evaluations. Lady Heather can now play sound
files at sunrise, solar noon, sunset... your basic GPS disciplined rooster
and church bells.
And, for the sundial crowd, tomorrow is the day the Equation of Time
crosses 0.0 seconds so get out and set your sundials...
Interesting, Mark, especially your comments about online calculators. My
WXtrack program computes many of the values you mention, so I would be
interested to compare results. It calculates positions for the moon as
Also runs under Linux/WINE. I use routines from Dr TS Kelso. You will be
aware of the three different definitions of sunset, of course.
SatSignal Software - Quality software written to your requirements
Email: david-taylor at blueyonder.co.uk
More information about the time-nuts