Exemplo n.º 1
0
        private void TestTimingFile(string file)
        {
            TimingFile timingFile = TimingFile.Load(file);

            Assert.IsNotNull(timingFile);

            Coordinates           coordinates = new Coordinates(timingFile.Parameters.Latitude, timingFile.Parameters.Longitude);
            CalculationParameters parameters  = ParseParameters(timingFile.Parameters);

            foreach (TimingInfo info in timingFile.Times)
            {
                DateComponents dateComponents = TestUtils.GetDateComponents(info.Date);
                PrayerTimes    prayerTimes    = new PrayerTimes(coordinates, dateComponents, parameters);

                long fajrDifference = GetDifferenceInMinutes(prayerTimes.Fajr, info.Date, info.Fajr, timingFile.Parameters.Timezone);
                Assert.IsTrue(fajrDifference.IsAtMost(timingFile.Variance));

                long sunriseDifference = GetDifferenceInMinutes(prayerTimes.Sunrise, info.Date, info.Sunrise, timingFile.Parameters.Timezone);
                Assert.IsTrue(sunriseDifference.IsAtMost(timingFile.Variance));

                long dhuhrDifference = GetDifferenceInMinutes(prayerTimes.Dhuhr, info.Date, info.Dhuhr, timingFile.Parameters.Timezone);
                Assert.IsTrue(dhuhrDifference.IsAtMost(timingFile.Variance));

                long asrDifference = GetDifferenceInMinutes(prayerTimes.Asr, info.Date, info.Asr, timingFile.Parameters.Timezone);
                Assert.IsTrue(asrDifference.IsAtMost(timingFile.Variance));

                long maghribDifference = GetDifferenceInMinutes(prayerTimes.Maghrib, info.Date, info.Maghrib, timingFile.Parameters.Timezone);
                Assert.IsTrue(maghribDifference.IsAtMost(timingFile.Variance));

                long ishaDifference = GetDifferenceInMinutes(prayerTimes.Isha, info.Date, info.Isha, timingFile.Parameters.Timezone);
                Assert.IsTrue(ishaDifference.IsAtMost(timingFile.Variance));
            }
        }
Exemplo n.º 2
0
        private static async Task <PrayerTimes> GetPrayerTimesWithSchool(RequestForPrayerTimesInCityAndSchool request, HttpClient client)
        {
            var response = await client.GetStringAsync($"https://api.pray.zone/v2/times/today.json?city={request.City}&school={request.School}");

            var prayerTimes = PrayerTimes.FromJson(response);

            return(prayerTimes);
        }
Exemplo n.º 3
0
        private void DaysSinceSolsticeTest(int value, int year, int month, int day, double latitude)
        {
            // For Northern Hemisphere start from December 21
            // (DYY=0 for December 21, and counting forward, DYY=11 for January 1 and so on).
            // For Southern Hemisphere start from June 21
            // (DYY=0 for June 21, and counting forward)
            DateTime date      = TestUtils.MakeDate(year, month, day);
            int      dayOfYear = TestUtils.GetDayOfYear(date);

            Assert.IsTrue(PrayerTimes.DaysSinceSolstice(dayOfYear, date.Year, latitude) == value);
        }
Exemplo n.º 4
0
        public void MoonsightingMethod()
        {
            TimeZoneInfo timezone = TestUtils.GetTimeZone("America/New_York");

            DateComponents date        = new DateComponents(2016, 1, 31);
            Coordinates    coordinates = new Coordinates(35.7750, -78.6336);
            PrayerTimes    prayerTimes = new PrayerTimes(
                coordinates, date, CalculationMethod.MOON_SIGHTING_COMMITTEE.GetParameters());

            Assert.IsTrue(GetHour(prayerTimes.Fajr, timezone) == "05:48 AM");
            Assert.IsTrue(GetHour(prayerTimes.Sunrise, timezone) == "07:16 AM");
            Assert.IsTrue(GetHour(prayerTimes.Dhuhr, timezone) == "12:33 PM");
            Assert.IsTrue(GetHour(prayerTimes.Asr, timezone) == "03:20 PM");
            Assert.IsTrue(GetHour(prayerTimes.Maghrib, timezone) == "05:43 PM");
            Assert.IsTrue(GetHour(prayerTimes.Isha, timezone) == "07:05 PM");
        }
Exemplo n.º 5
0
        public override async Task <ResponseForPrayerTimesInCityAndSchool> GetPrayerTimesByCityAndSchool(RequestForPrayerTimesInCityAndSchool request, ServerCallContext context)
        {
            var         client      = httpClientFactory.CreateClient();
            PrayerTimes prayerTimes = await GetPrayerTimesWithSchool(request, client);

            return(new ResponseForPrayerTimesInCityAndSchool
            {
                Asr = prayerTimes.Results.Datetime[0].Times.Asr,
                Dhuhr = prayerTimes.Results.Datetime[0].Times.Dhuhr,
                Fajr = prayerTimes.Results.Datetime[0].Times.Fajr,
                Isha = prayerTimes.Results.Datetime[0].Times.Isha,
                Maghrib = prayerTimes.Results.Datetime[0].Times.Maghrib,
                TimeStamp = Timestamp.FromDateTime(DateTime.UtcNow),
                City = request.City,
                School = request.School
            });
        }
Exemplo n.º 6
0
        public void PrayerTimesAmericaNewYork()
        {
            TimeZoneInfo timezone = TestUtils.GetTimeZone("America/New_York");

            DateComponents        date       = new DateComponents(2015, 7, 12);
            CalculationParameters calcParams = CalculationMethod.NORTH_AMERICA.GetParameters();

            calcParams.Madhab = Madhab.HANAFI;

            Coordinates coordinates = new Coordinates(35.7750, -78.6336);
            PrayerTimes prayerTimes = new PrayerTimes(coordinates, date, calcParams);

            Assert.IsTrue(GetHour(prayerTimes.Fajr, timezone) == "04:42 AM");
            Assert.IsTrue(GetHour(prayerTimes.Sunrise, timezone) == "06:08 AM");
            Assert.IsTrue(GetHour(prayerTimes.Dhuhr, timezone) == "01:21 PM");
            Assert.IsTrue(GetHour(prayerTimes.Asr, timezone) == "06:22 PM");
            Assert.IsTrue(GetHour(prayerTimes.Maghrib, timezone) == "08:32 PM");
            Assert.IsTrue(GetHour(prayerTimes.Isha, timezone) == "09:57 PM");
        }
Exemplo n.º 7
0
        public void TimeForPrayer()
        {
            DateComponents        components = new DateComponents(2016, 7, 1);
            CalculationParameters parameters = CalculationMethod.MUSLIM_WORLD_LEAGUE.GetParameters();

            parameters.Madhab           = Madhab.HANAFI;
            parameters.HighLatitudeRule = HighLatitudeRule.TWILIGHT_ANGLE;
            Coordinates coordinates = new Coordinates(59.9094, 10.7349);

            PrayerTimes p = new PrayerTimes(coordinates, components, parameters);

            Assert.IsTrue(p.Fajr == p.TimeForPrayer(Prayer.FAJR));
            Assert.IsTrue(p.Sunrise == p.TimeForPrayer(Prayer.SUNRISE));
            Assert.IsTrue(p.Dhuhr == p.TimeForPrayer(Prayer.DHUHR));
            Assert.IsTrue(p.Asr == p.TimeForPrayer(Prayer.ASR));
            Assert.IsTrue(p.Maghrib == p.TimeForPrayer(Prayer.MAGHRIB));
            Assert.IsTrue(p.Isha == p.TimeForPrayer(Prayer.ISHA));
            Assert.IsNull(p.TimeForPrayer(Prayer.NONE));
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Coordinates           coordinates    = new Coordinates(43.61, -79.70);
            DateComponents        dateComponents = DateComponents.From(DateTime.Now);
            CalculationParameters parameters     = CalculationMethod.NORTH_AMERICA.GetParameters();

            string timeZone = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                              "Eastern Standard Time" : "America/New_York";

            TimeZoneInfo easternTime = TimeZoneInfo.FindSystemTimeZoneById(timeZone);

            PrayerTimes prayerTimes = new PrayerTimes(coordinates, dateComponents, parameters);

            Console.WriteLine("Fajr   : " + TimeZoneInfo.ConvertTimeFromUtc(prayerTimes.Fajr, easternTime));
            Console.WriteLine("Sunrise: " + TimeZoneInfo.ConvertTimeFromUtc(prayerTimes.Sunrise, easternTime));
            Console.WriteLine("Dhuhr  : " + TimeZoneInfo.ConvertTimeFromUtc(prayerTimes.Dhuhr, easternTime));
            Console.WriteLine("Asr    : " + TimeZoneInfo.ConvertTimeFromUtc(prayerTimes.Asr, easternTime));
            Console.WriteLine("Maghrib: " + TimeZoneInfo.ConvertTimeFromUtc(prayerTimes.Maghrib, easternTime));
            Console.WriteLine("Isha   : " + TimeZoneInfo.ConvertTimeFromUtc(prayerTimes.Isha, easternTime));
        }
Exemplo n.º 9
0
        public void NextPrayer()
        {
            DateComponents        components = new DateComponents(2015, 9, 1);
            CalculationParameters parameters = CalculationMethod.KARACHI.GetParameters();

            parameters.Madhab           = Madhab.HANAFI;
            parameters.HighLatitudeRule = HighLatitudeRule.TWILIGHT_ANGLE;
            Coordinates coordinates = new Coordinates(33.720817, 73.090032);

            PrayerTimes p = new PrayerTimes(coordinates, components, parameters);

            Assert.IsTrue(p.NextPrayer(TestUtils.AddSeconds(p.Fajr, -1)) == Prayer.FAJR);
            Assert.IsTrue(p.NextPrayer(p.Fajr) == Prayer.SUNRISE);
            Assert.IsTrue(p.NextPrayer(TestUtils.AddSeconds(p.Fajr, 1)) == Prayer.SUNRISE);
            Assert.IsTrue(p.NextPrayer(TestUtils.AddSeconds(p.Sunrise, 1)) == Prayer.DHUHR);
            Assert.IsTrue(p.NextPrayer(TestUtils.AddSeconds(p.Dhuhr, 1)) == Prayer.ASR);
            Assert.IsTrue(p.NextPrayer(TestUtils.AddSeconds(p.Asr, 1)) == Prayer.MAGHRIB);
            Assert.IsTrue(p.NextPrayer(TestUtils.AddSeconds(p.Maghrib, 1)) == Prayer.ISHA);
            Assert.IsTrue(p.NextPrayer(TestUtils.AddSeconds(p.Isha, 1)) == Prayer.NONE);
        }
Exemplo n.º 10
0
        public void MoonsightingMethodHighLat()
        {
            TimeZoneInfo timezone = TestUtils.GetTimeZone("Europe/Oslo");

            // Values from http://www.moonsighting.com/pray.php
            DateComponents        date       = new DateComponents(2016, 1, 1);
            CalculationParameters parameters = CalculationMethod.MOON_SIGHTING_COMMITTEE.GetParameters();

            parameters.Madhab = Madhab.HANAFI;
            Coordinates coordinates = new Coordinates(59.9094, 10.7349);

            PrayerTimes prayerTimes = new PrayerTimes(coordinates, date, parameters);

            Assert.IsTrue(GetHour(prayerTimes.Fajr, timezone) == "07:34 AM");
            Assert.IsTrue(GetHour(prayerTimes.Sunrise, timezone) == "09:19 AM");
            Assert.IsTrue(GetHour(prayerTimes.Dhuhr, timezone) == "12:25 PM");
            Assert.IsTrue(GetHour(prayerTimes.Asr, timezone) == "01:36 PM");
            Assert.IsTrue(GetHour(prayerTimes.Maghrib, timezone) == "03:25 PM");
            Assert.IsTrue(GetHour(prayerTimes.Isha, timezone) == "05:02 PM");
        }
Exemplo n.º 11
0
        public void OffsetTests()
        {
            TimeZoneInfo timezone = TestUtils.GetTimeZone("America/New_York");

            DateComponents        date        = new DateComponents(2015, 12, 1);
            Coordinates           coordinates = new Coordinates(35.7750, -78.6336);
            CalculationParameters parameters  = CalculationMethod.MUSLIM_WORLD_LEAGUE.GetParameters();

            PrayerTimes prayerTimes = new PrayerTimes(coordinates, date, parameters);

            Assert.IsTrue(GetHour(prayerTimes.Fajr, timezone) == "05:35 AM");
            Assert.IsTrue(GetHour(prayerTimes.Sunrise, timezone) == "07:06 AM");
            Assert.IsTrue(GetHour(prayerTimes.Dhuhr, timezone) == "12:05 PM");
            Assert.IsTrue(GetHour(prayerTimes.Asr, timezone) == "02:42 PM");
            Assert.IsTrue(GetHour(prayerTimes.Maghrib, timezone) == "05:01 PM");
            Assert.IsTrue(GetHour(prayerTimes.Isha, timezone) == "06:26 PM");

            parameters.Adjustments.Fajr    = 10;
            parameters.Adjustments.Sunrise = 10;
            parameters.Adjustments.Dhuhr   = 10;
            parameters.Adjustments.Asr     = 10;
            parameters.Adjustments.Maghrib = 10;
            parameters.Adjustments.Isha    = 10;

            prayerTimes = new PrayerTimes(coordinates, date, parameters);
            Assert.IsTrue(GetHour(prayerTimes.Fajr, timezone) == "05:45 AM");
            Assert.IsTrue(GetHour(prayerTimes.Sunrise, timezone) == "07:16 AM");
            Assert.IsTrue(GetHour(prayerTimes.Dhuhr, timezone) == "12:15 PM");
            Assert.IsTrue(GetHour(prayerTimes.Asr, timezone) == "02:52 PM");
            Assert.IsTrue(GetHour(prayerTimes.Maghrib, timezone) == "05:11 PM");
            Assert.IsTrue(GetHour(prayerTimes.Isha, timezone) == "06:36 PM");

            parameters.Adjustments = new PrayerAdjustments();
            prayerTimes            = new PrayerTimes(coordinates, date, parameters);
            Assert.IsTrue(GetHour(prayerTimes.Fajr, timezone) == "05:35 AM");
            Assert.IsTrue(GetHour(prayerTimes.Sunrise, timezone) == "07:06 AM");
            Assert.IsTrue(GetHour(prayerTimes.Dhuhr, timezone) == "12:05 PM");
            Assert.IsTrue(GetHour(prayerTimes.Asr, timezone) == "02:42 PM");
            Assert.IsTrue(GetHour(prayerTimes.Maghrib, timezone) == "05:01 PM");
            Assert.IsTrue(GetHour(prayerTimes.Isha, timezone) == "06:26 PM");
        }
Exemplo n.º 12
0
        public static PrayerTimes GetPrayerTimes(SchoolsofThought Madhab, PrayerCalculationMethod Calc_Method, DateTime doDate, double longitude, double latitude, double timezone, bool doDayLightSavings)
        {
            PrayerTimes prayerTimes = new PrayerTimes();
            AstroValues astroValues = new AstroValues();
            int         myday       = doDate.Day;
            int         mymonth     = doDate.Month;
            int         myyear      = doDate.Year;

            double mj;
            double diffMin;

            DateTime curDate;

            //
            // main loop. All the work is done in the functions with the double names
            // find_sun_and_twi_events_for_date() and find_moonrise_set()
            //
            mj = JulianDay(myday, mymonth, myyear, 0);

            double imsaakAngle;
            double fajrAngle;
            double IshaAngle;

            if (Calc_Method == PrayerCalculationMethod.Karachi)
            {
                imsaakAngle = -18; fajrAngle = -18.0; IshaAngle = -18.0;
            }
            else if (Calc_Method == PrayerCalculationMethod.ISNA)
            {
                imsaakAngle = -18; fajrAngle = -15.0; IshaAngle = -15.0;
            }
            else if (Calc_Method == PrayerCalculationMethod.MuslimWorldLeague)
            {
                imsaakAngle = -18; fajrAngle = -18.0; IshaAngle = -17.0;
            }
            else if (Calc_Method == PrayerCalculationMethod.Egypt)
            {
                imsaakAngle = -19.5; fajrAngle = -19.5; IshaAngle = -17.5;
            }
            else
            {
                imsaakAngle = -18; fajrAngle = -16.0; IshaAngle = -15.0;
            }

            // Start Loop here if you want to go through dates
            astroCalcs.find_sun_and_twi_events_for_date(mj, timezone, longitude, latitude, imsaakAngle, fajrAngle, IshaAngle, astroValues);

            diffMin = Math.Abs((astroValues.sunset_end - astroValues.sunset_begin).TotalMinutes);

            curDate = new DateTime(myyear, mymonth, myday);

            getAsr getAsr = new getAsr();

            prayerTimes.Fajr    = astroValues.astro_begin;
            prayerTimes.SunRise = astroValues.sunset_begin;
            prayerTimes.Dhuhr   = astroValues.sunset_begin.AddMinutes(diffMin / 2); //  DateAdd("n", diffMin / 2, (DateTime)sunset_begin);;
            prayerTimes.Isha    = astroValues.astro_end;

            prayerTimes.SalatUlLayl = prayerTimes.Dhuhr.AddHours(12);   // add 12 hours to zhuhr;

            if (Madhab == SchoolsofThought.Hanafi)
            {
                prayerTimes.Imsaak  = astroValues.imsaak_begin;
                prayerTimes.Asr     = getAsr.CalculateAsr(longitude, latitude, timezone, curDate, prayerTimes.Dhuhr, 2);
                prayerTimes.Sunset  = null;
                prayerTimes.Maghrib = astroValues.sunset_end;
            }
            else if (Madhab == SchoolsofThought.Shaffii)
            {
                prayerTimes.Imsaak  = astroValues.imsaak_begin;
                prayerTimes.Asr     = getAsr.CalculateAsr(longitude, latitude, timezone, curDate, prayerTimes.Dhuhr, 1);
                prayerTimes.Sunset  = null;
                prayerTimes.Maghrib = astroValues.sunset_end;
            }
            else
            {
                prayerTimes.Imsaak  = astroValues.imsaak_begin;
                prayerTimes.Asr     = getAsr.CalculateAsr(longitude, latitude, timezone, curDate, prayerTimes.Dhuhr, 1);
                prayerTimes.Sunset  = astroValues.sunset_end;
                prayerTimes.Maghrib = astroValues.civil_end;

                //prayerTimes.Midnight = DateAdd(DateInterval.Minute, (DateDiff(DateInterval.Minute, (DateTime)Today + " " + sunset_end, (DateTime)Today.AddDays(1) + " " + astro_begin) / 2), sunset_end);

                prayerTimes.Midnight = astroValues.sunset_end.AddMinutes((astroValues.astro_begin.AddDays(1) - astroValues.sunset_end).TotalMinutes / 2);
            }
            getAsr = null /* TODO Change to default(_) if this is not a reference type */;

            prayerTimes.Fajr  = Convert.ToDateTime(prayerTimes.Fajr); // .AddMinutes(1)
            prayerTimes.Dhuhr = Convert.ToDateTime(prayerTimes.Dhuhr).AddMinutes(1);
            prayerTimes.Isha  = Convert.ToDateTime(prayerTimes.Isha); // .AddMinutes(1)

            switch (Calc_Method)
            {
            case PrayerCalculationMethod.LevaInstitute:
            case PrayerCalculationMethod.ISNA:
            {
                prayerTimes.Imsaak = astroValues.imsaak_begin;
                break;
            }

            case PrayerCalculationMethod.Karachi:
            case PrayerCalculationMethod.MuslimWorldLeague:
            case PrayerCalculationMethod.Saudi:
            case PrayerCalculationMethod.Egypt:
            {
                prayerTimes.Imsaak = astroValues.astro_begin.AddMinutes(-10);
                break;
            }
            }

            // Apply Daylight Savings time if necessary
            if (doDayLightSavings)
            {
                // DAY LIGHT SAVINGS TIME PART
                bool do_DST; // Do Day Light savings or not

                daylightSavings.GetDayLightSavings(myyear, out DateTime beginDST, out DateTime endDST);

                do_DST = daylightSavings.isDST(beginDST, endDST, mymonth, myday);

                if (do_DST == true)
                {
                    prayerTimes.Imsaak  = prayerTimes.Imsaak.AddHours(1);
                    prayerTimes.Fajr    = prayerTimes.Fajr.AddHours(1);
                    prayerTimes.SunRise = prayerTimes.SunRise.AddHours(1);
                    prayerTimes.Dhuhr   = prayerTimes.Dhuhr.AddHours(1);
                    prayerTimes.Asr     = prayerTimes.Asr.AddHours(1);
                    if (prayerTimes.Sunset.HasValue)
                    {
                        prayerTimes.Sunset = prayerTimes.Sunset.Value.AddHours(1);
                    }
                    prayerTimes.Maghrib     = prayerTimes.Maghrib.AddHours(1);
                    prayerTimes.Isha        = prayerTimes.Isha.AddHours(1);
                    prayerTimes.Midnight    = prayerTimes.Midnight.AddHours(1);
                    prayerTimes.SalatUlLayl = prayerTimes.SalatUlLayl.AddHours(1);
                }
            }

            return(prayerTimes);
        } // end of main program