Background

I wanted to add a feature to Presto's Sidebar Clock that would automatically adjust the color of the clock based on the time of day. Because the clock has support for international time zones, I thought it might be helpful to know whether it was day or night in the other time zones that a user tracks.

There are a lot of web sites that calculate this information. And most of them use JavaScript. And some sites, such as NOAA, had a generous license that would allow reuse of the code. Unfortunately, extracting the code and making it usable proved more difficult than it should have been.

Eventually, I found a page with the calculations and decided it would be faster to go ahead and write it myself from the grounds up. I've generalized it a bit and made it a class in the hopes that other developers can use it.