
This simple C# Singleton class calculates the Sunrise and Sunset times for a given date. After searching for a simple and decent implementation for calculating Sunrise and Sunset times for given dates, and trying several implementations that were eiter too complicated to migrate to C# or simply not working, I found a simple yet working JavaScript implementation here: (http://home.att.net/~srschmitt/script_sun_rise_set.html). . I migrated the code to C#, tweeking it a little so that it provides accurate calculations. Also, I wrapped it as a Singleton class (assuming multiple instances would not be required for such a class) and added a lock to the main calculation method, in order to make it thread safe (via blocking).
|