/// <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); }
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."); } } }