using Innovative.SolarCalculator;
using Innovative.Geometry;
private static DateTime RoundUp(DateTime date)
return date.AddSeconds((60 - date.Second) <= 30 ? (60 - date.Second) : -date.Second);
private static DateTime AngleTime(Angle angle, SolarTimes sunDetails)
if (sunDetails.SolarElevation < (double)-3)
zman = DateTime.Today.AddHours(1);
while (sunDetails.SolarElevation <= angle)
zman = zman.AddMinutes(1);
sunDetails.ForDate = zman;
zman = new DateTime(sunDetails.ForDate.Ticks);
while (sunDetails.SolarElevation >= angle)
zman = zman.AddMinutes(1);
sunDetails.ForDate = zman;
public static void main()
SolarTimes solarTimes = new SolarTimes(new DateTime(2023,3,13), 32.10933, 34.8555);
DateTime sunrise = RoundUp(solarTimes.Sunrise);
DateTime sunset = RoundUp(solarTimes.Sunset);
DateTime realSunrise = sunrise.AddMinutes(-4);
DateTime realSunset = sunset.AddMinutes(4);
TimeSpan difference = realSunset.Subtract(realSunrise);
double differenceInMin = difference.TotalMinutes;
TimeSpan TempHour = TimeSpan.FromMinutes(((differenceInMin) / 12));
TimeSpan TempMin = TimeSpan.FromMinutes(TempHour.TotalMinutes / 60);
DateTime alotHashar = AngleTime(-16.999, solarTimes);
DateTime talitAndTfilin = AngleTime(-10.2, solarTimes);
DateTime sofZmanKriatShma = RoundUp(realSunrise.AddHours(TempHour.TotalHours * 3));
DateTime sofZmantfila = RoundUp(realSunrise.AddHours(TempHour.TotalHours * 4));
DateTime hazot = RoundUp(realSunrise.AddHours(6 * TempHour.TotalHours));
DateTime minhaGedola = difference.Hours >= 12 ? RoundUp(realSunrise.AddHours(TempHour.TotalHours * 6.5)) : hazot.AddMinutes(30);
DateTime minhaKtana = RoundUp(realSunset.AddHours(-2.5 * TempHour.TotalHours));
DateTime plagHaminha = RoundUp(realSunset.AddHours(-1.25 * TempHour.TotalHours));
SolarTimes sunsetSolar = new SolarTimes(sunset, 32.10933,34.8555);
double zetAngle = (double)sunsetSolar.SolarElevation - 6;
DateTime zetHakochavim = AngleTime(zetAngle, sunsetSolar);
Console.WriteLine("Knisat shabat : " + sunset.AddMinutes(-22).ToString("HH:mm:ss") + "\n");