/// <summary> /// Compute night fraction value for given high latitude method, angle and sunset/sunrise difference. /// </summary> /// <param name="method"> /// <see cref="HighLatitudeAdjustment" /> method to use to get the night fraction. /// </param> /// <param name="angle"> /// Sun's angle value to get the night fraction. Only required when <paramref name="method" /> is set to <see cref="HighLatitudeAdjustment.AngleBased" /> /// method. /// </param> /// <param name="diff"> /// Difference hour between sunrise to sunset in floating point. /// </param> /// <returns> /// Night fraction value for given high latitude method, angle and sunset/sunrise difference. /// </returns> internal static double GetNightFraction(HighLatitudeAdjustment method, double angle, double diff) { // Default value to middle of the night method. double nightFraction; switch (method) { case HighLatitudeAdjustment.MiddleOfNight: nightFraction = 0.5; break; case HighLatitudeAdjustment.OneSeventhOfNight: nightFraction = 0.14285714285714285; break; case HighLatitudeAdjustment.AngleBased: nightFraction = 0.016666666666666667 * angle; break; default: throw new ArgumentOutOfRangeException(nameof(method)); } return(nightFraction * diff); }
/// <summary> /// Adjust calculated prayer time to high latitude adjustment. /// </summary> private static double AdjustForHighLatitude(HighLatitudeAdjustment method, double time, double baseTime, double angle, double diff, Direction direction) { // Compute night fraction and duration. var nightFraction = AstronomyMath.GetNightFraction(method, angle, diff); var duration = direction == Direction.Clockwise ? DateTimeMath.ComputeDuration(time, baseTime) : DateTimeMath.ComputeDuration(baseTime, time); // Copy reference; var newTime = time; if (duration > nightFraction) { var adjustment = direction == Direction.Clockwise ? nightFraction : -nightFraction; newTime = baseTime + adjustment; } return(newTime); }