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