/// <summary>
        /// Returns the first occurrence of the specified <see cref="System.DayOfWeek"/> after the <see cref="JewishDate"/>.
        /// If the <see cref="JewishDate"/> falls on the specified <see cref="System.DayOfWeek"/> then no days are added.
        /// </summary>
        /// <param name="day">The day of the week to search for</param>
        /// <returns>The <see cref="JewishDate"/> that matches the <paramref name="day"/>, could be the original <see cref="JewishDate"/></returns>
        public JewishDate FindNextDay(DayOfWeek day)
        {
            JewishDate result = this;

            while (result.DayOfWeek != day)
            {
                result = result.Add(new TimeSpan(1, 0, 0, 0));
            }

            return(result);
        }
Exemple #2
0
        public static IList <SpecialDates> GetDayInfo(JewishDate date, bool inIsrael)
        {
            IList <SpecialDates> specialDates = new List <SpecialDates>();

            int year  = date.Year;
            int month = date.Month;
            int day   = date.Day;

            bool isShabbos          = IsShabbos(date);
            bool isYesterdayShabbos = IsYesterdayShabbos(date);
            bool isCheshvanShort    = IsCheshvanShort(year);
            bool isKislevLong       = IsKislevLong(year);
            bool isLeapYear         = IsLeapYear(year);

            if (!isLeapYear && month > 6)
            {
                //This is to keep it in-line with the enum Months. If it is a leap year Nissan = 7, if it isn't it's 6. This lines them up
                month++;
            }


            switch ((Months)month)
            {
            case Months.Tishrei:
                if (day == 1 || day == 2)
                {
                    specialDates.Add(SpecialDates.RoshHashana);
                }
                else if ((day == 3 && !isShabbos) || (day == 4 && isYesterdayShabbos))
                {
                    specialDates.Add(SpecialDates.FastOfGedalia);
                }
                else if (day == 10)
                {
                    specialDates.Add(SpecialDates.YomKippur);
                }
                else if ((day > 14 && day < 22))
                {
                    specialDates.Add(SpecialDates.Sukkos);
                }
                else if (day == 22 && !inIsrael)
                {
                    specialDates.Add(SpecialDates.ShminiAtzeres);
                }
                else if ((day == 22 && inIsrael) || (day == 23 && !inIsrael))
                {
                    specialDates.Add(SpecialDates.SimchasTorah);
                }
                break;

            case Months.Cheshvan:
                break;

            case Months.Kislev:
                if (day > 24)
                {
                    specialDates.Add(SpecialDates.Chanukah);
                }
                break;

            case Months.Teves:
                if (day < 3 || (day == 3 && !isKislevLong))
                {
                    specialDates.Add(SpecialDates.Chanukah);
                }
                else if (day == 10)
                {
                    specialDates.Add(SpecialDates.TenthOfTeves);
                }
                break;

            case Months.Shvat:
                if (day == 15)
                {
                    specialDates.Add(SpecialDates.TuBishvat);
                }
                break;

            case Months.AdarI:
                if (!isLeapYear)
                {
                    if ((day == 11 && IsShabbos(date.Add(new TimeSpan(2, 0, 0, 0)))) || (day == 13 && !isShabbos))
                    {
                        specialDates.Add(SpecialDates.FastOfEsther);
                    }
                    else if (day == 14)
                    {
                        specialDates.Add(SpecialDates.Purim);
                    }
                    else if (day == 15)
                    {
                        specialDates.Add(SpecialDates.ShushanPurim);
                    }
                }
                else
                {
                    if (day == 14)
                    {
                        specialDates.Add(SpecialDates.PurimKatan);
                    }
                }
                break;

            case Months.AdarII:
                if ((day == 11 && IsShabbos(date.Add(new TimeSpan(2, 0, 0, 0)))) || (day == 13 && !isShabbos))
                {
                    specialDates.Add(SpecialDates.FastOfEsther);
                }
                else if (day == 14)
                {
                    specialDates.Add(SpecialDates.Purim);
                }
                else if (day == 15)
                {
                    specialDates.Add(SpecialDates.ShushanPurim);
                }
                break;

            case Months.Nissan:
                if ((day == 14 && !isShabbos) || (day == 12 && IsShabbos(date.Add(new TimeSpan(2, 0, 0, 0)))))
                {
                    specialDates.Add(SpecialDates.FastOfTheFirstborn);
                }
                else if ((day > 14 && day < 22) || (day == 22 && !inIsrael))
                {
                    specialDates.Add(SpecialDates.Pesach);
                }
                break;

            case Months.Iyar:
                if (day == 14)
                {
                    specialDates.Add(SpecialDates.PesachSheni);
                }
                else if (day == 18)
                {
                    specialDates.Add(SpecialDates.LagBaomer);
                }
                break;

            case Months.Sivan:
                if (day == 6 || (day == 7 && !inIsrael))
                {
                    specialDates.Add(SpecialDates.Shovuos);
                }
                break;

            case Months.Tamuz:
                if ((day == 17 && !isShabbos) || (day == 18 && isYesterdayShabbos))
                {
                    specialDates.Add(SpecialDates.SeventeenthOfTamuz);
                }
                break;

            case Months.Av:
                if ((day == 9 && !isShabbos) || (day == 10 && isYesterdayShabbos))
                {
                    specialDates.Add(SpecialDates.NinthOfAv);
                }
                else if (day == 15)
                {
                    specialDates.Add(SpecialDates.TuBeAv);
                }
                break;

            case Months.Elul:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(month), month, null);
            }

            //Check if Rosh Chodesh
            if (IsRoshChodesh(date))
            {
                specialDates.Add(SpecialDates.RoshChodesh);
            }

            return(specialDates);
        }