Exemplo n.º 1
0
        int GetDayOfOmer(JewishMonth jewishMonth, int dayOfMonth)
        {
            int omer = -1; // not a day of the Omer

            // if Nissan and second day of Pesach and on
            if (jewishMonth == JewishMonth.NISSAN && dayOfMonth >= 16)
            {
                omer = dayOfMonth - 15;
                // if Iyar
            }
            else if (jewishMonth == JewishMonth.IYAR)
            {
                omer = dayOfMonth + 15;
                // if Sivan and before Shavuos
            }
            else if (jewishMonth == JewishMonth.SIVAN && dayOfMonth < 6)
            {
                omer = dayOfMonth + 44;
            }

            return(omer);
        }
Exemplo n.º 2
0
        JewishHoliday GetJewishHoliday(int dayOfMonth, int dayOfWeek, int year,
                                       bool inIsrael, bool useModernHolidays, JewishMonth hebrewMonth,
                                       bool isAdar29Days)
        {
            switch (hebrewMonth)
            {
            case JewishMonth.NISSAN:
                if (dayOfMonth == 14)
                {
                    return(JewishHoliday.EREV_PESACH);
                }
                else if (dayOfMonth == 15 || dayOfMonth == 21 ||
                         (!inIsrael && (dayOfMonth == 16 || dayOfMonth == 22)))
                {
                    return(JewishHoliday.PESACH);
                }
                else if (dayOfMonth >= 17 && dayOfMonth <= 20 ||
                         (dayOfMonth == 16 && inIsrael))
                {
                    return(JewishHoliday.CHOL_HAMOED_PESACH);
                }

                if (useModernHolidays &&
                    ((dayOfMonth == 26 && dayOfWeek == 5) ||
                     (dayOfMonth == 28 && dayOfWeek == 2) ||
                     (dayOfMonth == 27 && dayOfWeek != 1 && dayOfWeek != 6)))
                {
                    return(JewishHoliday.YOM_HASHOAH);
                }

                break;

            case JewishMonth.IYAR:
                if (useModernHolidays &&
                    ((dayOfMonth == 4 && dayOfWeek == 3) ||
                     ((dayOfMonth == 3 || dayOfMonth == 2) && dayOfWeek == 4) || (dayOfMonth == 5 && dayOfWeek == 2)))
                {
                    return(JewishHoliday.YOM_HAZIKARON);
                }

                // if 5 Iyar falls on Wed Yom Haatzmaut is that day. If it fal1s on Friday or Shabbos it is moved back to
                // Thursday. If it falls on Monday it is moved to Tuesday
                if (useModernHolidays &&
                    ((dayOfMonth == 5 && dayOfWeek == 4) ||
                     ((dayOfMonth == 4 || dayOfMonth == 3) && dayOfWeek == 5) || (dayOfMonth == 6 && dayOfWeek == 3)))
                {
                    return(JewishHoliday.YOM_HAATZMAUT);
                }

                if (dayOfMonth == 14)
                {
                    return(JewishHoliday.PESACH_SHENI);
                }

                if (useModernHolidays && dayOfMonth == 28)
                {
                    return(JewishHoliday.YOM_YERUSHALAYIM);
                }

                break;

            case JewishMonth.SIVAN:
                if (dayOfMonth == 5)
                {
                    return(JewishHoliday.EREV_SHAVUOS);
                }
                else if (dayOfMonth == 6 || (dayOfMonth == 7 && !inIsrael))
                {
                    return(JewishHoliday.SHAVUOS);
                }

                break;

            case JewishMonth.TAMMUZ:
                // push off the fast day if it falls on Shabbos
                if ((dayOfMonth == 17 && dayOfWeek != 7) ||
                    (dayOfMonth == 18 && dayOfWeek == 1))
                {
                    return(JewishHoliday.SEVENTEEN_OF_TAMMUZ);
                }

                break;

            case JewishMonth.AV:
                // if Tisha B'av falls on Shabbos, push off until Sunday
                if ((dayOfWeek == 1 && dayOfMonth == 10) ||
                    (dayOfWeek != 7 && dayOfMonth == 9))
                {
                    return(JewishHoliday.TISHA_BEAV);
                }
                else if (dayOfMonth == 15)
                {
                    return(JewishHoliday.TU_BEAV);
                }

                break;

            case JewishMonth.ELUL:
                if (dayOfMonth == 29)
                {
                    return(JewishHoliday.EREV_ROSH_HASHANA);
                }

                break;

            case JewishMonth.TISHREI:
                if (dayOfMonth == 1 || dayOfMonth == 2)
                {
                    return(JewishHoliday.ROSH_HASHANA);
                }
                else if ((dayOfMonth == 3 && dayOfWeek != 7) ||
                         (dayOfMonth == 4 && dayOfWeek == 1))
                {
                    // push off Tzom Gedalia if it falls on Shabbos
                    return(JewishHoliday.FAST_OF_GEDALYAH);
                }
                else if (dayOfMonth == 9)
                {
                    return(JewishHoliday.EREV_YOM_KIPPUR);
                }
                else if (dayOfMonth == 10)
                {
                    return(JewishHoliday.YOM_KIPPUR);
                }
                else if (dayOfMonth == 14)
                {
                    return(JewishHoliday.EREV_SUCCOS);
                }

                if (dayOfMonth == 15 || (dayOfMonth == 16 && !inIsrael))
                {
                    return(JewishHoliday.SUCCOS);
                }

                if (dayOfMonth >= 17 && dayOfMonth <= 20 || (dayOfMonth == 16 && inIsrael))
                {
                    return(JewishHoliday.CHOL_HAMOED_SUCCOS);
                }

                if (dayOfMonth == 21)
                {
                    return(JewishHoliday.HOSHANA_RABBA);
                }

                if (dayOfMonth == 22)
                {
                    //theoretically this could be simchat torah if in Israel, but shemini atzeret is really the yom tov
                    return(JewishHoliday.SHEMINI_ATZERES);
                }

                if (dayOfMonth == 23 && !inIsrael)
                {
                    return(JewishHoliday.SIMCHAS_TORAH);
                }

                break;

            case JewishMonth.KISLEV:     // no yomtov in CHESHVAN
                // if (dayOfMonth == 24) {
                // return EREV_CHANUKAH;
                // } else
                if (dayOfMonth >= 25)
                {
                    return(JewishHoliday.CHANUKAH);
                }

                break;

            case JewishMonth.TEVES:
                if (dayOfMonth == 1 || dayOfMonth == 2 ||
                    (dayOfMonth == 3 && isAdar29Days))
                {
                    return(JewishHoliday.CHANUKAH);
                }
                else if (dayOfMonth == 10)
                {
                    return(JewishHoliday.TENTH_OF_TEVES);
                }

                break;

            case JewishMonth.SHEVAT:
                if (dayOfMonth == 15)
                {
                    return(JewishHoliday.TU_BESHVAT);
                }

                break;

            case JewishMonth.ADAR:
                if (!IsLeapYear(year))
                {
                    // if 13th Adar falls on Friday or Shabbos, push back to Thursday
                    if (((dayOfMonth == 11 || dayOfMonth == 12) && dayOfWeek == 5) ||
                        (dayOfMonth == 13 && !(dayOfWeek == 6 || dayOfWeek == 7)))
                    {
                        return(JewishHoliday.FAST_OF_ESTHER);
                    }

                    if (dayOfMonth == 14)
                    {
                        return(JewishHoliday.PURIM);
                    }
                    else if (dayOfMonth == 15 && inIsrael)
                    {
                        return(JewishHoliday.SHUSHAN_PURIM);
                    }
                }
                else
                {
                    // else if a leap year
                    if (dayOfMonth == 14)
                    {
                        return(JewishHoliday.PURIM_KATAN);
                    }
                }

                break;

            case JewishMonth.ADAR_II:
                // if 13th Adar falls on Friday or Shabbos, push back to Thursday
                if (((dayOfMonth == 11 || dayOfMonth == 12) && dayOfWeek == 5) ||
                    (dayOfMonth == 13 && !(dayOfWeek == 6 || dayOfWeek == 7)))
                {
                    return(JewishHoliday.FAST_OF_ESTHER);
                }

                if (dayOfMonth == 14)
                {
                    return(JewishHoliday.PURIM);
                }
                else if (dayOfMonth == 15 && inIsrael)
                {
                    return(JewishHoliday.SHUSHAN_PURIM);
                }

                break;
            }

            // if we get to this stage, then there are no holidays for the given date return -1
            return(JewishHoliday.NONE);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Jewishs the month to native month.
        /// see https://msdn.microsoft.com/en-us/library/system.globalization.hebrewcalendar(v=vs.110).aspx
        /// </summary>
        /// <returns>The month to native month.</returns>
        /// <param name="jewishMonth">Jewish month.</param>
        /// <param name="leapYear">If set to <c>true</c> leap year.</param>
        public int JewishMonthToNativeMonth(JewishMonth jewishMonth, bool leapYear)
        {
            switch (jewishMonth)
            {
            case JewishMonth.TISHREI:
                return(1);

            case JewishMonth.CHESHVAN:
                return(2);

            case JewishMonth.KISLEV:
                return(3);

            case JewishMonth.TEVES:
                return(4);

            case JewishMonth.SHEVAT:
                return(5);
            }

            if (leapYear)
            {
                switch (jewishMonth)
                {
                case JewishMonth.ADAR:
                    return(6);

                case JewishMonth.ADAR_II:
                    return(7);

                case JewishMonth.NISSAN:
                    return(8);

                case JewishMonth.IYAR:
                    return(9);

                case JewishMonth.SIVAN:
                    return(10);

                case JewishMonth.TAMMUZ:
                    return(11);

                case JewishMonth.AV:
                    return(12);

                case JewishMonth.ELUL:
                    return(13);
                }
            }
            else
            {
                switch (jewishMonth)
                {
                case JewishMonth.ADAR:
                    return(6);

                case JewishMonth.NISSAN:
                    return(7);

                case JewishMonth.IYAR:
                    return(8);

                case JewishMonth.SIVAN:
                    return(9);

                case JewishMonth.TAMMUZ:
                    return(10);

                case JewishMonth.AV:
                    return(11);

                case JewishMonth.ELUL:
                    return(12);
                }
            }

            return(-1);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the jewish days in month.
        /// </summary>
        /// <returns>The jewish days in month.</returns>
        /// <param name="year">Year.</param>
        /// <param name="month">Month.</param>
        public int GetJewishDaysInMonth(int year, JewishMonth month)
        {
            int nativeMonth = JewishMonthToNativeMonth(month, IsLeapYear(year));

            return(GetDaysInMonth(year, nativeMonth));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Gets the jewish days in month.
 /// </summary>
 /// <returns>The jewish days in month.</returns>
 /// <param name="dt">Dt.</param>
 /// <param name="month">Month.</param>
 public int GetJewishDaysInMonth(DateTime dt, JewishMonth month)
 {
     return(GetJewishDaysInMonth(GetYear(dt), month));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Months the is 29 days / short
 /// </summary>
 /// <returns><c>true</c>, if is29 days was monthed, <c>false</c> otherwise.</returns>
 /// <param name="dt">Dt.</param>
 /// <param name="month">Month.</param>
 public bool MonthIs29Days(DateTime dt, JewishMonth month)
 {
     return(GetJewishDaysInMonth(dt, month) == 29 ? true : false);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the jewish date time.
 /// </summary>
 /// <returns>The jewish date time.</returns>
 /// <param name="year">Year.</param>
 /// <param name="month">Month.</param>
 /// <param name="day">Day.</param>
 public DateTime GetJewishDateTime(int year, JewishMonth month, int day)
 {
     return(new DateTime(year, JewishMonthToNativeMonth(month, IsLeapYear(year)), day, this));
 }