private static void AddTevesSpecialDays(ArrayList list, int jYear, int jDay) { if (JewishDateCalculations.IsShortKislev(jYear)) { if (jDay == 1) { list.Add(new SpecialDay("Chanuka - Six Candles", "'חנוכה - נר ו", SpecialDayTypes.MinorYomtov)); } else if (jDay == 2) { list.Add(new SpecialDay("Chanuka - Seven Candles", "'חנוכה - נר ז", SpecialDayTypes.MinorYomtov)); } else if (jDay == 3) { list.Add(new SpecialDay("Chanuka - Eight Candles", "'חנוכה - נר ח", SpecialDayTypes.MinorYomtov)); } } else { if (jDay == 1) { list.Add(new SpecialDay("Chanuka - Seven Candles", "'חנוכה - נר ז", SpecialDayTypes.MinorYomtov)); } else if (jDay == 2) { list.Add(new SpecialDay("Chanuka - Eight Candles", "'חנוכה - נר ח", SpecialDayTypes.MinorYomtov)); } } if (jDay == 10) { list.Add(new SpecialDay("Fast - 10th of Teves", "צום עשרה בטבת", SpecialDayTypes.FastDay)); } }
/// <summary> /// Sets the current Jewish date to the date represented by the given "Absolute Date" - /// which is the number of days after/before December 31st, 1 BCE. /// The logic here was translated from the C code - which in turn were translated /// from the Lisp code in ''Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold in /// Software---Practice & Experience, vol. 20, no. 9 (September, 1990), pp. 899--928. /// </summary> /// <param name="absoluteDate"></param> private void SetFromAbsoluteDate(int absoluteDate) { this._absoluteDate = absoluteDate; //To save on calculations, start with an estimation of a few years before date this._year = 3761 + (absoluteDate / (absoluteDate > 0 ? 366 : 300)); //The following is from the original code; it starts the calculations way back when and takes almost as long to calculate all of them... //this._year = ((absoluteDate + JewishDateCalculations.HEBREW_EPOCH) / 366); // Approximation from below. // Search forward for year from the approximation. while (absoluteDate >= JewishDateCalculations.GetAbsoluteFromJewishDate((this._year + 1), 7, 1)) { this._year++; } // Search forward for month from either Tishrei or Nissan. if (absoluteDate < JewishDateCalculations.GetAbsoluteFromJewishDate(this._year, 1, 1)) { this._month = 7; // Start at Tishrei } else { this._month = 1; // Start at Nissan } while (absoluteDate > JewishDateCalculations.GetAbsoluteFromJewishDate( this._year, this._month, (JewishDateCalculations.DaysInJewishMonth(this._year, this._month)))) { this._month++; } // Calculate the day by subtraction. this._day = (absoluteDate - JewishDateCalculations.GetAbsoluteFromJewishDate(this._year, this._month, 1) + 1); }
/// <summary> /// Creates a new JewishDate with the specified Hebrew year, month, day and absolute day. /// Caution: If the absolute day doesn't correctly match the given year/month/day, weird things will happen. /// </summary> /// <param name="year">The year - counted from the creation of the world</param> /// <param name="month">The Jewish month. As it is in the Torah, Nissan is 1.</param> /// <param name="day">The day of the month</param> /// <param name="absoluteDay">The "absolute day"</param> public JewishDate(int year, int month, int day, int absoluteDay) { this._year = year; this._month = month; this._day = day; this._absoluteDate = absoluteDay; this._gregorianDate = JewishDateCalculations.GetGregorianDateFromJewishDate(this); }
/// <summary> /// Gets the "proper" name in Hebrew for the given Jewish Month. /// This means for a leap year, labeling each of the the 2 Adars. /// </summary> /// <param name="jYear"></param> /// <param name="jMonth"></param> /// <returns></returns> public static string GetProperMonthNameHeb(int jYear, int jMonth) { if (jMonth == 12 && JewishDateCalculations.IsJewishLeapYear(jYear)) { return("אדר ראשון"); } else { return(JewishMonthNamesHebrew[jMonth]); } }
/// <summary> /// Gets the "proper" name for the given Jewish Month. /// This means for a leap year, labeling each of the the 2 Adars. /// </summary> /// <param name="jYear"></param> /// <param name="jMonth"></param> /// <returns></returns> public static string GetProperMonthName(int jYear, int jMonth) { if (jMonth == 12 && JewishDateCalculations.IsJewishLeapYear(jYear)) { return("Adar Rishon"); } else { return(JewishMonthNamesEnglish[jMonth]); } }
/// <summary> /// Creates a Jewish date that corresponds to the given Gregorian date in the given location. Cut-off time is sunset. /// </summary> /// <param name="date">The Gregorian date from which to create the Jewish Date</param> /// <param name="location">The location. This will be used to determine the time of sunset.</param> public JewishDate(DateTime date, Location location) { int abs = JewishDateCalculations.GetAbsoluteFromGregorianDate(date); var zman = new Zmanim(date, location); if (zman.GetShkia() <= date.TimeOfDay) { abs++; } this.SetFromAbsoluteDate(abs); this._gregorianDate = date; this.TimeOfDay = date.TimeOfDay; }
/// <summary> /// Adds the given number of years to the current date and returns the new Jewish Date /// </summary> /// <param name="years"></param> /// <returns></returns> /// <remarks>If the current month is Adar Sheini and the new year is not a leap year, the month is set to Adar. /// If the current Day is the 30th of Cheshvan or Kislev and in the new year that month only has 29 days, /// the day is set to the 1st of the following month. /// </remarks> public JewishDate AddYears(int years) { int year = this._year + years, month = this._month, day = this._day; if (month == 13 && !JewishDateCalculations.IsJewishLeapYear(year)) { month = 12; } else if (month == 8 && day == 30 && !JewishDateCalculations.IsLongCheshvan(year)) { month = 9; day = 1; } else if (month == 9 && day == 30 && JewishDateCalculations.IsShortKislev(year)) { month = 10; day = 1; } return(new JewishDate(year, month, day)); }
/// <summary> /// Adds the given number of months to the current date and returns the new Jewish Date /// </summary> /// <param name="months"></param> /// <returns></returns> public JewishDate AddMonths(int months) { int year = this._year, month = this._month, day = this._day, miy = JewishDateCalculations.MonthsInJewishYear(year); for (var i = 0; i < Math.Abs(months); i++) { if (months > 0) { month += 1; if (month > miy) { month = 1; } if (month == 7) { year += 1; miy = JewishDateCalculations.MonthsInJewishYear(year); } } else if (months < 0) { month -= 1; if (month == 0) { month = miy; } if (month == 6) { year -= 1; miy = JewishDateCalculations.MonthsInJewishYear(year); } } } return(new JewishDate(year, month, day)); }
/// <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); }
private Sedra(int year, bool inIsrael) { //If the last call is within the same year as this one, we reuse the data. //If memory is an issue, remove these next few lines if (_lastSedraCalculated != null && _lastSedraCalculated._year == year && _lastSedraCalculated._inIsrael == inIsrael) { this._firstSatInYear = _lastSedraCalculated._firstSatInYear; this._sedraArray = _lastSedraCalculated._sedraArray; return; } //Save the data in case the next call is for the same year _lastSedraCalculated = this; bool longCheshvon = JewishDateCalculations.IsLongCheshvan(year); bool shortKislev = JewishDateCalculations.IsShortKislev(year); int roshHashana = JewishDateCalculations.GetAbsoluteFromJewishDate(year, 7, 1); DayOfWeek roshHashanaDOW = (DayOfWeek)Math.Abs(roshHashana % 7); YearType yearType; if (longCheshvon && !shortKislev) { yearType = YearType.Complete; } else if (!longCheshvon && shortKislev) { yearType = YearType.Incomplete; } else { yearType = YearType.Regular; } this._year = year; this._inIsrael = inIsrael; /* find and save the first shabbos on or after Rosh Hashana */ this._firstSatInYear = GetDayOnOrBefore(6, roshHashana + 6); if (!JewishDateCalculations.IsJewishLeapYear(year)) { switch (roshHashanaDOW) { case DayOfWeek.Saturday: if (yearType == YearType.Incomplete) { this._sedraArray = shabbos_short; } else if (yearType == YearType.Complete) { this._sedraArray = shabbos_long; } break; case DayOfWeek.Monday: if (yearType == YearType.Incomplete) { this._sedraArray = mon_short; } else if (yearType == YearType.Complete) { this._sedraArray = this._inIsrael ? mon_short : mon_long; } break; case DayOfWeek.Tuesday: if (yearType == YearType.Regular) { this._sedraArray = this._inIsrael ? mon_short : mon_long; } break; case DayOfWeek.Thursday: if (yearType == YearType.Regular) { this._sedraArray = this._inIsrael ? thu_normal_Israel : thu_normal; } else if (yearType == YearType.Complete) { this._sedraArray = thu_long; } break; default: throw new Exception("improper sedra year type calculated."); } } else /* leap year */ { switch (roshHashanaDOW) { case DayOfWeek.Saturday: if (yearType == YearType.Incomplete) { this._sedraArray = shabbos_short_leap; } else if (yearType == YearType.Complete) { this._sedraArray = this._inIsrael ? shabbos_short_leap : shabbos_long_leap; } break; case DayOfWeek.Monday: if (yearType == YearType.Incomplete) { this._sedraArray = this._inIsrael ? mon_short_leap_Israel : mon_short_leap; } else if (yearType == YearType.Complete) { this._sedraArray = this._inIsrael ? mon_long_leap_Israel : mon_long_leap; } break; case DayOfWeek.Tuesday: if (yearType == YearType.Regular) { this._sedraArray = this._inIsrael ? mon_long_leap_Israel : mon_long_leap; } break; case DayOfWeek.Thursday: if (yearType == YearType.Incomplete) { this._sedraArray = thu_short_leap; } else if (yearType == YearType.Complete) { this._sedraArray = thu_long_leap; } break; default: throw new Exception("improper sedra year type calculated."); } } }
/// <summary> /// Creates a Hebrew date from the "absolute date". /// In other words, the Hebrew date on the day that is the given number of days after/before December 31st, 1 BCE /// </summary> /// <param name="absoluteDate">The number of days elapsed since the theoretical Gregorian date Sunday, December 31, 1 BCE. /// Since there is no year 0 in the calendar, the year following 1 BCE is 1 CE. /// So, the Gregorian date January 1, 1 CE is absolute date number 1.</param> public JewishDate(int absoluteDate) { this.SetFromAbsoluteDate(absoluteDate); this._gregorianDate = JewishDateCalculations.GetGregorianDateFromJewishDate(this); }
/// <summary> /// Creates a Jewish date that corresponds to the given Gregorian date /// </summary> /// <param name="date">The Gregorian date from which to create the Jewish Date</param> public JewishDate(DateTime date) { this.SetFromAbsoluteDate(JewishDateCalculations.GetAbsoluteFromGregorianDate(date)); this._gregorianDate = date; this.TimeOfDay = date.TimeOfDay; }
/// <summary> /// Creates a new JewishDate with the specified Hebrew year, month and day /// </summary> /// <param name="year">The year - counted from the creation of the world</param> /// <param name="month">The Jewish month. As it is in the Torah, Nissan is 1.</param> /// <param name="day">The day of the month</param> public JewishDate(int year, int month, int day) : this(year, month, day, JewishDateCalculations.GetAbsoluteFromJewishDate(year, month, day)) { }
/// <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); } }
/// <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<JewishCalendar.SpecialDay>() /// </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); }