/// <summary>
 /// Compares this Jewish Date to another one to see if they both represent the same Jewish calendar date.
 /// </summary>
 /// <param name="jd1">This JewishDate</param>
 /// <param name="jd2">The JewishDate to test against this one</param>
 /// <returns>Whether or not the two represent the same Jewish calendar date</returns>
 public static bool IsSameDate(this JewishDate jd1, JewishDate jd2)
 {
     if (jd2 == null)
     {
         return(false);
     }
     return(jd1.Year == jd2.Year && jd1.Month == jd2.Month && jd1.Day == jd2.Day);
 }
Пример #2
0
 private static void SetPirkeiAvos(JewishDate jDate, bool inIsrael, ArrayList list)
 {
     int[] prakim = PirkeiAvos.GetPirkeiAvos(jDate, inIsrael);
     if (prakim.Length > 0)
     {
         string engStr = "", hebStr = "";
         foreach (int p in prakim)
         {
             engStr += (engStr.Length > 0 ? " and " : "") + p.ToSuffixedString();
             hebStr += (hebStr.Length > 0 ? ", " : "") + p.ToNumberHeb();
         }
         list.Add(new SpecialDay("Pirkei Avos - Perek " + engStr, "פרקי אבות - פרק " + hebStr));
     }
 }
Пример #3
0
        /// <summary>
        /// Gets the Parsha/s for the given Jewish date
        /// </summary>
        /// <param name="date"></param>
        /// <param name="inIsrael"></param>
        /// <returns></returns>
        public static Parsha[] GetSedra(JewishDate date, bool inIsrael)
        {
            Parsha[] parshaArray;

            //If we are between the first day of Sukkos and Simchas Torah, the parsha will always be Vezos Habracha.
            if (date.Month == 7 && date.Day >= 15 && date.Day < (inIsrael ? 23 : 24))
            {
                return(new Parsha[] { ParshaList[53] });
            }

            Sedra sedraOrder = new Sedra(date.Year, inIsrael);
            int   absDate    = date.AbsoluteDate;
            int   index;
            int   weekNum;

            /* find the first saturday on or after today's date */
            absDate = GetDayOnOrBefore(6, absDate + 6);

            weekNum = (absDate - sedraOrder._firstSatInYear) / 7;
            if (weekNum >= sedraOrder._sedraNumWeeks)
            {
                int indexLast = sedraOrder._sedraArray[sedraOrder._sedraNumWeeks - 1];
                if (indexLast < 0)
                {
                    /* advance 2 parashiyot ahead after a doubled week */
                    index = (-indexLast) + 2;
                }
                else
                {
                    index = indexLast + 1;
                }
            }
            else
            {
                index = sedraOrder._sedraArray[weekNum];
            }

            if (index >= 0)
            {
                parshaArray = new Parsha[] { ParshaList[index] };
            }
            else
            {
                int i = -index;      /* undouble the parsha */
                parshaArray = new Parsha[] { ParshaList[i], ParshaList[i + 1] };
            }
            return(parshaArray);
        }
Пример #4
0
        /// <summary>
        /// Returns true if the given day is a day of Yom Tov or Chol Ha'moed in the given location.
        /// </summary>
        /// <param name="jd"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public static bool IsMajorYomTov(JewishDate jd, Location location)
        {
            switch (jd.Month)
            {
            case 1:
                return(jd.Day > 14 && jd.Day < (location.IsInIsrael ? 22 : 23));

            case 3:
                return(jd.Day == 6 || ((!location.IsInIsrael) && jd.Day == 7));

            case 7:
                return(jd.Day.In(1, 2, 10) ||
                       (jd.Day > 14 && jd.Day < (location.IsInIsrael ? 23 : 24)));

            default:
                return(false);
            }
        }
Пример #5
0
        private static void AddShabbosSpecialDays(JewishDate jDate, bool inIsrael, ArrayList list, bool isLeapYear)
        {
            int jYear  = jDate.Year,
                jMonth = jDate.Month,
                jDay   = jDate.Day;

            if (jMonth == 1 && jDay > 7 && jDay < 15)
            {
                list.Add(new SpecialDay("Shabbos HaGadol", "שבת הגדול"));
            }
            else if (jMonth == 7 && jDay > 2 && jDay < 10)
            {
                list.Add(new SpecialDay("Shabbos Shuva", "שבת שובה"));
            }
            else if (jMonth == 5 && jDay > 2 && jDay < 10)
            {
                list.Add(new SpecialDay("Shabbos Chazon", "שבת חזון"));
            }
            else if ((jMonth == (isLeapYear ? 12 : 11) && jDay > 24) ||
                     (jMonth == (isLeapYear ? 13 : 12) && jDay == 1))
            {
                list.Add(new SpecialDay("Parshas Shkalim", "פרשת שקלים"));
            }
            else if (jMonth == (isLeapYear ? 13 : 12) && jDay > 7 && jDay < 14)
            {
                list.Add(new SpecialDay("Parshas Zachor", "פרשת זכור"));
            }
            else if (jMonth == (isLeapYear ? 13 : 12) && jDay > 16 && jDay < 24)
            {
                list.Add(new SpecialDay("Parshas Parah", "פרשת פרה"));
            }
            else if ((jMonth == (isLeapYear ? 13 : 12) && jDay > 23 && jDay < 30) ||
                     (jMonth == 1 && jDay == 1))
            {
                list.Add(new SpecialDay("Parshas Hachodesh", "פרשת החודש"));
            }

            if (jMonth != 6 && jDay > 22 && jDay < 30)
            {
                list.Add(new SpecialDay("Shabbos Mevarchim", "מברכים החודש"));
            }

            SetPirkeiAvos(jDate, inIsrael, list);
        }
        /// <summary>
        /// Returns the correct Secular Date for a JewishDate at the given Time and Location.
        /// </summary>
        /// <param name="jd">The Jewish Date</param>
        /// <param name="location"></param>
        /// <param name="timeOfDay"></param>
        /// <returns></returns>
        /// <remarks>
        /// When using a JewishDate constructor that takes a "Location" object,
        /// if the initializing DateTime was after sunset, the Jewish date was set to the next day, but not the GregorianDate.
        /// The GregorianDate property therefore only represents the correct Secular Date for the original location and time.
        /// This function returns the correct GregorianDate for a JewishDate at the given time and place.
        /// </remarks>
        public static DateTime GetGregorianDateFromJewishDate(JewishDate jd, TimeOfDay timeOfDay, Location location)
        {
            //The Gregorian date that starts at midnight of the given Jewish Date
            DateTime gregDateAtMidnight = GetGregorianDateFromJewishDate(jd);

            //If given time is after mid-day (sunset is never, ever before mid-day; not even at the North and South Poles)
            //and given time is after sunset at the given location
            if (timeOfDay.Hour >= 12 && timeOfDay >= new Zmanim(jd.GregorianDate, location).GetShkia())
            {
                // From sunset to midnight:
                // Jewish today is Secular tomorrow and Secular Today is Jewish Yesterday
                // (please sir, keep your yarmulka on!) [double meanings all around]
                return(gregDateAtMidnight.AddDays(-1));
            }
            else
            {
                return(gregDateAtMidnight);
            }
        }
Пример #7
0
        /// <summary>
        /// Returns true if the given day is a day of Yom Tov or Shabbos in the given location.
        /// </summary>
        /// <param name="jd"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public static bool IsShabbosOrYomTov(JewishDate jd, Location location)
        {
            if (jd.DayOfWeek == DayOfWeek.Saturday)
            {
                return(true);
            }
            switch (jd.Month)
            {
            case 1:
                return(jd.Day == 15 || (!location.IsInIsrael && jd.Day == 16) || jd.Day == 21 || (!location.IsInIsrael && jd.Day == 22));

            case 3:
                return(jd.Day == 6 || ((!location.IsInIsrael) && jd.Day == 7));

            case 7:
                return(jd.Day.In(1, 2, 10) ||
                       (jd.Day == 15 || (!location.IsInIsrael && jd.Day == 16) || jd.Day == 22 || (!location.IsInIsrael && jd.Day == 23)));

            default:
                return(false);
            }
        }
Пример #8
0
        /// <summary>
        /// Gets the difference in months between two JewishDates.
        /// If the second date is before this one, the number will be negative.
        /// </summary>
        /// <param name="jd"></param>
        /// <returns></returns>
        /// <remarks>Ignores Day part. For example, from 29 Kislev to 1 Teves will
        /// return 1 even though they are only a day or two apart</remarks>
        public int DateDiffMonth(JewishDate jd)
        {
            int month  = jd._month,
                year   = jd._year,
                months = 0;

            while (!(year == this._year && month == this._month))
            {
                if (this.AbsoluteDate > jd.AbsoluteDate)
                {
                    months--;
                    month++;
                    if (month > JewishDateCalculations.MonthsInJewishYear(year))
                    {
                        month = 1;
                    }
                    else if (month == 7)
                    {
                        year++;
                    }
                }
                else
                {
                    months++;
                    month--;
                    if (month < 1)
                    {
                        month = JewishDateCalculations.MonthsInJewishYear(year);
                    }
                    else if (month == 6)
                    {
                        year--;
                    }
                }
            }

            return(months);
        }
Пример #9
0
 /// <summary>
 /// static constructor
 /// </summary>
 static JewishDate()
 {
     MinDate = new JewishDate(1, 7, 1);
     MaxDate = new JewishDate(5999, 6, 29);
 }
 /// <summary>
 /// Gets the Gregorian date that starts at midnight of the given Jewish Date
 /// </summary>
 /// <param name="jd"></param>
 /// <returns></returns>
 public static DateTime GetGregorianDateFromJewishDate(JewishDate jd) => GetGregorianDateFromAbsolute(jd.AbsoluteDate).Add(jd.TimeOfDay);
Пример #11
0
        /// <summary>
        /// Returns true if the given day is a special day or a fast day,
        /// but not Shabbos or a major Yom Tov in the given location.
        /// </summary>
        /// <param name="jd"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public static bool IsMinorYomTovOrFast(JewishDate jd, Location location)
        {
            DayOfWeek dow   = jd.DayOfWeek;
            int       day   = jd.Day,
                      month = jd.Month,
                      year  = jd.Year;

            if (dow == DayOfWeek.Saturday || IsMajorYomTov(jd, location))
            {
                return(false);
            }
            if (day.In(30, 1))
            {
                return(true);
            }
            switch (month)
            {
            case 1:
                return(day == 14);

            case 2:
                return(day.In(14, 18));

            case 4:
                return((day == 17 && dow != DayOfWeek.Saturday) ||
                       (day == 18 && dow == DayOfWeek.Sunday));

            case 5:
                return((day == 9 && dow != DayOfWeek.Saturday) ||
                       (day == 10 && dow == DayOfWeek.Sunday) ||
                       day == 15);

            case 6:
                return(day == 29);

            case 7:
                return(((day == 3 && dow != DayOfWeek.Saturday) ||
                        (day == 4 && dow == DayOfWeek.Sunday)) ||
                       day == 9);

            case 9:
                return(day > 24);

            case 10:
                if (day < 4)
                {
                    return(JewishDateCalculations.IsShortKislev(year) || (day < 3));
                }
                else
                {
                    return(day == 10);
                }

            case 11:
                return(day == 15);

            case 12:
            case 13:
                if (month == 12 && JewishDateCalculations.IsJewishLeapYear(year))
                {
                    return(day.In(14, 15));
                }
                else
                {
                    return
                        ((day == 11 && dow == DayOfWeek.Thursday) ||
                         (day == 13 && dow != DayOfWeek.Saturday) ||
                         (day.In(14, 15)));
                }

            default:
                return(false);
            }
        }
Пример #12
0
 /// <summary>
 /// Create a new Zmanim instance for the given Jewish day and Location
 /// </summary>
 /// <param name="hd"></param>
 /// <param name="loc"></param>
 public Zmanim(JewishDate hd, Location loc)
     : this(hd.GregorianDate, loc)
 {
 }
Пример #13
0
 /// <summary>
 /// Gets a dash delimited list of holidays for the given Jewish Day
 /// </summary>
 /// <param name="jdate"></param>
 /// <param name="inIsrael"></param>
 /// <param name="hebrew"></param>
 /// <returns></returns>
 public static string GetHolidaysText(JewishDate jdate, bool inIsrael, bool hebrew)
 {
     return(GetHolidaysText(GetHolidays(jdate, inIsrael), " - ", hebrew));
 }
Пример #14
0
        /// <summary>
        /// Gets a list of special days and information about the given Jewish Date
        /// </summary>
        /// <param name="jDate"></param>
        /// <param name="inIsrael"></param>
        /// <returns></returns>
        /// <remarks>We use an ArrayList rather than a generic List to accommodate
        /// the .NET Micro framework which does not support generic lists.
        /// For regular projects just use as follows: GetHolidays(jDate, inIsrael).Cast&lt;JewishCalendar.SpecialDay&gt;()
        /// </remarks>
        public static ArrayList GetHolidays(JewishDate jDate, bool inIsrael)
        {
            var       list       = new ArrayList();
            int       jYear      = jDate.Year;
            int       jMonth     = jDate.Month;
            int       jDay       = jDate.Day;
            DayOfWeek dayOfWeek  = jDate.DayOfWeek;
            bool      isLeapYear = JewishDateCalculations.IsJewishLeapYear(jYear);
            DateTime  secDate    = jDate.GregorianDate;

            if (dayOfWeek == DayOfWeek.Friday)
            {
                list.Add(new SpecialDay("Erev Shabbos", "ערב שבת",
                                        SpecialDayTypes.Information | SpecialDayTypes.HasCandleLighting));
            }
            else if (dayOfWeek == DayOfWeek.Saturday)
            {
                AddShabbosSpecialDays(jDate, inIsrael, list, isLeapYear);
            }
            AddRoshChodeshSpecialDays(list, jYear, jMonth, jDay, isLeapYear);

            //V'sain Tal U'Matar in Chutz La'aretz is according to the secular date
            if (secDate.Month == 12 && secDate.Day.In(5, 6) && !inIsrael)
            {
                bool nextYearIsLeap = JewishDateCalculations.IsJewishLeapYear(jYear + 1);
                if (((secDate.Day == 5 && !nextYearIsLeap)) || (secDate.Day == 6 && nextYearIsLeap))
                {
                    list.Add(new SpecialDay("V'sain Tal U'Matar", "ותן טל ומטר"));
                }
            }

            switch (jMonth)
            {
            case 1:     //Nissan
                AddNissanSpecialDays(inIsrael, list, jDay, dayOfWeek);
                break;

            case 2:     //Iyar
                AddIyarSpecialDays(list, jDay, dayOfWeek);
                break;

            case 3:     //Sivan
                AddSivanSpecialDays(inIsrael, list, jDay, dayOfWeek);
                break;

            case 4:     //Tamuz
                AddTamuzSpecialDays(list, jDay, dayOfWeek);
                break;

            case 5:     //Av
                AddAvSpecialDays(list, jDay, dayOfWeek);
                break;

            case 6:     //Ellul
                AddEllulSpecialDays(list, jDay, dayOfWeek);
                break;

            case 7:     //Tishrei
                AddTishreiSpecialDays(inIsrael, list, jDay, dayOfWeek);
                break;

            case 8:     //Cheshvan
                AddCheshvanSpecialDays(inIsrael, list, jDay, dayOfWeek);
                break;

            case 9:     //Kislev
                AddKislevSpecialDays(list, jDay);
                break;

            case 10:     //Teves
                AddTevesSpecialDays(list, jYear, jDay);
                break;

            case 11:     //Shvat
                AddShvatSpecialDays(list, jDay);
                break;

            case 12:     //Adars
            case 13:
                AddAdarSpecialDays(list, jMonth, jDay, dayOfWeek, isLeapYear);
                break;
            }

            if ((jMonth == 1 && jDay > 15) || jMonth == 2 || (jMonth == 3 && jDay < 6))
            {
                int dayOfSefirah = jDate.GetDayOfOmer();
                if (dayOfSefirah > 0)
                {
                    list.Add(new SpecialDay("Sefiras Ha'omer - Day " + dayOfSefirah.ToString(), "ספירת העומר - יום " + dayOfSefirah.ToString()));
                }
            }
            //Remove any candle lighting added by a YomTov from Shabbos....
            if (dayOfWeek == DayOfWeek.Saturday)
            {
                foreach (SpecialDay sd in list)
                {
                    if (sd.DayType.IsSpecialDayType(SpecialDayTypes.HasCandleLighting))
                    {
                        sd.DayType = (SpecialDayTypes)(sd.DayType - SpecialDayTypes.HasCandleLighting);
                    }
                }
            }

            return(list);
        }