/// <summary> /// Adjust calculated imsak, fajr, maghrib and isha prayer times to high latitude adjustment. /// </summary> private static PrayersInDouble AdjustAllForHighLatitude(PrayersInDouble raw, PrayerCalculationSettings settings) { // // Do not apply adjustment if none option is specified. if (settings.HighLatitudeAdjustment == HighLatitudeAdjustment.None) { return(raw); } // Copy reference. var method = settings.HighLatitudeAdjustment; var imsak = raw.Imsak; var fajr = raw.Fajr; var sunrise = raw.Sunrise; var sunset = raw.Sunset; var maghrib = raw.Maghrib; var isha = raw.Isha; var imsakParameterValue = settings.ImsakParameter.Value; var fajrParameterValue = settings.CalculationMethod.FajrParameter.Value; var maghribParameterValue = settings.CalculationMethod.MaghribParameter.Value; var ishaParameterValue = settings.CalculationMethod.IshaParameter.Value; // Compute sunrise to sunset difference. var diff = DateTimeMath.ComputeDuration(raw.Sunrise, raw.Sunset); // Adjust. raw.Imsak = AdjustForHighLatitude(method, imsak, sunrise, imsakParameterValue, diff, Direction.CounterClockwise); raw.Fajr = AdjustForHighLatitude(method, fajr, sunrise, fajrParameterValue, diff, Direction.CounterClockwise); raw.Maghrib = AdjustForHighLatitude(method, maghrib, sunset, maghribParameterValue, diff, Direction.Clockwise); raw.Isha = AdjustForHighLatitude(method, isha, sunset, ishaParameterValue, diff, Direction.Clockwise); return(raw); }
/// <summary> /// Apply adjustments to given calculated prayer time. /// </summary> private static PrayersInDouble AdjustTime(PrayersInDouble raw, PrayerCalculationSettings settings, double longitude, double timeZone) { // Adjust imsak if minute adjustment parameter is used. if (settings.ImsakParameter.Type == PrayerCalculationParameterType.MinutesAdjust) { raw.Imsak = raw.Fajr + (settings.ImsakParameter.Value / 60.0); } // Adjust maghrib if minute adjustment parameter is used. // This is Sunni method which maghrib equals to sunset. As precaution, this // library add 1 minute to the sunset time. if (settings.CalculationMethod.MaghribParameter.Type == PrayerCalculationParameterType.MinutesAdjust) { raw.Maghrib = raw.Sunset + 0.016666666666666667 + (settings.CalculationMethod.MaghribParameter.Value / 60.0); } // Adjust isha if minute adjustment parameter is used. if (settings.CalculationMethod.IshaParameter.Type == PrayerCalculationParameterType.MinutesAdjust) { raw.Isha = raw.Maghrib + (settings.CalculationMethod.IshaParameter.Value / 60.0); } // Adjust to time zone. raw = AdjustAllToTimeZone(raw, longitude, timeZone); raw = AdjustAllForHighLatitude(raw, settings); raw = MinuteAdjustAll(raw, settings); return(raw); }
/// <summary> /// Apply time zone adjustment to given calculated prayer time. /// </summary> private static PrayersInDouble MinuteAdjustAll(PrayersInDouble raw, PrayerCalculationSettings settings) { raw.Imsak = raw.Imsak + (settings.ImsakMinutesAdjustment / 60.0); raw.Fajr = raw.Fajr + (settings.FajrMinutesAdjustment / 60.0); raw.Sunrise = raw.Sunrise + (settings.SunriseMinutesAdjustment / 60.0); raw.Dhuha = raw.Dhuha + (settings.DhuhaMinutesAdjustment / 60.0); raw.Zuhr = raw.Zuhr + (settings.ZuhrMinutesAdjustment / 60.0); raw.Asr = raw.Asr + (settings.AsrMinutesAdjustment / 60.0); raw.Maghrib = raw.Maghrib + (settings.MaghribMinutesAdjustment / 60.0); raw.Isha = raw.Isha + (settings.IshaMinutesAdjustment / 60.0); return(raw); }
/// <summary> /// Convert <see cref="PrayersInDouble"/> into <see cref="Prayers"/>. /// </summary> private static Prayers ConvertFromFloatingPointFormat(PrayersInDouble prayers, int year, int month, int day, double timeZone) { var local = new DateTimeOffset(year, month, day, 0, 0, 0, TimeSpan.FromHours(timeZone)); var instant = Instant.FromDateTimeOffset(local); return(new Prayers(instant + Duration.FromHours(prayers.Imsak), instant + Duration.FromHours(prayers.Fajr), instant + Duration.FromHours(prayers.Sunrise), instant + Duration.FromHours(prayers.Dhuha), instant + Duration.FromHours(prayers.Zuhr), instant + Duration.FromHours(prayers.Asr), instant + Duration.FromHours(prayers.Sunset), instant + Duration.FromHours(prayers.Maghrib), instant + Duration.FromHours(prayers.Isha), instant + Duration.FromHours(prayers.Midnight))); }
/// <summary> /// Apply time zone adjustment to given calculated prayer time. /// </summary> private static PrayersInDouble AdjustAllToTimeZone(PrayersInDouble raw, double longitude, double timeZone) { var adjustment = timeZone - (longitude / 15.0); raw.Imsak = raw.Imsak + adjustment; raw.Fajr = raw.Fajr + adjustment; raw.Sunrise = raw.Sunrise + adjustment; raw.Dhuha = raw.Dhuha + adjustment; raw.Zuhr = raw.Zuhr + adjustment; raw.Asr = raw.Asr + adjustment; raw.Sunset = raw.Sunset + adjustment; raw.Maghrib = raw.Maghrib + adjustment; raw.Isha = raw.Isha + adjustment; return(raw); }
/// <summary> /// Compute all prayer times at given Julian Date and return the raw results. /// </summary> private static PrayersInDouble ComputeRaw(double jd, PrayerCalculationSettings settings, double latitude, double altitude) { var raw = new PrayersInDouble(); // Compute imsak. if (settings.ImsakParameter.Type == PrayerCalculationParameterType.Angle) { // raw.imsak = _computeImsakTime(jd, settings.imsakParameter.value, latitude); // NOTE: Do imsak time can be calculated using angle parameter? throw new PrayerCalculationException("Imsak calculation parameter type must be the type of minute adjust."); } // Check fajr parameter type. if (settings.CalculationMethod.FajrParameter.Type == PrayerCalculationParameterType.MinutesAdjust) { throw new PrayerCalculationException("Fajr calculation parameter type must be the type of angle."); } // Compute fajr, sunrise, dhuha, zuhr, asr and sunset. raw.Fajr = ComputeFajrTime(jd, settings.CalculationMethod.FajrParameter.Value, latitude); raw.Sunrise = ComputeSunriseTime(jd, latitude, altitude); raw.Dhuha = ComputeDhuhaTime(raw.Fajr, raw.Sunrise); raw.Zuhr = ComputeZuhrTime(jd); raw.Asr = ComputeAsrTime(jd, settings.JuristicMethod.TimeOfShadow, latitude); raw.Sunset = ComputeSunsetTime(jd, latitude, altitude); // Compute maghrib. if (settings.CalculationMethod.MaghribParameter.Type == PrayerCalculationParameterType.Angle) { raw.Maghrib = ComputeMaghribTime(jd, settings.CalculationMethod.MaghribParameter.Value, latitude); } // Compute isha. if (settings.CalculationMethod.IshaParameter.Type == PrayerCalculationParameterType.Angle) { raw.Isha = ComputeIshaTime(jd, settings.CalculationMethod.IshaParameter.Value, latitude); } return(raw); }