Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <summary>
        ///     Generate after later prayer time.
        /// </summary>
        /// <param name="clock">
        ///     <see cref="IClock" /> interface object for getting after later <see cref="Instant" /> value.
        /// </param>
        /// <param name="settings">
        ///     Settings containing parameters for calculating prayer times.
        /// </param>
        /// <param name="coordinate">
        ///     Location's coordinate.
        /// </param>
        /// <param name="timeZone">
        ///     Location's time zone.
        /// </param>
        /// <returns>
        ///     <see cref="Prayer" /> object containing after later prayer time data.
        /// </returns>
        internal static Prayer GetAfterLaterPrayerTime(IClock clock, PrayerCalculationSettings settings, Geocoordinate coordinate, double timeZone)
        {
            var now      = clock.GetCurrentInstant();
            var today    = GetPrayerTimesForOneDay(now, settings, coordinate, timeZone);
            var tomorrow = GetPrayerTimesForOneDay(now + Duration.FromDays(1), settings, coordinate, timeZone);

            if (now < today.Imsak)
            {
                return(new Prayer(PrayerType.Sunrise, today.Sunrise));
            }

            if (now < today.Fajr)
            {
                return(new Prayer(PrayerType.Dhuha, today.Dhuha));
            }

            if (now < today.Sunrise)
            {
                return(new Prayer(PrayerType.Zuhr, today.Zuhr));
            }

            if (now < today.Dhuha)
            {
                return(new Prayer(PrayerType.Asr, today.Asr));
            }

            if (now < today.Zuhr)
            {
                return(new Prayer(PrayerType.Maghrib, today.Maghrib));
            }

            if (now < today.Asr)
            {
                return(new Prayer(PrayerType.Isha, today.Isha));
            }

            if (now < today.Maghrib)
            {
                return(new Prayer(PrayerType.Imsak, today.Imsak));
            }

            if (now < today.Isha)
            {
                return(new Prayer(PrayerType.Fajr, tomorrow.Fajr));
            }

            return(new Prayer(PrayerType.Sunrise, tomorrow.Sunrise));
        }
Example #5
0
        /// <summary>
        ///     Generate prayer times for one day at given date.
        /// </summary>
        /// <param name="when">
        ///     <see cref="Instant" /> value which represents the date.
        /// </param>
        /// <param name="settings">
        ///     Settings containing parameters for calculating prayer times.
        /// </param>
        /// <param name="coordinate">
        ///     Location's coordinate.
        /// </param>
        /// <param name="timeZone">
        ///     Location's time zone.
        /// </param>
        /// <returns>
        ///     <see cref="Prayers" /> object containing prayer times for one day at given date.
        /// </returns>
        internal static Prayers GetPrayerTimesForOneDay(Instant when, [NotNull] PrayerCalculationSettings settings, Geocoordinate coordinate, double timeZone)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var utc    = when.InUtc();
            var year   = utc.Year;
            var month  = utc.Month;
            var day    = utc.Day;
            var local  = new LocalDate(year, month, day);
            var newUtc = new ZonedDateTime(local.AtMidnight(), DateTimeZone.Utc, Offset.Zero);

            var jd              = newUtc.ToInstant().ToJulianDate() - (coordinate.Longitude / 360.0);
            var raw             = ComputeRaw(jd, settings, coordinate.Latitude, coordinate.Altitude);
            var afterAdjustment = AdjustTime(raw, settings, coordinate.Longitude, timeZone);

            // Calculate midnight.
            var fajr    = afterAdjustment.Fajr;
            var sunrise = afterAdjustment.Sunrise;
            var sunset  = afterAdjustment.Sunset;

            afterAdjustment.Midnight = ComputeMidnightTime(settings.CalculationMethod.MidnightMethod, fajr, sunrise, sunset);

            // Convert.
            var converted = ConvertFromFloatingPointFormat(afterAdjustment, year, month, day, timeZone);

            // Round.
            var rounded = new Prayers(RoundPrayerTime(converted.Imsak),
                                      RoundPrayerTime(converted.Fajr),
                                      RoundPrayerTime(converted.Sunrise),
                                      RoundPrayerTime(converted.Dhuha),
                                      RoundPrayerTime(converted.Zuhr),
                                      RoundPrayerTime(converted.Asr),
                                      RoundPrayerTime(converted.Sunset),
                                      RoundPrayerTime(converted.Maghrib),
                                      RoundPrayerTime(converted.Isha),
                                      RoundPrayerTime(converted.Midnight));

            return(rounded);
        }
Example #6
0
        /// <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);
        }
Example #7
0
 /// <summary>
 ///     Get next prayer time.
 /// </summary>
 /// <param name="settings">
 ///     Settings containing parameters for calculating prayer times.
 /// </param>
 /// <param name="coordinate">
 ///     Location's coordinate.
 /// </param>
 /// <param name="timeZone">
 ///     Location's time zone.
 /// </param>
 /// <param name="clock">
 ///     <see cref="IClock" /> interface object for getting current <see cref="Instant" /> value.
 /// </param>
 /// <returns>
 ///     <see cref="Prayer" /> object containing next prayer time data.
 /// </returns>
 public static Prayer Next(PrayerCalculationSettings settings, Geocoordinate coordinate, double timeZone, IClock clock)
 {
     return(PrayerCalculator.GetNextPrayerTime(clock, settings, coordinate, timeZone));
 }
Example #8
0
 /// <summary>
 ///     Get prayer times for given date.
 /// </summary>
 /// <param name="when">
 ///     <see cref="Instant" /> value which represents the date.
 /// </param>
 /// <param name="settings">
 ///     Settings containing parameters for calculating prayer times.
 /// </param>
 /// <param name="coordinate">
 ///     Location's coordinate.
 /// </param>
 /// <param name="timeZone">
 ///     Location's time zone.
 /// </param>
 /// <returns>
 ///     <see cref="Prayers" /> object containing prayer times for given date.
 /// </returns>
 public static Prayers On(Instant when, PrayerCalculationSettings settings, Geocoordinate coordinate, double timeZone)
 {
     return(PrayerCalculator.GetPrayerTimesForOneDay(when, settings, coordinate, timeZone));
 }
Example #9
0
        /// <summary>
        ///     Get prayer times for today.
        /// </summary>
        /// <param name="settings">
        ///     Settings containing parameters for calculating prayer times.
        /// </param>
        /// <param name="coordinate">
        ///     Location's coordinate.
        /// </param>
        /// <param name="timeZone">
        ///     Location's time zone.
        /// </param>
        /// <param name="clock">
        ///     <see cref="IClock" /> interface object for getting current <see cref="Instant" /> value.
        /// </param>
        /// <returns>
        ///     <see cref="Prayers" /> object containing prayer times for today.
        /// </returns>
        public static Prayers Today(PrayerCalculationSettings settings, Geocoordinate coordinate, double timeZone, IClock clock)
        {
            var now = clock.GetCurrentInstant();

            return(PrayerCalculator.GetPrayerTimesForOneDay(now, settings, coordinate, timeZone));
        }