Giter Site home page Giter Site logo

drmontoya / solar-calculator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from porrey/solar-calculator

0.0 0.0 0.0 2.05 MB

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.

License: GNU Lesser General Public License v3.0

C# 99.63% Batchfile 0.37%

solar-calculator's Introduction

Build Status

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()}.");

solar-calculator's People

Contributors

georgehahn avatar porrey avatar t1m0thyj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.