private static DateTime SeasonAdjustedEveningTwilight( double latitude, int day, int year, DateTime sunset) { double a = 75 + ((25.60 / 55.0) * Math.Abs(latitude)); double b = 75 + ((2.050 / 55.0) * Math.Abs(latitude)); double c = 75 - ((9.210 / 55.0) * Math.Abs(latitude)); double d = 75 + ((6.140 / 55.0) * Math.Abs(latitude)); double adjustment; int dyy = PrayerTimes.DaysSinceSolstice(day, year, latitude); if (dyy < 91) { adjustment = a + (b - a) / 91.0 * dyy; } else if (dyy < 137) { adjustment = b + (c - b) / 46.0 * (dyy - 91); } else if (dyy < 183) { adjustment = c + (d - c) / 46.0 * (dyy - 137); } else if (dyy < 229) { adjustment = d + (c - d) / 46.0 * (dyy - 183); } else if (dyy < 275) { adjustment = c + (b - c) / 46.0 * (dyy - 229); } else { adjustment = b + (a - b) / 91.0 * (dyy - 275); } return(sunset.AddSeconds((int)Math.Round(adjustment * 60.0))); }
private static DateTime SeasonAdjustedMorningTwilight( double latitude, int day, int year, DateTime sunrise) { double a = 75 + ((28.65 / 55.0) * Math.Abs(latitude)); double b = 75 + ((19.44 / 55.0) * Math.Abs(latitude)); double c = 75 + ((32.74 / 55.0) * Math.Abs(latitude)); double d = 75 + ((48.10 / 55.0) * Math.Abs(latitude)); double adjustment; int dyy = PrayerTimes.DaysSinceSolstice(day, year, latitude); if (dyy < 91) { adjustment = a + (b - a) / 91.0 * dyy; } else if (dyy < 137) { adjustment = b + (c - b) / 46.0 * (dyy - 91); } else if (dyy < 183) { adjustment = c + (d - c) / 46.0 * (dyy - 137); } else if (dyy < 229) { adjustment = d + (c - d) / 46.0 * (dyy - 183); } else if (dyy < 275) { adjustment = c + (b - c) / 46.0 * (dyy - 229); } else { adjustment = b + (a - b) / 91.0 * (dyy - 275); } return(sunrise.AddSeconds(-(int)Math.Round(adjustment * 60.0))); }