Exemple #1
0
    private static bool isBetween(DateTime now, DateComponents startDateComponents, DateComponents endDateComponents)
    {
        DateTime startDate = toDateTime(startDateComponents).Date;
        DateTime endDate   = toDateTime(endDateComponents).Date;

        return(now.Date >= startDate && now.Date <= endDate);
    }
Exemple #2
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));
            }
        }
    public static int RegisterNotification(int id, DateTime fireDate, string body)
    {
        if (fireDate < UnbiasedTime.Instance.Now())              // fire date is in past
        {
            return(-1);
        }

        // notifications are disabled
        if (PreferencesFactory.GetInt(Constants.KeyNotificationsAllowed, 1) == 0)
        {
            return(-1);
        }

#if UNITY_IPHONE
        NotificationCenter.RequestPermissions((result) =>
        {
            PreferencesFactory.SetInt(Constants.KeyNotificationsAllowed, result.IsSucceeded ? 1 : 0);

            //Debug.Log("RequestPermissions callback: err: " + (result.HasError ? result.Error.Message : null) + "; success: " + result.IsSucceeded + "; failed: " + result.IsFailed);
        });

        var content = new NotificationContent();
        content.Body  = body;
        content.Badge = 1;

        var dateComponents = new DateComponents()
        {
            Year   = fireDate.Year,
            Month  = fireDate.Month,
            Day    = fireDate.Day,
            Hour   = fireDate.Hour,
            Minute = fireDate.Minute,
            Second = fireDate.Second
        };

        var trigger = new CalendarTrigger(dateComponents);
        var request = new NotificationRequest(id.ToString(), content, trigger);

        NotificationCenter.AddNotificationRequest(request, (result) => {
            //Debug.Log("AddNotificationRequest callback: err: " + (result.HasError ? result.Error.Message : null) + "; success: " + result.IsSucceeded + "; failed: " + result.IsFailed);
        });
                #endif

                #if UNITY_ANDROID
        TimeSpan delay = fireDate - UnbiasedTime.Instance.Now();
        AndroidNotificationBuilder builder = new AndroidNotificationBuilder(id,
                                                                            GameManager.Instance.GameName,
                                                                            body,
                                                                            (int)delay.TotalSeconds);

        AndroidNotificationManager.Instance.ScheduleLocalNotification(builder);
                #endif

        return(id);
    }
Exemple #4
0
    public static void Run(out bool match, out string about, DateTime now, string startDate = "1/1", string endDate = "12/31")
    {
        int currentYear = now.Year;

        try{
            DateComponents startDateComponents = parseDate(startDate);
            DateComponents endDateComponents   = parseDate(endDate);

            if (startDateComponents.year == null ^ endDateComponents.year == null)
            {
                throw new Exception("Start & end date styles must match (MM/DD or MM/DD/YY)");
            }

            // If only the month & day are defined, set the start year to the current year
            if (startDateComponents.year == null)
            {
                startDateComponents.year = currentYear;

                if (endDateComponents.month < startDateComponents.month && now.Month < startDateComponents.month)
                {
                    startDateComponents.year = currentYear - 1;
                }
            }

            // If only the month & day are defined and the end date is before the start date
            if (endDateComponents.year == null)
            {
                endDateComponents.year = currentYear;
                if (endDateComponents.month < startDateComponents.month)
                {
                    endDateComponents.year = startDateComponents.year + 1;
                }

                if (endDateComponents.month == startDateComponents.month &&
                    endDateComponents.day < startDateComponents.day)
                {
                    endDateComponents.year = startDateComponents.year + 1;
                }
            }

            match = isBetween(now, startDateComponents, endDateComponents);

            about  = now.ToString("Now: MM/dd/yy");
            about += "\nMatch: " + match.ToString();
            about += "\n\n--- Caluclated Range ---";
            about += "\n  Start: " + formatDateComponents(startDateComponents);
            about += "\n  End: " + formatDateComponents(endDateComponents);
        }
        catch (Exception e) {
            about  = "INVALID CONFIGURATION: \n\n" + e.Message;
            about += "\n\n" + "Valid date formats are MM/DD or MM/DD/YY";
            match  = false;
        }
    }
        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");
        }
        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");
        }
        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));
        }
Exemple #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));
        }
        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);
        }
        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");
        }
        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");
        }
Exemple #12
0
 private static string formatDateComponents(DateComponents date)
 {
     return(string.Format("{0}/{1}/{2}", date.month.ToString(), date.day.ToString(), date.year == null ? "**" : date.year.ToString()));
 }
Exemple #13
0
 private static DateTime toDateTime(DateComponents date)
 {
     return(new DateTime((int)date.year, (int)date.month, (int)date.day));
 }
Exemple #14
0
 /// <summary>
 /// Constructs an object by accepting DateComponents object
 /// </summary>
 /// <param name="DateComponents">DateComponents object</param>
 public Date(DateComponents DateComponents)
 {
     this.DateComponents     = DateComponents;
     DateComponentsAsStrings = new DateComponentsAsStrings(DateComponents);
 }
Exemple #15
0
 /// <summary>
 /// Calculate PrayerTimes
 /// </summary>
 /// <param name="coordinates">the coordinates of the location</param>
 /// <param name="date">the date components for that location</param>
 /// <param name="params">he parameters for the calculation</param>
 public PrayerTimes(Coordinates coordinates, DateComponents date, CalculationParameters parameters)
     : this(coordinates, CalendarUtil.ResolveTime(date), parameters)
 {
 }