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