using Innovative.SolarCalculator;
using System.Collections.Generic;
using Innovative.Geometry;
public static bool isSunsetPast(){return true;}
public static Tuple<DateTime, DateTime> ShabesTimesCalcuate(Angle ang)
TimeSpan offset = new TimeSpan(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTimeOffset.UtcNow, "Israel Standard Time").Offset.Ticks);
DateTimeOffset localDate = new DateTimeOffset(DateTime.Today.Ticks, offset);
DateTimeOffset today = (localDate.DayOfWeek == DayOfWeek.Saturday && !isSunsetPast()) ? localDate.AddDays(-1) : localDate;
SolarTimes shabesSolar = new SolarTimes(today, 32.109333, 34.855499);
DateTimeOffset nextFriday = Enumerable.Range(0, 7)
.Select(i => today.AddDays(i))
.Single(day => day.DayOfWeek == DayOfWeek.Friday);
shabesSolar.ForDate = nextFriday;
knisa = RoundTimes(shabesSolar.Sunset.AddMinutes(-21));
localDate = new DateTimeOffset(shabesSolar.Sunset, offset);
shabesSolar.ForDate = localDate;
yezia = AngleTime(ang, shabesSolar);
return new Tuple<DateTime, DateTime>(knisa, yezia);
public static DateTime RoundTimes(DateTime time)
return time.AddSeconds((60 - time.Second));
public static DateTime AngleTime(Angle angle, SolarTimes sunDetails)
DateTimeOffset zman = new DateTimeOffset(sunDetails.ForDate.Ticks, sunDetails.ForDate.Offset);
if (sunDetails.SolarElevation < (double)-3)
while (sunDetails.SolarElevation <= angle)
zman = zman.AddMinutes(1);
sunDetails.ForDate = zman;
while (sunDetails.SolarElevation >= angle)
zman = zman.AddMinutes(1);
sunDetails.ForDate = zman;
return new DateTime(zman.Ticks);
public static void Main()
TimeSpan offset = new TimeSpan(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTimeOffset.UtcNow, "Israel Standard Time").Offset.Ticks);
DateTimeOffset localDate = new DateTimeOffset(DateTime.Today.Ticks, offset);
SolarTimes sunSolar = new SolarTimes(localDate.AddDays(0), 32.109333, 34.855499);
DateTime sunrise = sunSolar.Sunrise;
DateTime sunset = sunSolar.Sunset;
TimeSpan difference = sunset.Subtract(sunrise);
double differenceInMin = difference.TotalMinutes;
TimeSpan TempHour = TimeSpan.FromMinutes(((differenceInMin) / 12));
TimeSpan TempMin = TimeSpan.FromMinutes(TempHour.TotalMinutes / 60);
DateTime start = sunrise.Add(-72*TempMin);
DateTime end = sunset.Add(72*TempMin);
TimeSpan newDifference = end.Subtract(start);
double newDifferenceInMin = newDifference.TotalMinutes;
TimeSpan newTempHour = TimeSpan.FromMinutes(((newDifferenceInMin) / 12));
TimeSpan newTempMin = TimeSpan.FromMinutes(TempHour.TotalMinutes / 60);
DateTime alotHashar = sunrise.Add(-72*TempMin);
DateTime talitAndTfilin = sunrise.Add(-66*TempMin);
DateTime sofZmanKriatShmaMagenAvraham = alotHashar.Add(3*newTempHour);
DateTime sofZmanKriatShmaHagra = sunrise.Add(3*TempHour);
DateTime sofZmanTfilaMagenAvraham = alotHashar.Add(4*newTempHour);
DateTime sofZmanTfilaHagra = sunrise.Add(4*TempHour);
DateTime hazot = sunrise.AddHours(6 * TempHour.TotalHours);
DateTime minhaGedola = hazot.AddMinutes(30);
DateTime minhaKetana = sunrise.Add(9.5*TempHour);
DateTime plagHamincha = sunset.Add(-1.025*TempHour);
DateTime knisa = ShabesTimesCalcuate(0.0).Item1;
DateTime yezia = ShabesTimesCalcuate(-8.5).Item2;
Console.WriteLine("Temp H:" + TempHour);
Console.WriteLine("sunrise: " + sunrise);
Console.WriteLine("sunset: " + sunset);
Console.WriteLine("shabes times \nknisa: " + knisa.ToString("HH:mm:ss") + "\n" + "yezia: " + yezia.ToString("HH:mm:ss"));