using Innovative.SolarCalculator;
using System.Collections.Generic;
using Innovative.Geometry;
public static bool isSunsetPast(){return false;}
public static Tuple<DateTime, DateTime, DateTime> ShabesTimesCalcuate(Angle ang=null)
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 = ang != null ? shabesSolar.Sunset.AddMinutes(-18) : shabesSolar.Sunset.AddMinutes(-20);
localDate = new DateTimeOffset(shabesSolar.Sunset, offset);
shabesSolar.ForDate = localDate;
yezia = ang != null ? AngleTime(ang, shabesSolar) : shabesSolar.Sunset.AddMinutes(30);
yeziaRabenuTam = shabesSolar.Sunset;
return new Tuple<DateTime, DateTime, DateTime>(knisa, yezia,yeziaRabenuTam);
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(new DateTime(2024,11,08).Ticks, offset);
SolarTimes sunSolar = new SolarTimes(localDate, 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);
TimeSpan realSunrise = new TimeSpan(06,02,00);
TimeSpan realSunset = new TimeSpan(16,46,00);
TimeSpan realDifference = sunset.Subtract(sunrise);
double realDifferenceInMin = realDifference.TotalMinutes;
TimeSpan realTempHour = TimeSpan.FromMinutes(((realDifferenceInMin) / 12));
TimeSpan realTempMin = TimeSpan.FromMinutes(realTempHour.TotalMinutes / 60);
Console.WriteLine("---------------------");
Console.WriteLine(realTempHour);
Console.WriteLine(realTempMin);
Console.WriteLine("---------------------");
Console.WriteLine("Alot Hashahar: " + sunrise.Add(-72*TempMin));
Console.WriteLine("Talit: " + sunrise.Add(-66*TempMin));
Console.WriteLine("---------------------");
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 zetHachohavim = sunset.Add(13.5*TempMin);
DateTime knisa = ShabesTimesCalcuate().Item1;
DateTime yezia = ShabesTimesCalcuate().Item2;
DateTime yeziaRabenuTam = ShabesTimesCalcuate().Item3.Add(72*TempMin);
Console.WriteLine("Temp H:" + TempHour);
Console.WriteLine("alot - " + alotHashar);
Console.WriteLine("talit - " +talitAndTfilin);
Console.WriteLine("netz - " +sunrise);
Console.WriteLine("sz-kash-magen - " +sofZmanKriatShmaMagenAvraham);
Console.WriteLine("sz-kash-hagra - " +sofZmanKriatShmaHagra);
Console.WriteLine("sz-tfi-magen - " +sofZmanTfilaMagenAvraham);
Console.WriteLine("sz-tfi-hagra - " +sofZmanTfilaHagra);
Console.WriteLine("hazot - " +hazot);
Console.WriteLine("minhaGedola - " +minhaGedola);
Console.WriteLine("minhaKetana - " +minhaKetana);
Console.WriteLine("plagHamincha - " +plagHamincha);
Console.WriteLine("shkiaa - " +sunset);
Console.WriteLine("zetHachohavim - " +zetHachohavim);
Console.WriteLine("shabes times \nknisa: " + knisa.ToString("HH:mm:ss") + "\n" + "yezia: " + yezia.ToString("HH:mm:ss") + "\n" + "yezia-r-t: " + yeziaRabenuTam.ToString("HH:mm:ss"));