private double GetCosineSunLocalHour(double sunTrueLong, Zenith zenith)
        {
            double sinSunDeclination    = GetSinOfSunDeclination(sunTrueLong);
            double cosineSunDeclination = GetCosineOfSunDeclination(sinSunDeclination);

            double zenithInRads = Utility.ConvertDegreesToRadians(zenith.degrees);
            double cosineZenith = Math.Cos(zenithInRads);
            double sinLatitude  = Math.Sin(Utility.ConvertDegreesToRadians(this.location.latitude));
            double cosLatitude  = Math.Cos(Utility.ConvertDegreesToRadians(this.location.latitude));

            double sinDeclinationTimesSinLat = sinSunDeclination * sinLatitude;
            double dividend = cosineZenith - sinDeclinationTimesSinLat;
            double divisor  = cosineSunDeclination * cosLatitude;

            return(Utility.SetScale(dividend / divisor));
        }
        private double ComputerSolarEventTime(Zenith solarZenith, DateTime date, bool isSunrise)
        {
            date = TimeZoneInfo.ConvertTime(date, this.timeZone);
            double longitudeHour = GetLongitudeHour(date, isSunrise);

            double meanAnomaly        = GetMeanAnomaly(longitudeHour);
            double sunTrueLong        = GetSunTrueLongitude(meanAnomaly);
            double cosineSunLocalHour = GetCosineSunLocalHour(sunTrueLong, solarZenith);

            if ((cosineSunLocalHour < -1d) || (cosineSunLocalHour > 1d))
            {
                throw new ArgumentOutOfRangeException("Sun Local Hour out of range");
            }

            double sunLocalHour  = GetSunLocalHour(cosineSunLocalHour, isSunrise);
            double localMeanTime = GetLocalMeanTime(sunTrueLong, longitudeHour, sunLocalHour);
            double localTime     = GetLocalTime(localMeanTime, date);

            return(localTime);
        }
 /// <summary>
 /// Computes the sunset time for the given zenith at the given date
 /// </summary>
 /// <param name="solarZenith"><see cref="Zenith"/> enum corresponding to the type of sunset to compute</param>
 /// <param name="date"><see cref="DateTime"/> object representing the date to compute the sunset for</param>
 /// <returns>The sunset time as a <see cref="DateTime?"/></returns>
 public DateTime?ComputeSunsetCalendar(Zenith solarZenith, DateTime date)
 {
     return(GetLocalTimeAsDateTime(ComputerSolarEventTime(solarZenith, date, false), date));
 }
 /// <summary>
 /// Computes the sunset time for the given zenith at the given date
 /// </summary>
 /// <param name="solarZenith"><see cref="Zenith"/> enum corresponding to the type of sunset to compute</param>
 /// <param name="date"><see cref="DateTime"/> object representing the date to compute the sunset for</param>
 /// <returns>The sunset time, in HH:MM format (24-hour clock), 00:00 if the sun does not set on the given date</returns>
 public string ComputeSunsetTime(Zenith solarZenith, DateTime date)
 {
     return(GetLocalTimeAsString(ComputerSolarEventTime(solarZenith, date, false)));
 }