SolarCalculator 3.3.0

GitHub Workflow Status (with branch)

Nuget Nuget

Nuget Nuget

Solar-Calculator

Calculates the sunrise and sunset for a given date and location (using GEO coordinates). This library uses the method outlined NOAA Solar Calculations Day spreadsheet found at http://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html.

Installing

Add this to your project in Visual Studio using NuGet Package Manager UI and ID SolarCalculator or using the Package Manager Console.

PM> Install-Package SolarCalculator

Sample Code

The sample code below shows how to initialize and call the Solar Calculator to get the sunrise and sunset for the given location.

Sunrise in Chicago

using System;
using Innovative.SolarCalculator;

//
// Geo coordinates of Oak Street Beach in Chicago, IL
//
// NOTE: the .Date is not necessary but is included to demonstrate that time input 
// does not affect the output. Time will be returned in the current time zone so it 
// will need to be adjusted to the time zone where the coordinates are from (there 
// are services that can be used to get time zone from a latitude and longitude position).
//
TimeZoneInfo cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
SolarTimes solarTimes = new SolarTimes(DateTime.Now.Date, 41.9032, -87.6224);
DateTime sunrise = TimeZoneInfo.ConvertTimeFromUtc(solarTimes.Sunrise.ToUniversalTime(), cst);

//
// Display the sunrise
//
Console.WriteLine($"View the sunrise across Lake Michigan from Oak Street Beach in Chicago at {sunrise.ToLongTimeString()} on {sunrise.ToLongDateString()}.");

Sunset in Michigan

//
// Geo coordinates of Benton Harbor/Benton Heights in Michigan
//
TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");              
SolarTimes solarTimes = new SolarTimes(DateTime.Now, 42.1543, -86.4459);
DateTime sunset = TimeZoneInfo.ConvertTimeFromUtc(solarTimes.Sunset.ToUniversalTime(), est);

//
// Display the sunset
//
Console.WriteLine($"View the sunset across Lake Michigan from Benton Harbor in Michigan at {sunset.ToLongTimeString()} on {sunset.ToLongDateString()}.");

No packages depend on SolarCalculator.

v3.3.0 Corrections added for Polar Day and Polar Night (Nickztar) v3.2.1 Added ReadMe to package. v3.2.0 Added net 7.0 support. v3.1.0 Added support for net 5.0 and net 6.0. v3.0.6 Added calculations for Astronomical, Nautical and Civil Dawn and Dusk times (rbdavison). v3.0.5 Reverted changes until further research can be done. v3.0.4 Corrected date shifting issue. v3.0.3 Added missing documentation. v3.0.2 Added source code and symbol integration to NuGet package. v3.0.1 Changed license to LGPL Public 3.0. v3.0.0 Added support for multiple frameworks. v2.0.4 Bug Fix - Removed internal date setting by string that was not compatible in all locales - t1m0thyj v2.0.3 Added azimuth calculation - GeorgeHahn v2.0.2 Corrected date portion of SolarNoon date and time. It was showing the correct time but the wrong day. v2.0.1 Change default value for SolarNoon to the ForDate property. v2.0.0 Converted to .NET Standard/Moved to GitHub. v1.0.8 Added multiple .NET versions. v1.0.7 Removed Angle class and referenced it from NuGet library. v1.0.6 Updated NuGet package only. v1.0.5 Added a class/data type called Angle to handle computations and conversions. This class inherently behaves as a type double so that pre-existing code is not broken. v1.0.4 Change the type of ForDate to DateTimeOffset due to improper handling of Time Zone. This does not affected code already written against this method. v1.0.3 Corrected a time issue causing the wrong sunrise and sunset times to be returned. All test cases passed. v1.0.2 Added XML comments file. v1.0.1 Updated license and project URL's in package.

.NET Framework 4.0

.NET Framework 4.5

.NET Framework 4.6.1

.NET Standard 1.3

.NET Core 3.1

.NET 5.0

.NET 6.0

.NET 7.0

.NET Standard 2.0

.NET Standard 2.1

Version Downloads Last updated
3.6.0 0 11/15/2025
3.5.0 1 04/28/2025
3.4.0 0 09/11/2024
3.3.0 1 03/24/2025
3.2.1 0 12/02/2022
3.2.0 0 12/02/2022
3.1.0 0 01/15/2022
3.0.6 0 08/04/2020
3.0.5 0 04/17/2020
3.0.4 0 04/16/2020
3.0.3 0 04/14/2020
3.0.2 0 04/14/2020
3.0.1 0 01/25/2020
2.0.4 0 10/17/2018
2.0.3 0 07/10/2018
2.0.2 0 10/02/2017
2.0.1 0 10/01/2017
2.0.0 0 09/29/2017
1.0.8 0 07/27/2014